Removed helpers lib and updated to flutter 3.22
This commit is contained in:
@@ -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<String, dynamic> initialData;
|
||||
|
||||
@override
|
||||
ConsumerState<BudgetOverviewScreen> createState() =>
|
||||
_BudgetOverviewScreenState();
|
||||
ConsumerState<BudgetOverviewScreen> createState() => _BudgetOverviewScreenState();
|
||||
}
|
||||
|
||||
class _BudgetOverviewScreenState extends ConsumerState<BudgetOverviewScreen> {
|
||||
@@ -30,23 +28,18 @@ class _BudgetOverviewScreenState extends ConsumerState<BudgetOverviewScreen> {
|
||||
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<int, double> 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<BudgetOverviewScreen> {
|
||||
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<BudgetOverviewScreen> {
|
||||
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<BudgetOverviewScreen> {
|
||||
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<BudgetOverviewScreen> {
|
||||
),
|
||||
)
|
||||
: 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<BudgetOverviewScreen> {
|
||||
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<BudgetOverviewScreen> {
|
||||
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<BudgetOverviewScreen> {
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const TransactionsListview()));
|
||||
context, MaterialPageRoute(builder: (context) => const TransactionsListview()));
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -292,8 +250,7 @@ class _BudgetOverviewScreenState extends ConsumerState<BudgetOverviewScreen> {
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.loop),
|
||||
color: Styles.seaweedGreen,
|
||||
onPressed: () =>
|
||||
ref.read(dashboardProvider.notifier).fetchDashboard(),
|
||||
onPressed: () => ref.read(dashboardProvider.notifier).fetchDashboard(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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<TransactionsListview> createState() =>
|
||||
_TransactionsListviewState();
|
||||
ConsumerState<TransactionsListview> createState() => _TransactionsListviewState();
|
||||
}
|
||||
|
||||
class _TransactionsListviewState extends ConsumerState<TransactionsListview> {
|
||||
@@ -23,8 +21,7 @@ class _TransactionsListviewState extends ConsumerState<TransactionsListview> {
|
||||
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<TransactionsListview> {
|
||||
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<TransactionsListview> {
|
||||
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<TransactionsListview> {
|
||||
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<TransactionSort>(
|
||||
dropdownColor: Styles.lavender,
|
||||
value: ref.watch(selectedTransactionSortProvider),
|
||||
@@ -108,8 +104,7 @@ class _TransactionsListviewState extends ConsumerState<TransactionsListview> {
|
||||
.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<TransactionsListview> {
|
||||
}
|
||||
}),
|
||||
const SizedBox(height: 20),
|
||||
if (ref.read(selectedTransactionSortProvider) ==
|
||||
TransactionSort.category)
|
||||
if (ref.read(selectedTransactionSortProvider) == TransactionSort.category)
|
||||
DropdownButton<BudgetCategory>(
|
||||
dropdownColor: Styles.lavender,
|
||||
value: ref.watch(selectedCategory),
|
||||
@@ -154,8 +148,7 @@ class _TransactionsListviewState extends ConsumerState<TransactionsListview> {
|
||||
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<TransactionsListview> {
|
||||
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<TransactionsListview> {
|
||||
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<TransactionsListview> {
|
||||
}
|
||||
|
||||
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<TransactionSort>(
|
||||
(ref) => TransactionSort.all,
|
||||
);
|
||||
|
||||
final selectedSortDateProvider =
|
||||
StateProvider<SortDate>((ref) => SortDate.decending);
|
||||
final selectedSortDateProvider = StateProvider<SortDate>((ref) => SortDate.decending);
|
||||
|
||||
final transactionHistoryListProvider = StateProvider<List<Transaction>>(
|
||||
(ref) => [],
|
||||
|
||||
Reference in New Issue
Block a user