diff --git a/flake.lock b/flake.lock index b7dcc41..b5a5892 100644 --- a/flake.lock +++ b/flake.lock @@ -114,11 +114,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1712608508, - "narHash": "sha256-vMZ5603yU0wxgyQeHJryOI+O61yrX2AHwY6LOFyV1gM=", + "lastModified": 1716948383, + "narHash": "sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4cba8b53da471aea2ab2b0c1f30a81e7c451f4b6", + "rev": "ad57eef4ef0659193044870c731987a6df5cf56b", "type": "github" }, "original": { @@ -183,4 +183,4 @@ }, "root": "root", "version": 7 -} \ No newline at end of file +} diff --git a/flake.nix b/flake.nix index 9aeb23e..e69256d 100644 --- a/flake.nix +++ b/flake.nix @@ -32,21 +32,6 @@ platforms-android-34 emulator ]); - # See below link for configuring ruby env with bundix - # https://github.com/the-nix-way/nix-flake-dev-environments/tree/main/ruby-on-rails - rubyEnv = pkgs.bundlerEnv { - name = "ruby-env"; - inherit (pkgs) ruby; - gemdir = ./android; - }; - # buildNodeJs = pkgs.callPackage "${nixpkgs}/pkgs/development/web/nodejs/nodejs.nix" { - # python = pkgs.python3; - # }; - # nodejs = buildNodeJs { - # enableNpm = true; - # version = "20.0.0"; - # sha256 = "sha256-Q5xxqi84woYWV7+lOOmRkaVxJYBmy/1FSFhgScgTQZA="; - # }; in pkgs.mkShell { # Fix an issue with Flutter using an older version of aapt2, which does not know @@ -60,13 +45,6 @@ # pkg-config jdk17 android-sdk - rubyEnv - rubyEnv.wrappedRuby - # fastlane - bundix - # gems - firebase-tools - # nodejs ]; shellHook = '' export PATH="$PATH":"$HOME/.pub-cache/bin" diff --git a/lib/features/account/account_create_screen.dart b/lib/features/account/account_create_screen.dart index a61f7e9..e65a075 100644 --- a/lib/features/account/account_create_screen.dart +++ b/lib/features/account/account_create_screen.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; import 'package:rluv/features/account/signup.dart'; import 'package:rluv/global/styles.dart'; @@ -13,8 +12,7 @@ class AccountCreateScreen extends ConsumerStatefulWidget { const AccountCreateScreen({super.key}); @override - ConsumerState createState() => - _AccountCreateScreenState(); + ConsumerState createState() => _AccountCreateScreenState(); } enum _AccountScreen { options, login, signup } @@ -40,7 +38,7 @@ class _AccountCreateScreenState extends ConsumerState { }, ); } - final screen = BuildMedia(context).size; + final screen = MediaQuery.of(context).size; return Scaffold( backgroundColor: Styles.purpleNurple, body: SafeArea( @@ -60,11 +58,8 @@ class _AccountCreateScreenState extends ConsumerState { Padding( padding: const EdgeInsets.symmetric(vertical: 40.0), child: Image.asset("assets/app_icon.png", - height: - screen.width > 500 ? 250 : screen.width * 0.5, - width: screen.width > 500 - ? 250 - : screen.width * 0.5), + height: screen.width > 500 ? 250 : screen.width * 0.5, + width: screen.width > 500 ? 250 : screen.width * 0.5), ), UiButton( color: Styles.sunflower, diff --git a/lib/features/account/login.dart b/lib/features/account/login.dart index 35d475b..1c2ad55 100644 --- a/lib/features/account/login.dart +++ b/lib/features/account/login.dart @@ -1,7 +1,6 @@ +import 'package:colorful_print/colorful_print.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; -import 'package:helpers/helpers/print.dart'; import '../../global/api.dart'; import '../../global/styles.dart'; @@ -19,7 +18,7 @@ class Login extends ConsumerStatefulWidget { } class _LoginState extends ConsumerState { - bool usingUsername = false; + bool usingUsername = true; final emailController = TextEditingController(); final usernameController = TextEditingController(); final passwordController = TextEditingController(); @@ -32,7 +31,7 @@ class _LoginState extends ConsumerState { @override Widget build(BuildContext context) { - final screen = BuildMedia(context).size; + final screen = MediaQuery.of(context).size; return Form( key: widget.formKey, child: Stack( @@ -134,7 +133,7 @@ class _LoginState extends ConsumerState { text: 'Password: ', validatorFunc: (s) { if (s != null && s.length < 6) { - return 'Please do a better password (you have to)'; + return 'Please do a better password, at least 6 characters (you have to)'; } return null; }, @@ -205,35 +204,21 @@ class _LoginState extends ConsumerState { Future login() async { try { - if (widget.formKey.currentState != null && - !widget.formKey.currentState!.validate()) { + if (widget.formKey.currentState != null && !widget.formKey.currentState!.validate()) { return; } - final data = - await ref.read(apiProvider.notifier).post(path: 'auth/login', data: { - 'username': - usernameController.text.isEmpty ? null : usernameController.text, + final Map? data = await ref.read(apiProvider.notifier).post(path: 'auth/login', data: { + 'username': usernameController.text.isEmpty ? null : usernameController.text, 'email': emailController.text.isEmpty ? null : emailController.text, 'password': passwordController.text, }); - String message = 'Login unsuccessful'; - bool success = data?['success'] == 'false'; - if (data != null) { - if (data['message'] != null) { - message = data['message']; - } else if (success) { - message = 'Logged in!'; - } - } - // final bool success = data?['success'] ?? false; - printAmber(data); - showSnack( - ref: ref, - text: message, - type: !success ? SnackType.error : SnackType.success); + bool success = data?['success'] ?? false; + String message = data?['message'] ?? (success ? 'Login success!' : 'Login unsuccessful.'); + printColor(data, textColor: TextColor.yellow); + showSnack(ref: ref, text: message, type: success ? SnackType.success : SnackType.error); } catch (err, st) { - printRed('Error in login: $err\n$st'); + printColor('Error in login: $err\n$st', textColor: TextColor.red); } } } diff --git a/lib/features/account/signup.dart b/lib/features/account/signup.dart index 5024d51..c672c5a 100644 --- a/lib/features/account/signup.dart +++ b/lib/features/account/signup.dart @@ -1,7 +1,6 @@ +import 'package:colorful_print/colorful_print.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; -import 'package:helpers/helpers/print.dart'; import '../../global/api.dart'; import '../../global/styles.dart'; @@ -36,7 +35,7 @@ class _SignupState extends ConsumerState { @override Widget build(BuildContext context) { - final screen = BuildMedia(context).size; + final screen = MediaQuery.of(context).size; return Form( key: widget.formKey, child: Stack( @@ -126,8 +125,7 @@ class _SignupState extends ConsumerState { ), UiButton( width: screen.width * 0.4, - icon: const Icon(Icons.cancel, - color: Styles.washedStone, size: 20), + icon: const Icon(Icons.cancel, color: Styles.washedStone, size: 20), onPressed: () { setState( () => hasFamilyCode = false, @@ -140,9 +138,7 @@ class _SignupState extends ConsumerState { : Padding( padding: const EdgeInsets.all(8.0), child: UiButton( - width: screen.width * 0.5 > 400 - ? 400 - : screen.width * 0.5, + width: screen.width * 0.5 > 400 ? 400 : screen.width * 0.5, text: 'JOIN FAMILY', // color: Styles.flounderBlue, onPressed: () { @@ -190,8 +186,7 @@ class _SignupState extends ConsumerState { text, style: TextStyle(fontSize: size.width < 350 ? 16 : 20), ), - if (subtext != null) - Text(subtext, style: const TextStyle(fontSize: 12)), + if (subtext != null) Text(subtext, style: const TextStyle(fontSize: 12)), ], ), ), @@ -223,36 +218,29 @@ class _SignupState extends ConsumerState { Future signup() async { try { - if (widget.formKey.currentState != null && - !widget.formKey.currentState!.validate()) { + if (widget.formKey.currentState != null && !widget.formKey.currentState!.validate()) { return; } - final data = - await ref.read(apiProvider.notifier).post(path: 'auth/signup', data: { + final data = await ref.read(apiProvider.notifier).post(path: 'auth/signup', data: { 'name': nameCotroller.text, - 'username': - usernameController.text.isEmpty ? null : usernameController.text, + 'username': usernameController.text.isEmpty ? null : usernameController.text, 'email': emailController.text.isEmpty ? null : emailController.text, 'password': passwordController.text, - 'family_code': familyCodeController.text.isEmpty - ? null - : familyCodeController.text.toUpperCase(), + 'family_code': familyCodeController.text.isEmpty ? null : familyCodeController.text.toUpperCase(), 'budget_name': 'Budget' }); final success = data?['success'] ?? false; showSnack( ref: ref, - text: data?['message'] ?? success - ? 'Login successful' - : 'Login unsuccessful', + text: data?['message'] ?? success ? 'Login successful' : 'Login unsuccessful', type: !success ? SnackType.error : SnackType.success); - printAmber(data); + printColor(data, textColor: TextColor.yellow); // final user = User.fromJson(data?['user']); // ref.read(tokenProvider.notifier).state = } catch (err) { - printRed(err); + printColor(err, textColor: TextColor.red); } } } diff --git a/lib/features/budget/screens/budget_overview.dart b/lib/features/budget/screens/budget_overview.dart index 70b597b..f970863 100644 --- a/lib/features/budget/screens/budget_overview.dart +++ b/lib/features/budget/screens/budget_overview.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers.dart'; import 'package:rluv/features/budget/screens/transactions_listview.dart'; import 'package:rluv/features/budget/widgets/add_transaction_dialog.dart'; import 'package:rluv/features/budget/widgets/budget_category_bar.dart'; @@ -19,8 +18,7 @@ class BudgetOverviewScreen extends ConsumerStatefulWidget { final Map initialData; @override - ConsumerState createState() => - _BudgetOverviewScreenState(); + ConsumerState createState() => _BudgetOverviewScreenState(); } class _BudgetOverviewScreenState extends ConsumerState { @@ -30,23 +28,18 @@ class _BudgetOverviewScreenState extends ConsumerState { final budget = ref.watch(budgetProvider); final budgetCategories = ref.watch(budgetCategoriesProvider); final transactions = ref.watch(transactionsProvider); - final screen = BuildMedia(context).size; + final screen = MediaQuery.of(context).size; double netExpense = 0.0; double netIncome = 0.0; double expectedExpenses = 0.0; Map budgetCategoryNetMap = {}; - netExpense = transactions - .where((t) => t.type == TransactionType.expense) - .fold(netExpense, (net, t) => net + t.amount); - netIncome = transactions - .where((t) => t.type == TransactionType.income) - .fold(netIncome, (net, t) => net + t.amount); + netExpense = + transactions.where((t) => t.type == TransactionType.expense).fold(netExpense, (net, t) => net + t.amount); + netIncome = transactions.where((t) => t.type == TransactionType.income).fold(netIncome, (net, t) => net + t.amount); for (final bud in budgetCategories) { double net = 0.0; expectedExpenses += bud.amount; - net = transactions - .where((t) => t.budgetCategoryId == bud.id) - .fold(net, (net, t) => net + t.amount); + net = transactions.where((t) => t.budgetCategoryId == bud.id).fold(net, (net, t) => net + t.amount); budgetCategoryNetMap[bud.id!] = net; } return Stack( @@ -64,23 +57,14 @@ class _BudgetOverviewScreenState extends ConsumerState { const Spacer(flex: 2), Text( formatDate(DateTime.now()), - style: const TextStyle( - fontSize: 16, color: Styles.electricBlue), + style: const TextStyle(fontSize: 16, color: Styles.electricBlue), ), const Spacer(), - const Text('MONTHLY', - style: - TextStyle(fontSize: 42, color: Styles.electricBlue)), + const Text('MONTHLY', style: TextStyle(fontSize: 42, color: Styles.electricBlue)), const Spacer(flex: 2), - BudgetNetBar( - isPositive: true, - net: netIncome, - expected: budget?.expectedIncome ?? 0.0), + BudgetNetBar(isPositive: true, net: netIncome, expected: budget?.expectedIncome ?? 0.0), const Spacer(), - BudgetNetBar( - isPositive: false, - net: netExpense, - expected: expectedExpenses), + BudgetNetBar(isPositive: false, net: netExpense, expected: expectedExpenses), const Spacer(), ], ), @@ -107,8 +91,7 @@ class _BudgetOverviewScreenState extends ConsumerState { padding: EdgeInsets.all(8.0), child: Text( 'BUDGET', - style: TextStyle( - fontSize: 28, color: Styles.electricBlue), + style: TextStyle(fontSize: 28, color: Styles.electricBlue), ), ), budgetCategories.isEmpty @@ -120,25 +103,18 @@ class _BudgetOverviewScreenState extends ConsumerState { children: [ const Padding( padding: EdgeInsets.all(8.0), - child: Text( - 'No budget categories created yet, add some!'), + child: Text('No budget categories created yet, add some!'), ), UiButton( - onPressed: - ref.watch(budgetProvider) == - null - ? null - : () => showDialog( - context: context, - builder: (context) => Dialog( - shape: Styles - .dialogShape, - backgroundColor: - Styles - .dialogColor, - child: - const BudgetCategoryDialog()), - ), + onPressed: ref.watch(budgetProvider) == null + ? null + : () => showDialog( + context: context, + builder: (context) => Dialog( + shape: Styles.dialogShape, + backgroundColor: Styles.dialogColor, + child: const BudgetCategoryDialog()), + ), text: 'Add Category', ), ], @@ -146,55 +122,42 @@ class _BudgetOverviewScreenState extends ConsumerState { ), ) : Padding( - padding: const EdgeInsets.symmetric( - horizontal: 2.0, vertical: 4.0), + padding: const EdgeInsets.symmetric(horizontal: 2.0, vertical: 4.0), child: SizedBox( height: screen.height * 0.36, child: Scrollbar( controller: budgetListScrollController, thumbVisibility: true, child: ListView( - physics: - const BouncingScrollPhysics(), - controller: - budgetListScrollController, + physics: const BouncingScrollPhysics(), + controller: budgetListScrollController, shrinkWrap: true, children: [ - ...budgetCategories - .mapIndexed((i, category) { + ...budgetCategories.map((category) { + final int i = budgetCategories.indexOf(category); return BudgetCategoryBar( budgetCategory: category, - currentAmount: - budgetCategoryNetMap[ - category.id]!, + currentAmount: budgetCategoryNetMap[category.id]!, index: i, ); }).toList(), const SizedBox(height: 20), Row( - mainAxisAlignment: - MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width: 140, child: ElevatedButton( - onPressed: ref.watch( - budgetProvider) == - null + onPressed: ref.watch(budgetProvider) == null ? null : () => showDialog( context: context, builder: (context) => Dialog( - shape: Styles - .dialogShape, - backgroundColor: - Styles - .dialogColor, - child: - const BudgetCategoryDialog()), + shape: Styles.dialogShape, + backgroundColor: Styles.dialogColor, + child: const BudgetCategoryDialog()), ), - child: const Text( - 'Add Category'), + child: const Text('Add Category'), ), ), ], @@ -214,8 +177,7 @@ class _BudgetOverviewScreenState extends ConsumerState { children: [ Expanded( child: Padding( - padding: - const EdgeInsets.only(left: 20.0, right: 15.0), + padding: const EdgeInsets.only(left: 20.0, right: 15.0), child: Container( height: 70, decoration: BoxDecoration( @@ -225,8 +187,7 @@ class _BudgetOverviewScreenState extends ConsumerState { child: InkWell( child: const Center( child: Padding( - padding: EdgeInsets.symmetric( - horizontal: 20.0, vertical: 14.0), + padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 14.0), child: FittedBox( child: Text( 'Transaction History', @@ -238,10 +199,7 @@ class _BudgetOverviewScreenState extends ConsumerState { ), onTap: () { Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - const TransactionsListview())); + context, MaterialPageRoute(builder: (context) => const TransactionsListview())); }, ), ), @@ -292,8 +250,7 @@ class _BudgetOverviewScreenState extends ConsumerState { child: IconButton( icon: const Icon(Icons.loop), color: Styles.seaweedGreen, - onPressed: () => - ref.read(dashboardProvider.notifier).fetchDashboard(), + onPressed: () => ref.read(dashboardProvider.notifier).fetchDashboard(), ), ), ), diff --git a/lib/features/budget/screens/transactions_listview.dart b/lib/features/budget/screens/transactions_listview.dart index b6c1bb1..f07daf4 100644 --- a/lib/features/budget/screens/transactions_listview.dart +++ b/lib/features/budget/screens/transactions_listview.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; import 'package:rluv/features/budget/widgets/transaction_list_item.dart'; import 'package:rluv/global/styles.dart'; import 'package:rluv/models/transaction_model.dart'; @@ -12,8 +11,7 @@ class TransactionsListview extends ConsumerStatefulWidget { const TransactionsListview({super.key}); @override - ConsumerState createState() => - _TransactionsListviewState(); + ConsumerState createState() => _TransactionsListviewState(); } class _TransactionsListviewState extends ConsumerState { @@ -23,8 +21,7 @@ class _TransactionsListviewState extends ConsumerState { void initState() { // TODO: implement initState WidgetsBinding.instance.addPostFrameCallback((_) { - ref.read(selectedTransactionSortProvider.notifier).state = - TransactionSort.all; + ref.read(selectedTransactionSortProvider.notifier).state = TransactionSort.all; ref.read(selectedSortDateProvider.notifier).state = SortDate.decending; }); super.initState(); @@ -34,8 +31,8 @@ class _TransactionsListviewState extends ConsumerState { Widget build(BuildContext context) { final budgetCategories = ref.watch(budgetCategoriesProvider); if (ref.read(selectedCategory) == null && budgetCategories.isNotEmpty) { - WidgetsBinding.instance.addPostFrameCallback((_) => - ref.read(selectedCategory.notifier).state = budgetCategories.first); + WidgetsBinding.instance + .addPostFrameCallback((_) => ref.read(selectedCategory.notifier).state = budgetCategories.first); } final sortType = ref.watch(selectedTransactionSortProvider); final sortDate = ref.watch(selectedSortDateProvider); @@ -60,8 +57,7 @@ class _TransactionsListviewState extends ConsumerState { if (ref.read(selectedCategory) != null) { transactions = transactions .where( - (element) => - element.budgetCategoryId == ref.read(selectedCategory)!.id, + (element) => element.budgetCategoryId == ref.read(selectedCategory)!.id, ) .toList(); } @@ -79,15 +75,15 @@ class _TransactionsListviewState extends ConsumerState { break; } - WidgetsBinding.instance.addPostFrameCallback((_) => - ref.read(transactionHistoryListProvider.notifier).state = transactions); + WidgetsBinding.instance + .addPostFrameCallback((_) => ref.read(transactionHistoryListProvider.notifier).state = transactions); return Scaffold( endDrawer: Drawer( backgroundColor: Styles.purpleNurple, child: SafeArea( child: Column( children: [ - SizedBox(height: BuildMedia(context).height * 0.15), + SizedBox(height: MediaQuery.of(context).size.height * 0.15), DropdownButton( dropdownColor: Styles.lavender, value: ref.watch(selectedTransactionSortProvider), @@ -108,8 +104,7 @@ class _TransactionsListviewState extends ConsumerState { .toList(), onChanged: (TransactionSort? value) { if (value != null) { - ref.read(selectedTransactionSortProvider.notifier).state = - value; + ref.read(selectedTransactionSortProvider.notifier).state = value; } }), const SizedBox(height: 20), @@ -137,8 +132,7 @@ class _TransactionsListviewState extends ConsumerState { } }), const SizedBox(height: 20), - if (ref.read(selectedTransactionSortProvider) == - TransactionSort.category) + if (ref.read(selectedTransactionSortProvider) == TransactionSort.category) DropdownButton( dropdownColor: Styles.lavender, value: ref.watch(selectedCategory), @@ -154,8 +148,7 @@ class _TransactionsListviewState extends ConsumerState { width: 18, decoration: BoxDecoration( shape: BoxShape.circle, - border: Border.all( - color: Colors.black, width: 1.5), + border: Border.all(color: Colors.black, width: 1.5), color: e.color, ), ), @@ -186,9 +179,7 @@ class _TransactionsListviewState extends ConsumerState { alignment: Alignment.topLeft, child: Padding( padding: const EdgeInsets.only(left: 8.0, top: 16.0), - child: IconButton( - icon: const Icon(Icons.chevron_left), - onPressed: () => Navigator.pop(context)), + child: IconButton(icon: const Icon(Icons.chevron_left), onPressed: () => Navigator.pop(context)), ), ), const Center( @@ -201,14 +192,11 @@ class _TransactionsListviewState extends ConsumerState { Row(mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.only(left: 8.0, top: 16.0), - child: IconButton( - icon: const Icon(Icons.chevron_left), - onPressed: () => Navigator.pop(context)), + child: IconButton(icon: const Icon(Icons.chevron_left), onPressed: () => Navigator.pop(context)), ), const Spacer(), const Padding( - padding: - EdgeInsets.symmetric(vertical: 18.0, horizontal: 0.0), + padding: EdgeInsets.symmetric(vertical: 18.0, horizontal: 0.0), child: Text( 'Transaction History', style: TextStyle(fontSize: 28), @@ -245,8 +233,7 @@ class _TransactionsListviewState extends ConsumerState { } void toggleDrawer() { - if (scaffoldKey.currentState != null && - scaffoldKey.currentState!.isDrawerOpen) { + if (scaffoldKey.currentState != null && scaffoldKey.currentState!.isDrawerOpen) { scaffoldKey.currentState!.openDrawer(); } else if (scaffoldKey.currentState != null) { scaffoldKey.currentState!.openEndDrawer(); @@ -292,8 +279,7 @@ final selectedTransactionSortProvider = StateProvider( (ref) => TransactionSort.all, ); -final selectedSortDateProvider = - StateProvider((ref) => SortDate.decending); +final selectedSortDateProvider = StateProvider((ref) => SortDate.decending); final transactionHistoryListProvider = StateProvider>( (ref) => [], diff --git a/lib/features/budget/widgets/add_budget_category_dialog.dart b/lib/features/budget/widgets/add_budget_category_dialog.dart index 34fb6c6..a993442 100644 --- a/lib/features/budget/widgets/add_budget_category_dialog.dart +++ b/lib/features/budget/widgets/add_budget_category_dialog.dart @@ -1,7 +1,6 @@ +import 'package:colorful_print/colorful_print.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; -import 'package:helpers/helpers/print.dart'; import 'package:rluv/global/styles.dart'; import 'package:rluv/models/budget.dart'; import 'package:rluv/models/budget_category_model.dart'; @@ -17,12 +16,10 @@ class BudgetCategoryDialog extends ConsumerStatefulWidget { final BudgetCategory? category; @override - ConsumerState createState() => - _AddBudgetCategoryDialogState(); + ConsumerState createState() => _AddBudgetCategoryDialogState(); } -class _AddBudgetCategoryDialogState - extends ConsumerState { +class _AddBudgetCategoryDialogState extends ConsumerState { late final Budget? budget; final categoryNameController = TextEditingController(); final amountController = TextEditingController(); @@ -65,12 +62,11 @@ class _AddBudgetCategoryDialogState return Container(); } return SizedBox( - width: BuildMedia(context).width * Styles.dialogScreenWidthFactor, + width: MediaQuery.of(context).size.width * Styles.dialogScreenWidthFactor, child: Stack( children: [ Padding( - padding: - const EdgeInsets.symmetric(vertical: 18.0, horizontal: 32.0), + padding: const EdgeInsets.symmetric(vertical: 18.0, horizontal: 32.0), child: Form( key: formKey, child: Column( @@ -78,9 +74,7 @@ class _AddBudgetCategoryDialogState children: [ Padding( padding: const EdgeInsets.only(bottom: 18.0), - child: Text(widget.category == null - ? 'Add Category:' - : 'Edit Category'), + child: Text(widget.category == null ? 'Add Category:' : 'Edit Category'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -149,8 +143,7 @@ class _AddBudgetCategoryDialogState ], ), Padding( - padding: const EdgeInsets.symmetric( - vertical: 6.0, horizontal: 16.0), + padding: const EdgeInsets.symmetric(vertical: 6.0, horizontal: 16.0), child: SizedBox( height: 76, child: ListView.builder( @@ -164,23 +157,21 @@ class _AddBudgetCategoryDialogState } else { setState(() => selectedColorIndex = -1); } - printBlue(selectedColorIndex); + printColor(selectedColorIndex, textColor: TextColor.blue); }, child: Padding( padding: const EdgeInsets.all(8.0), child: AnimatedContainer( decoration: selectedColorIndex == index ? BoxDecoration( - borderRadius: - BorderRadius.circular(15.0), + borderRadius: BorderRadius.circular(15.0), border: Border.all( color: Styles.washedStone, width: 2.0, ), ) : BoxDecoration( - borderRadius: - BorderRadius.circular(5.0), + borderRadius: BorderRadius.circular(5.0), border: Border.all( color: Colors.transparent, width: 2.0, @@ -205,8 +196,7 @@ class _AddBudgetCategoryDialogState decoration: BoxDecoration( color: colors[index], shape: BoxShape.circle, - border: Border.all( - color: Colors.black, width: 1.5), + border: Border.all(color: Colors.black, width: 1.5), ), ), ], @@ -227,8 +217,7 @@ class _AddBudgetCategoryDialogState color: Styles.expensesRed, text: 'DELETE', onPressed: () { - if (formKey.currentState != null && - formKey.currentState!.validate()) { + if (formKey.currentState != null && formKey.currentState!.validate()) { removeCategory().then((success) { Navigator.pop(context); if (success) { @@ -254,8 +243,7 @@ class _AddBudgetCategoryDialogState color: Styles.lavender, text: 'SAVE', onPressed: () { - if (formKey.currentState != null && - formKey.currentState!.validate()) { + if (formKey.currentState != null && formKey.currentState!.validate()) { submitCategory(colors[selectedColorIndex]).then((_) { Navigator.pop(context); showSnack( @@ -282,7 +270,7 @@ class _AddBudgetCategoryDialogState Future submitCategory(Color categoryColor) async { if (formKey.currentState != null && !formKey.currentState!.validate()) { - printPink('Failed validation'); + printColor('Failed validation', textColor: TextColor.red); return; } Map? budgetData; @@ -296,58 +284,41 @@ class _AddBudgetCategoryDialogState name: categoryNameController.text, ); - budgetData = await ref - .read(apiProvider.notifier) - .post(path: 'budget_category', data: newBudget.toJson()); + budgetData = await ref.read(apiProvider.notifier).post(path: 'budget_category', data: newBudget.toJson()); success = budgetData != null ? budgetData['success'] as bool : false; if (success) { - ref - .read(dashboardProvider.notifier) - .add({'budget_categories': budgetData}); + ref.read(dashboardProvider.notifier).add({'budget_categories': budgetData}); } } else { - final newBudget = - BudgetCategory.copyWith(category: widget.category!, data: { + final newBudget = BudgetCategory.copyWith(category: widget.category!, data: { 'amount': double.parse(amountController.text), 'color': categoryColor, 'name': categoryNameController.text }); - budgetData = await ref - .read(apiProvider.notifier) - .put(path: 'budget_category', data: newBudget.toJson()); + budgetData = await ref.read(apiProvider.notifier).put(path: 'budget_category', data: newBudget.toJson()); success = budgetData != null ? budgetData['success'] as bool : false; if (success) { - ref - .read(dashboardProvider.notifier) - .update({'budget_categories': budgetData}); + ref.read(dashboardProvider.notifier).update({'budget_categories': budgetData}); } } if (success) { showSnack( ref: ref, - text: widget.category == null - ? 'Added budget category!' - : 'Updated category!', + text: widget.category == null ? 'Added budget category!' : 'Updated category!', type: SnackType.error); } else { showSnack( ref: ref, - text: widget.category == null - ? 'Could not add budget category' - : 'Could not update category', + text: widget.category == null ? 'Could not add budget category' : 'Could not update category', type: SnackType.error); } } Future removeCategory() async { - final res = await ref - .read(apiProvider.notifier) - .delete(path: 'budget_category', data: {'id': widget.category!.id}); + final res = await ref.read(apiProvider.notifier).delete(path: 'budget_category', data: {'id': widget.category!.id}); final success = res != null ? res['success'] as bool : false; if (success) { - ref - .read(dashboardProvider.notifier) - .removeWithId('budget_categories', widget.category!.id!); + ref.read(dashboardProvider.notifier).removeWithId('budget_categories', widget.category!.id!); } return success; } diff --git a/lib/features/budget/widgets/add_transaction_dialog.dart b/lib/features/budget/widgets/add_transaction_dialog.dart index b6e0d6f..429585e 100644 --- a/lib/features/budget/widgets/add_transaction_dialog.dart +++ b/lib/features/budget/widgets/add_transaction_dialog.dart @@ -1,7 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; import 'package:rluv/global/utils.dart'; import '../../../global/api.dart'; @@ -18,8 +17,7 @@ class TransactionDialog extends ConsumerStatefulWidget { final Transaction? transaction; @override - ConsumerState createState() => - _AddTransactionDialogState(); + ConsumerState createState() => _AddTransactionDialogState(); } class _AddTransactionDialogState extends ConsumerState { @@ -37,8 +35,7 @@ class _AddTransactionDialogState extends ConsumerState { @override void initState() { if (widget.transaction != null) { - amountController = - TextEditingController(text: widget.transaction!.amount.toString()); + amountController = TextEditingController(text: widget.transaction!.amount.toString()); memoController = TextEditingController(text: widget.transaction!.memo); transactionType = widget.transaction!.type; selectedDate = widget.transaction!.date; @@ -53,8 +50,7 @@ class _AddTransactionDialogState extends ConsumerState { } final u = ref.read(userProvider); if (u == null) { - WidgetsBinding.instance.addPostFrameCallback( - (_) => ref.read(jwtProvider.notifier).revokeToken()); + WidgetsBinding.instance.addPostFrameCallback((_) => ref.read(jwtProvider.notifier).revokeToken()); } else { user = u; } @@ -65,10 +61,9 @@ class _AddTransactionDialogState extends ConsumerState { @override Widget build(BuildContext context) { if (user == null) return Container(); - final List budgetCategories = - ref.read(budgetCategoriesProvider); + final List budgetCategories = ref.read(budgetCategoriesProvider); return SizedBox( - width: BuildMedia(context).width * Styles.dialogScreenWidthFactor, + width: MediaQuery.of(context).size.width * Styles.dialogScreenWidthFactor, child: budgetCategories.isEmpty ? const Padding( padding: EdgeInsets.all(8.0), @@ -91,25 +86,21 @@ class _AddTransactionDialogState extends ConsumerState { onTap: transactionType == TransactionType.expense ? null : () { - setState(() => transactionType = - TransactionType.expense); + setState(() => transactionType = TransactionType.expense); }, child: AnimatedContainer( height: 38, width: 80, decoration: BoxDecoration( borderRadius: const BorderRadius.only( - topLeft: Radius.circular(8.0), - topRight: Radius.circular(8.0)), - color: transactionType == - TransactionType.expense + topLeft: Radius.circular(8.0), topRight: Radius.circular(8.0)), + color: transactionType == TransactionType.expense ? Styles.lavender : Styles.washedStone), duration: const Duration(milliseconds: 300), child: const Padding( padding: EdgeInsets.all(8.0), - child: Text('Expense', - style: TextStyle(fontSize: 16)), + child: Text('Expense', style: TextStyle(fontSize: 16)), ), ), ), @@ -117,25 +108,20 @@ class _AddTransactionDialogState extends ConsumerState { onTap: transactionType == TransactionType.income ? null : () { - setState(() => transactionType = - TransactionType.income); + setState(() => transactionType = TransactionType.income); }, child: AnimatedContainer( height: 38, width: 80, decoration: BoxDecoration( borderRadius: const BorderRadius.only( - topLeft: Radius.circular(8.0), - topRight: Radius.circular(8.0)), + topLeft: Radius.circular(8.0), topRight: Radius.circular(8.0)), color: - transactionType == TransactionType.income - ? Styles.lavender - : Styles.washedStone), + transactionType == TransactionType.income ? Styles.lavender : Styles.washedStone), duration: const Duration(milliseconds: 300), child: const Padding( padding: EdgeInsets.all(8.0), - child: Text('Income', - style: TextStyle(fontSize: 16)), + child: Text('Income', style: TextStyle(fontSize: 16)), ), ), ), @@ -208,9 +194,7 @@ class _AddTransactionDialogState extends ConsumerState { width: 18, decoration: BoxDecoration( shape: BoxShape.circle, - border: Border.all( - color: Colors.black, - width: 1.5), + border: Border.all(color: Colors.black, width: 1.5), color: e.color, ), ), @@ -226,8 +210,7 @@ class _AddTransactionDialogState extends ConsumerState { if (kDebugMode) { print('${value.name} selected'); } - setState(() => - selectedBudgetCategory = value); + setState(() => selectedBudgetCategory = value); } }, ), @@ -247,7 +230,7 @@ class _AddTransactionDialogState extends ConsumerState { ), ), Container( - width: BuildMedia(context).width * 0.65, + width: MediaQuery.of(context).size.width * 0.65, height: 100, decoration: Styles.boxLavenderBubble, child: TextFormField( @@ -269,9 +252,7 @@ class _AddTransactionDialogState extends ConsumerState { Navigator.pop(context); showSnack( ref: ref, - text: widget.transaction != null - ? 'Transaction updated!' - : 'Transaction added!', + text: widget.transaction != null ? 'Transaction updated!' : 'Transaction added!', type: SnackType.success, ); }), @@ -289,9 +270,7 @@ class _AddTransactionDialogState extends ConsumerState { data: Transaction.copyWith(widget.transaction!, { 'memo': memoController.text.isNotEmpty ? memoController.text : null, 'amount': double.parse(amountController.text), - 'budget_category_id': transactionType == TransactionType.income - ? null - : selectedBudgetCategory.id, + 'budget_category_id': transactionType == TransactionType.income ? null : selectedBudgetCategory.id, }).toJson()); } else { data = await ref.read(apiProvider.notifier).post( @@ -299,15 +278,11 @@ class _AddTransactionDialogState extends ConsumerState { data: Transaction( amount: double.parse(amountController.text), createdByUserId: user!.id!, - budgetCategoryId: transactionType == TransactionType.income - ? null - : selectedBudgetCategory.id, + budgetCategoryId: transactionType == TransactionType.income ? null : selectedBudgetCategory.id, budgetId: user!.budgetId, date: DateTime.now(), type: transactionType, - memo: memoController.text.isNotEmpty - ? memoController.text - : null) + memo: memoController.text.isNotEmpty ? memoController.text : null) .toJson()); } final success = data != null ? data['success'] as bool : false; @@ -320,9 +295,7 @@ class _AddTransactionDialogState extends ConsumerState { } else { showSnack( ref: ref, - text: widget.transaction != null - ? 'Failed to edit transaction' - : 'Failed to add transaction', + text: widget.transaction != null ? 'Failed to edit transaction' : 'Failed to add transaction', type: SnackType.error); } } diff --git a/lib/features/budget/widgets/budget_category_bar.dart b/lib/features/budget/widgets/budget_category_bar.dart index 14cd7f4..b586973 100644 --- a/lib/features/budget/widgets/budget_category_bar.dart +++ b/lib/features/budget/widgets/budget_category_bar.dart @@ -1,7 +1,6 @@ import 'dart:math'; import 'package:flutter/material.dart'; -import 'package:helpers/helpers/print.dart'; import 'package:rluv/features/budget/widgets/add_budget_category_dialog.dart'; import 'package:rluv/global/utils.dart'; import 'package:rluv/models/budget_category_model.dart'; @@ -45,8 +44,7 @@ class _BudgetCategoryBarState extends State { } }); final innerHeight = widget.height - widget.innerPadding * 2; - final isBright = - getBrightness(widget.budgetCategory.color) == Brightness.light; + final isBright = getBrightness(widget.budgetCategory.color) == Brightness.light; final textStyle = TextStyle( fontSize: 14, fontWeight: FontWeight.bold, @@ -155,7 +153,6 @@ class _BudgetCategoryBarState extends State { if (!name.contains(' ') || name.indexOf(' ') == name.length - 1) { return name; } - printLime('here'); final words = name.split(' '); int index = 0; String firstLine = words[index]; diff --git a/lib/features/budget/widgets/budget_net_bar.dart b/lib/features/budget/widgets/budget_net_bar.dart index a700c0b..5a7a852 100644 --- a/lib/features/budget/widgets/budget_net_bar.dart +++ b/lib/features/budget/widgets/budget_net_bar.dart @@ -1,14 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:helpers/helpers.dart'; import 'package:rluv/global/styles.dart'; import 'package:rluv/global/utils.dart'; class BudgetNetBar extends StatelessWidget { - const BudgetNetBar( - {super.key, - required this.isPositive, - required this.net, - required this.expected}); + const BudgetNetBar({super.key, required this.isPositive, required this.net, required this.expected}); final bool isPositive; final double net; @@ -16,7 +11,7 @@ class BudgetNetBar extends StatelessWidget { @override Widget build(BuildContext context) { - final screenWidth = BuildMedia(context).width; + final screenWidth = MediaQuery.of(context).size.width; return Container( width: screenWidth * 0.85, decoration: BoxDecoration( @@ -25,8 +20,7 @@ class BudgetNetBar extends StatelessWidget { ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0), - child: - Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( isPositive ? 'Income' : 'Expenses', style: const TextStyle( @@ -35,9 +29,7 @@ class BudgetNetBar extends StatelessWidget { ), Text( '${net.currency()} / ${expected.currency()}', - style: TextStyle( - fontSize: 20, - color: isPositive ? Styles.incomeGreen : Styles.expensesRed), + style: TextStyle(fontSize: 20, color: isPositive ? Styles.incomeGreen : Styles.expensesRed), ), ]), ), diff --git a/lib/features/budget/widgets/transaction_list_item.dart b/lib/features/budget/widgets/transaction_list_item.dart index dd455be..14c074f 100644 --- a/lib/features/budget/widgets/transaction_list_item.dart +++ b/lib/features/budget/widgets/transaction_list_item.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; import 'package:intl/intl.dart'; import 'package:rluv/features/budget/screens/transactions_listview.dart'; import 'package:rluv/features/budget/widgets/add_transaction_dialog.dart'; @@ -19,8 +18,7 @@ class TransactionListItem extends ConsumerStatefulWidget { final int index; @override - ConsumerState createState() => - _TransactionListItemState(); + ConsumerState createState() => _TransactionListItemState(); } class _TransactionListItemState extends ConsumerState { @@ -54,17 +52,13 @@ class _TransactionListItemState extends ConsumerState { child: Padding( padding: const EdgeInsets.only(top: 8.0, left: 8.0, bottom: 8.0), child: ClipRRect( - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(10.0), - bottomLeft: Radius.circular(10.0)), + borderRadius: const BorderRadius.only(topLeft: Radius.circular(10.0), bottomLeft: Radius.circular(10.0)), child: AnimatedContainer( curve: Curves.easeOut, duration: const Duration(milliseconds: 200), height: cardHeight, decoration: const BoxDecoration( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(10.0), - bottomLeft: Radius.circular(10.0)), + borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), bottomLeft: Radius.circular(10.0)), color: Styles.washedStone, ), child: Row( @@ -74,19 +68,16 @@ class _TransactionListItemState extends ConsumerState { duration: const Duration(milliseconds: 200), height: cardHeight, width: 6, - color: transaction!.type == TransactionType.income - ? Styles.incomeBlue - : Styles.expensesOrange), + color: transaction!.type == TransactionType.income ? Styles.incomeBlue : Styles.expensesOrange), SizedBox( - width: BuildMedia(context).width * 0.65, + width: MediaQuery.of(context).size.width * 0.65, child: Padding( padding: const EdgeInsets.only(left: 8.0), child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(DateFormat('EEE MMM d, h:mm a') - .format(transaction!.date)), + Text(DateFormat('EEE MMM d, h:mm a').format(transaction!.date)), Row( children: [ const SizedBox( @@ -101,9 +92,7 @@ class _TransactionListItemState extends ConsumerState { ), ], Text( - transaction!.type == TransactionType.income - ? 'Income' - : budgetCategory!.name, + transaction!.type == TransactionType.income ? 'Income' : budgetCategory!.name, style: const TextStyle(fontSize: 20), ), ], @@ -125,9 +114,7 @@ class _TransactionListItemState extends ConsumerState { transaction!.amount.currency(), style: TextStyle( fontSize: 24, - color: transaction!.type == TransactionType.income - ? Styles.incomeGreen - : Styles.expensesRed), + color: transaction!.type == TransactionType.income ? Styles.incomeGreen : Styles.expensesRed), ), if (showDetails) ...[ IconButton( @@ -140,8 +127,7 @@ class _TransactionListItemState extends ConsumerState { builder: (context) => Dialog( backgroundColor: Styles.dialogColor, shape: Styles.dialogShape, - child: - TransactionDialog(transaction: transaction), + child: TransactionDialog(transaction: transaction), ), ); }, @@ -182,21 +168,14 @@ class _TransactionListItemState extends ConsumerState { } Future deleteTransaction() async { - final res = await ref - .read(apiProvider.notifier) - .delete(path: 'transaction', data: {'id': transaction!.id}); + final res = await ref.read(apiProvider.notifier).delete(path: 'transaction', data: {'id': transaction!.id}); final success = res != null ? res['success'] as bool : false; if (success) { - ref - .read(dashboardProvider.notifier) - .removeWithId('transactions', transaction!.id!); + ref.read(dashboardProvider.notifier).removeWithId('transactions', transaction!.id!); showSnack(ref: ref, text: 'Transaction removed', type: SnackType.success); } else { - showSnack( - ref: ref, - text: 'Could not delete transaction', - type: SnackType.error); + showSnack(ref: ref, text: 'Could not delete transaction', type: SnackType.error); } } } diff --git a/lib/features/notes/screens/notes_screen.dart b/lib/features/notes/screens/notes_screen.dart index 03b79f2..36234f3 100644 --- a/lib/features/notes/screens/notes_screen.dart +++ b/lib/features/notes/screens/notes_screen.dart @@ -1,8 +1,7 @@ +import 'package:colorful_print/colorful_print.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; -import 'package:helpers/helpers/print.dart'; import 'package:rluv/global/utils.dart'; import 'package:rluv/models/shared_note.dart'; @@ -22,7 +21,7 @@ class SharedNotesScreen extends ConsumerStatefulWidget { class _SharedNotesScreenState extends ConsumerState { @override Widget build(BuildContext context) { - final screen = BuildMedia(context).size; + final screen = MediaQuery.of(context).size; final sharedNotes = ref.watch(sharedNotesProvider); return Column( children: [ @@ -47,14 +46,10 @@ class _SharedNotesScreenState extends ConsumerState { ), itemBuilder: (BuildContext context, int index) { final note = sharedNotes[index]; - final colorBrightness = note.color == null - ? Brightness.light - : getBrightness(note.color!); + final colorBrightness = note.color == null ? Brightness.light : getBrightness(note.color!); final textStyle = TextStyle( fontSize: 16.0, - color: colorBrightness == Brightness.light - ? Colors.black54 - : Colors.white70, + color: colorBrightness == Brightness.light ? Colors.black54 : Colors.white70, ); return Padding( padding: const EdgeInsets.all(8.0), @@ -67,14 +62,10 @@ class _SharedNotesScreenState extends ConsumerState { padding: const EdgeInsets.all(8.0), child: Column( children: [ - FittedBox( - child: Text(note.title, - style: const TextStyle(fontSize: 20))), + FittedBox(child: Text(note.title, style: const TextStyle(fontSize: 20))), Flexible( child: Text( - note.content.length > 80 - ? "${note.content.substring(0, 75)}..." - : note.content, + note.content.length > 80 ? "${note.content.substring(0, 75)}..." : note.content, style: textStyle, ), ), @@ -93,9 +84,7 @@ class _SharedNotesScreenState extends ConsumerState { context: context, builder: (BuildContext context) { return Padding( - padding: EdgeInsets.only( - bottom: - MediaQuery.of(context).viewInsets.bottom), + padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), child: NoteBottomSheet( index: index, ), @@ -121,8 +110,7 @@ class _SharedNotesScreenState extends ConsumerState { context: context, builder: (BuildContext context) { return Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom), + padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), child: const NoteBottomSheet( index: null, ), @@ -182,19 +170,14 @@ class _NoteBottomSheetState extends ConsumerState { @override Widget build(BuildContext context) { - final screen = BuildMedia(context).size; + final screen = MediaQuery.of(context).size; return Container( width: screen.width, decoration: BoxDecoration( color: newNote.color ?? Styles.washedStone, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0)), + borderRadius: const BorderRadius.only(topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0)), boxShadow: const [ - BoxShadow( - color: Colors.black26, - spreadRadius: 5.0, - blurRadius: 2.0, - offset: Offset(0, -2)) + BoxShadow(color: Colors.black26, spreadRadius: 5.0, blurRadius: 2.0, offset: Offset(0, -2)) ]), child: Padding( padding: const EdgeInsets.all(16.0), @@ -218,8 +201,7 @@ class _NoteBottomSheetState extends ConsumerState { // decoration: Styles.inputLavenderBubble(), ), Padding( - padding: - const EdgeInsets.symmetric(vertical: 28.0, horizontal: 36.0), + padding: const EdgeInsets.symmetric(vertical: 28.0, horizontal: 36.0), child: UiButton( onPressed: !noteChanged(oldNote, newNote) ? null @@ -229,41 +211,26 @@ class _NoteBottomSheetState extends ConsumerState { try { Response? res; if (widget.index == null) { - res = await ref - .read(apiProvider) - .post('shared_note', data: newNote.toJson()); + res = await ref.read(apiProvider).post('shared_note', data: newNote.toJson()); } else { - res = await ref - .read(apiProvider) - .put('shared_note', data: newNote.toJson()); + res = await ref.read(apiProvider).put('shared_note', data: newNote.toJson()); } if (res.data != null && res.data['success']) { if (widget.index == null) { - ref - .read(dashboardProvider.notifier) - .add({'shared_notes': res.data}); + ref.read(dashboardProvider.notifier).add({'shared_notes': res.data}); } else { - ref - .read(dashboardProvider.notifier) - .update({'shared_notes': res.data}); + ref.read(dashboardProvider.notifier).update({'shared_notes': res.data}); } - showSnack( - ref: ref, - text: 'Added note', - type: SnackType.success); + showSnack(ref: ref, text: 'Added note', type: SnackType.success); } else { showSnack( ref: ref, - text: res.data['message'] ?? - 'Unexpected error occurred', + text: res.data['message'] ?? 'Unexpected error occurred', type: SnackType.error); } } catch (err) { - showSnack( - ref: ref, - text: 'Unexpected error occurred', - type: SnackType.error); - printRed(err); + showSnack(ref: ref, text: 'Unexpected error occurred', type: SnackType.error); + printColor(err, textColor: TextColor.red); } // ignore: use_build_context_synchronously Navigator.pop(context); diff --git a/lib/global/api.dart b/lib/global/api.dart index c559969..96240be 100644 --- a/lib/global/api.dart +++ b/lib/global/api.dart @@ -1,9 +1,9 @@ import 'dart:convert'; +import 'package:colorful_print/colorful_print.dart'; import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/print.dart'; import 'package:jwt_decoder/jwt_decoder.dart'; import 'package:rluv/global/store.dart'; @@ -11,7 +11,7 @@ import '../models/token.dart'; final tokenProvider = StateProvider((ref) { final jwt = ref.watch(jwtProvider); - printLime('Current token: $jwt'); + printColor('Current token: $jwt', textColor: TextColor.green); if (jwt == null) return null; try { return Token.fromJson(JwtDecoder.decode(jwt)); @@ -37,12 +37,12 @@ class _JwtNotifier extends StateNotifier { void setToken(String jwt) { state = jwt; - printCyan('Loaded jwt into client: $jwt'); + printColor('Loaded jwt into client: $jwt', textColor: TextColor.cyan); ref.read(prefsProvider)?.setString('jwt', jwt); } void revokeToken() { - printCyan('jwt token revoked'); + printColor('jwt token revoked', textColor: TextColor.cyan); state = null; ref.read(prefsProvider)?.remove('jwt'); } @@ -58,8 +58,7 @@ class _ApiNotifier extends StateNotifier { // dio.options.baseUrl = "http://localhost:8081/"; dio.options.baseUrl = "https://rluv.fosscat.com/"; dio.interceptors.addAll([ - InterceptorsWrapper(onRequest: - (RequestOptions options, RequestInterceptorHandler handler) { + InterceptorsWrapper(onRequest: (RequestOptions options, RequestInterceptorHandler handler) { final jwt = ref.read(jwtProvider); if (jwt != null) { options.headers['token'] = jwt; @@ -69,12 +68,10 @@ class _ApiNotifier extends StateNotifier { if (response.statusCode != null) { if (response.statusCode == 200) { try { - if ((response.data as Map) - .containsKey('success')) { + if ((response.data as Map).containsKey('success')) { if (!response.data['success']) return handler.next(response); } - if ((response.data as Map) - .containsKey('token')) { + if ((response.data as Map).containsKey('token')) { final jwt = response.data['token']; if (jwt != null) { ref.read(jwtProvider.notifier).setToken(jwt); @@ -83,7 +80,7 @@ class _ApiNotifier extends StateNotifier { } } } catch (err) { - printRed('Error in interceptor for token: $err'); + printColor('Error in interceptor for token: $err', textColor: TextColor.red); return handler.next(response); } } @@ -115,8 +112,7 @@ class _ApiNotifier extends StateNotifier { } } - Future?> put( - {required String path, Object? data}) async { + Future?> put({required String path, Object? data}) async { try { final res = await dio.put(path, data: data); @@ -129,8 +125,7 @@ class _ApiNotifier extends StateNotifier { } } - Future?> post( - {required String path, Object? data}) async { + Future?> post({required String path, Object? data}) async { try { final res = await dio.post(path, data: data); @@ -143,8 +138,7 @@ class _ApiNotifier extends StateNotifier { } } - Future?> delete( - {required String path, Object? data}) async { + Future?> delete({required String path, Object? data}) async { try { final res = await dio.delete(path, data: data); @@ -162,8 +156,7 @@ class _LoggingInterceptor extends Interceptor { _LoggingInterceptor(); @override - Future onRequest( - RequestOptions options, RequestInterceptorHandler handler) async { + Future onRequest(RequestOptions options, RequestInterceptorHandler handler) async { logPrint('///*** REQUEST ***\\\\\\'); printKV('URI', options.uri); printKV('METHOD', options.method); @@ -177,7 +170,7 @@ class _LoggingInterceptor extends Interceptor { @override void onError(DioException err, ErrorInterceptorHandler handler) { - printRed('///*** ERROR RESPONSE ***\\\\\\'); + printColor('///*** ERROR RESPONSE ***\\\\\\', textColor: TextColor.red); logPrint('URI: ${err.requestOptions.uri}'); if (err.response != null) { logPrint('STATUS CODE: ${err.response?.statusCode?.toString()}'); @@ -192,8 +185,7 @@ class _LoggingInterceptor extends Interceptor { } @override - Future onResponse( - Response response, ResponseInterceptorHandler handler) async { + Future onResponse(Response response, ResponseInterceptorHandler handler) async { logPrint('///*** RESPONSE ***\\\\\\'); printKV('URI', response.requestOptions.uri); printKV('STATUS CODE', response.statusCode ?? ''); @@ -206,7 +198,7 @@ class _LoggingInterceptor extends Interceptor { void printKV(String key, Object v) { if (kDebugMode) { - printOrange('$key: $v'); + printColor('$key: $v', textColor: TextColor.orange); } } @@ -215,21 +207,21 @@ class _LoggingInterceptor extends Interceptor { final data = (s as Map?); if (kDebugMode) { if (data == null) { - printAmber({}); + printColor({}, textColor: TextColor.yellow); return; } JsonEncoder encoder = const JsonEncoder.withIndent(' '); String prettyprint = encoder.convert(s); - printAmber(prettyprint); + printColor(prettyprint, textColor: TextColor.yellow); } } catch (_) { - printAmber(s); + printColor(s, textColor: TextColor.yellow); } } void logPrint(String s) { if (kDebugMode) { - printOrange(s); + printColor(s, textColor: TextColor.yellow); } } } diff --git a/lib/global/store.dart b/lib/global/store.dart index f966a74..e42874e 100644 --- a/lib/global/store.dart +++ b/lib/global/store.dart @@ -1,8 +1,8 @@ import 'dart:convert'; +import 'package:colorful_print/colorful_print.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/print.dart'; import 'package:rluv/global/api.dart'; import 'package:rluv/models/budget.dart'; import 'package:rluv/models/budget_category_model.dart'; @@ -13,8 +13,7 @@ import '../models/shared_note.dart'; import '../models/transaction_model.dart'; import '../models/user.dart'; -StateProvider prefsProvider = - StateProvider((ref) => null); +StateProvider prefsProvider = StateProvider((ref) => null); // final StateProvider tokenProvider = StateProvider((ref) { // // final tokenStr = prefs.getString('jwt'); @@ -42,8 +41,7 @@ final Provider familyProvider = Provider( }, ); -final Provider> budgetCategoriesProvider = - Provider>((ref) { +final Provider> budgetCategoriesProvider = Provider>((ref) { final dash = ref.watch(dashboardProvider); if (dash == null) return []; final categoriesData = dash['budget_categories'] as List; @@ -55,7 +53,7 @@ final Provider> budgetCategoriesProvider = final prefs = ref.read(prefsProvider); final budgetJson = jsonEncode({'budget_categories': categoriesData}); - printBlue('updated prefs stored categories'); + printColor('updated prefs stored categories', textColor: TextColor.blue); prefs?.setString('budget_categories', budgetJson); return categories; @@ -71,8 +69,7 @@ final Provider budgetProvider = Provider( }, ); -final Provider> transactionsProvider = - Provider>((ref) { +final Provider> transactionsProvider = Provider>((ref) { final dash = ref.watch(dashboardProvider); if (dash == null) return []; final transactions = dash['transactions'] as List; @@ -83,8 +80,7 @@ final Provider> transactionsProvider = .toList(); }); -final Provider> sharedNotesProvider = - Provider>( +final Provider> sharedNotesProvider = Provider>( (ref) { final dash = ref.watch(dashboardProvider); if (dash == null) return []; @@ -97,8 +93,7 @@ final Provider> sharedNotesProvider = }, ); -final dashboardProvider = - StateNotifierProvider?>( +final dashboardProvider = StateNotifierProvider?>( (ref) { return DashBoardStateNotifier(ref); }, @@ -119,10 +114,10 @@ class DashBoardStateNotifier extends StateNotifier?> { ); final token = ref.read(tokenProvider); if (token?.familyId == null) { - printPink('No token, cannot fetch dashboard'); + printColor('No token, cannot fetch dashboard', textColor: TextColor.red); return; } - printAmber('Fetching dashboard'); + printColor('Fetching dashboard', textColor: TextColor.yellow); state = await ref.read(apiProvider.notifier).get("dashboard"); WidgetsBinding.instance.addPostFrameCallback( (_) => ref.read(loadingStateProvider.notifier).state = false, @@ -131,7 +126,7 @@ class DashBoardStateNotifier extends StateNotifier?> { void update(Map data) { if (state == null) { - printPink('Cant update data, state is null'); + printColor('Cant update data, state is null', textColor: TextColor.red); return; } if (data.keys.length != 1 || data.values.length != 1) { @@ -149,9 +144,7 @@ class DashBoardStateNotifier extends StateNotifier?> { ) .toList(); subStateListObj.removeWhere( - (element) => - element['id'] == - (data.values.first as Map)['id'], + (element) => element['id'] == (data.values.first as Map)['id'], ); subStateListObj.add(data.values.first); @@ -167,7 +160,7 @@ class DashBoardStateNotifier extends StateNotifier?> { void add(Map data) { if (state == null) { - printPink('Cant add data, state is null'); + printColor('Cant add data, state is null', textColor: TextColor.red); return; } if (data.keys.length != 1 || data.values.length != 1) { @@ -192,7 +185,7 @@ class DashBoardStateNotifier extends StateNotifier?> { void removeWithId(String stateKey, int id) { if (state == null) { - printPink('Cant remove data, state is null'); + printColor('Cant remove data, state is null', textColor: TextColor.red); return; } switch (stateKey) { @@ -201,8 +194,7 @@ class DashBoardStateNotifier extends StateNotifier?> { case 'shared_noted': final subStateList = state![stateKey] as List; final newState = state; - subStateList - .removeWhere((e) => (e as Map)['id'] == id); + subStateList.removeWhere((e) => (e as Map)['id'] == id); newState![stateKey] = subStateList; state = {...newState}; // printBlue(state); diff --git a/lib/global/utils.dart b/lib/global/utils.dart index ad9a723..cc9fbcf 100644 --- a/lib/global/utils.dart +++ b/lib/global/utils.dart @@ -1,9 +1,9 @@ import 'dart:math'; +import 'package:colorful_print/colorful_print.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/print.dart'; import 'package:intl/intl.dart'; import 'package:rluv/global/styles.dart'; import 'package:rluv/main.dart'; @@ -20,20 +20,16 @@ bool boolFromJson(int value) => value == 1; int boolToJson(bool hide) => hide ? 1 : 0; -String colorToJson(Color color) => - color.toString().split('(0x')[1].split(')')[0]; +String colorToJson(Color color) => color.toString().split('(0x')[1].split(')')[0]; Color colorFromJson(String hex) => Color(int.parse(hex, radix: 16)); -String? optionalColorToJson(Color? optionalColor) => optionalColor == null - ? null - : optionalColor.toString().split('(0x')[1].split(')')[0]; +String? optionalColorToJson(Color? optionalColor) => + optionalColor == null ? null : optionalColor.toString().split('(0x')[1].split(')')[0]; -Color? optionalColorFromJson(String? hex) => - hex == null ? null : Color(int.parse(hex, radix: 16)); +Color? optionalColorFromJson(String? hex) => hex == null ? null : Color(int.parse(hex, radix: 16)); -Brightness getBrightness(Color color) => - ThemeData.estimateBrightnessForColor(color); +Brightness getBrightness(Color color) => ThemeData.estimateBrightnessForColor(color); List generateColorList() { List colors = []; @@ -60,7 +56,7 @@ extension MonetaryExtension on double { return "\$${pieces.first}.00"; } else { if (pieces.length > 2) { - printBlue(pieces); + printColor(pieces, textColor: TextColor.blue); } return '\$${pieces[0]}.${pieces[1].padRight(2, "0")}'; } @@ -83,7 +79,7 @@ void showSnack( Duration duration = const Duration(seconds: 2)}) { final messengerKey = ref.read(scaffoldMessengerKeyProvider); if (messengerKey.currentState == null) { - printPink('Cannot show snackbar, state == null'); + printColor('Cannot show snackbar, state == null', textColor: TextColor.red); return; } final color = type == SnackType.info @@ -99,8 +95,7 @@ void showSnack( elevation: 8, backgroundColor: Styles.deepPurpleNurple, shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0)), + borderRadius: BorderRadius.only(topLeft: Radius.circular(20.0), topRight: Radius.circular(20.0)), ), content: Padding( padding: const EdgeInsets.all(8.0), @@ -108,9 +103,7 @@ void showSnack( children: [ Padding( padding: const EdgeInsets.only(right: 14.0), - child: Icon( - type == SnackType.success ? Icons.check_circle : Icons.info, - color: color), + child: Icon(type == SnackType.success ? Icons.check_circle : Icons.info, color: color), ), Text(text, style: textStyle), ], @@ -120,8 +113,7 @@ void showSnack( } bool isEmailValid(String email) { - final RegExp regex = - RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$"); + final RegExp regex = RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$"); return regex.hasMatch(email); } diff --git a/lib/main.dart b/lib/main.dart index affef52..d3ddd7a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,6 @@ import 'package:animated_splash_screen/animated_splash_screen.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:helpers/helpers/misc_build/build_media.dart'; import 'package:rluv/features/account/account_create_screen.dart'; import 'package:rluv/features/budget/screens/budget_overview.dart'; import 'package:rluv/features/notes/screens/notes_screen.dart'; @@ -74,8 +73,7 @@ class _HomeState extends ConsumerState { } WidgetsBinding.instance.addPostFrameCallback( (_) { - ref.read(currentHomePageProvider.notifier).state = - const BudgetOverviewScreen(initialData: {}); + ref.read(currentHomePageProvider.notifier).state = const BudgetOverviewScreen(initialData: {}); }, ); super.initState(); @@ -92,8 +90,7 @@ class _HomeState extends ConsumerState { ); }); } - if (ref.watch(currentHomePageProvider).toString() == - "BudgetOverviewScreen") { + if (ref.watch(currentHomePageProvider).toString() == "BudgetOverviewScreen") { initData = {}; } return Scaffold( @@ -104,15 +101,13 @@ class _HomeState extends ConsumerState { child: SafeArea( child: Column( children: [ - SizedBox(height: BuildMedia(context).height * 0.15), + SizedBox(height: MediaQuery.of(context).size.height * 0.15), UiButton( text: 'Budget', color: drawerColors[4], onPressed: () { - if (ref.read(currentHomePageProvider).toString() != - "BudgetOverviewScreen") { - ref.read(currentHomePageProvider.notifier).state = - BudgetOverviewScreen(initialData: initData); + if (ref.read(currentHomePageProvider).toString() != "BudgetOverviewScreen") { + ref.read(currentHomePageProvider.notifier).state = BudgetOverviewScreen(initialData: initData); } toggleDrawer(); }, @@ -121,10 +116,8 @@ class _HomeState extends ConsumerState { text: 'Notes', color: drawerColors[5], onPressed: () { - if (ref.read(currentHomePageProvider).toString() != - "SharedNotesScreen") { - ref.read(currentHomePageProvider.notifier).state = - SharedNotesScreen(initialData: initData); + if (ref.read(currentHomePageProvider).toString() != "SharedNotesScreen") { + ref.read(currentHomePageProvider.notifier).state = SharedNotesScreen(initialData: initData); } toggleDrawer(); }, @@ -134,10 +127,8 @@ class _HomeState extends ConsumerState { text: 'Settings', color: drawerColors[0], onPressed: () { - if (ref.read(currentHomePageProvider).toString() != - "SettingsScreen") { - ref.read(currentHomePageProvider.notifier).state = - const SettingsScreen(); + if (ref.read(currentHomePageProvider).toString() != "SettingsScreen") { + ref.read(currentHomePageProvider.notifier).state = const SettingsScreen(); } toggleDrawer(); }, @@ -190,5 +181,4 @@ final appBarTitleProvider = Provider( ); final scaffoldMessengerKeyProvider = - Provider>( - (ref) => GlobalKey()); + Provider>((ref) => GlobalKey()); diff --git a/pubspec.lock b/pubspec.lock index d1e2155..65ed084 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -161,6 +161,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + colorful_print: + dependency: "direct main" + description: + name: colorful_print + sha256: "2c9784a0d5e6dcd480a0d4ab67b7263e19d31644a30a8bc7f67ceb6db89549c7" + url: "https://pub.dev" + source: hosted + version: "0.1.2" convert: dependency: transitive description: @@ -304,15 +312,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.1" - helpers: - dependency: "direct main" - description: - path: "." - ref: main - resolved-ref: e9486562cb1ec5ac31fdd91ff573e99d51b2d57f - url: "https://github.com/mitch2na/helpers.git" - source: git - version: "1.2.0" highlight: dependency: transitive description: @@ -405,26 +404,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" lints: dependency: transitive description: @@ -477,10 +476,10 @@ packages: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.12.0" mime: dependency: transitive description: @@ -762,10 +761,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" timing: dependency: transitive description: @@ -882,10 +881,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.1" watcher: dependency: transitive description: @@ -936,4 +935,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.3.0 <4.0.0" - flutter: ">=3.19.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 4e578ac..ae01a16 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,11 +37,8 @@ dependencies: cupertino_icons: ^1.0.2 dio: ^5.2.1+1 flutter_riverpod: ^2.1.3 - helpers: - git: - url: https://github.com/mitch2na/helpers.git - ref: main uuid: ^3.0.7 + colorful_print: ^0.1.2 json_annotation: ^4.8.0 shared_preferences: ^2.1.2 intl: ^0.18.1