1- import 'package:twoaxis_finance/app/theme_cubit.dart' ;
21import 'package:twoaxis_finance/features/dashboard/presentation/widgets/dashboard_button.dart' ;
32import 'package:twoaxis_finance/features/transactions/domain/transaction_type.dart' ;
43import 'package:twoaxis_finance/features/transactions/presentation/bloc/transactions_bloc.dart' ;
@@ -27,26 +26,23 @@ class _DashboardPageState extends State<DashboardPage> {
2726
2827 @override
2928 Widget build (BuildContext context) {
30- return BlocBuilder <UserCubit , UserState >(builder: (context, userState) {
31- var user = (userState as UserStateAuthenticated ).user;
29+ return BlocBuilder <UserCubit , UserState >(
30+ builder: (context, userState) {
31+
32+ if (userState is ! UserStateAuthenticated ) return const SizedBox ();
3233
33- return BlocBuilder <ThemeCubit , ThemeMode >(builder: (context, mode) {
3434 return Stack (
3535 children: [
36- if (mode == ThemeMode .dark)
37- Container (
38- height: 500 ,
39- decoration: BoxDecoration (
40- gradient: RadialGradient (
41- colors: [
42- Theme .of (context).colorScheme.primary,
43- Colors .transparent
44- ],
45- radius: 1 ,
46- center: Alignment .topCenter,
47- ),
36+ Container (
37+ height: 500 ,
38+ decoration: BoxDecoration (
39+ gradient: RadialGradient (
40+ colors: [Theme .of (context).colorScheme.primary, Colors .transparent],
41+ radius: 1 ,
42+ center: Alignment .topCenter,
4843 ),
4944 ),
45+ ),
5046 Container (
5147 padding: const EdgeInsets .all (20 ),
5248 child: Column (
@@ -72,9 +68,7 @@ class _DashboardPageState extends State<DashboardPage> {
7268 width: 120 ,
7369 height: 40 ,
7470 decoration: BoxDecoration (
75- color: Theme .of (context)
76- .colorScheme
77- .surfaceContainer,
71+ color: Theme .of (context).colorScheme.surfaceContainer,
7872 borderRadius: BorderRadius .circular (5 ),
7973 ),
8074 ),
@@ -83,15 +77,10 @@ class _DashboardPageState extends State<DashboardPage> {
8377 Text (
8478 formatMoneyWithContext (
8579 context,
86- user.balances.fold <double >(0 ,
87- (sum, balance) => sum + balance.value)),
88- style: TextStyle (
89- fontWeight: FontWeight .bold,
90- fontSize: 40 ,
91- color: mode == ThemeMode .dark
92- ? Theme .of (context).colorScheme.onSurface
93- : Theme .of (context).colorScheme.primary,
94- ),
80+ userState.user.balances.fold <double >(
81+ 0 , (sum, balance) => sum + balance.value)),
82+ style: const TextStyle (
83+ fontWeight: FontWeight .bold, fontSize: 40 ),
9584 ),
9685 IconButton (
9786 onPressed: () {
@@ -135,7 +124,7 @@ class _DashboardPageState extends State<DashboardPage> {
135124 decoration: BoxDecoration (
136125 color: Colors .grey[300 ],
137126 borderRadius:
138- BorderRadius .circular (2 ),
127+ BorderRadius .circular (2 ),
139128 ),
140129 ),
141130 const SizedBox (
@@ -175,8 +164,7 @@ class _DashboardPageState extends State<DashboardPage> {
175164 Navigator .push (
176165 context,
177166 MaterialPageRoute (
178- builder: (context) =>
179- const AnalyticsPage ()));
167+ builder: (context) => const AnalyticsPage ()));
180168 },
181169 ),
182170 DashboardButton (
@@ -186,8 +174,7 @@ class _DashboardPageState extends State<DashboardPage> {
186174 Navigator .push (
187175 context,
188176 MaterialPageRoute (
189- builder: (context) =>
190- const BudgetPage ()));
177+ builder: (context) => const BudgetPage ()));
191178 },
192179 ),
193180 ],
@@ -211,9 +198,9 @@ class _DashboardPageState extends State<DashboardPage> {
211198 children: [
212199 Expanded (
213200 child: Text (
214- "Recent Transactions" ,
215- style: TextStyle (fontSize: 15 ),
216- )),
201+ "Recent Transactions" ,
202+ style: TextStyle (fontSize: 15 ),
203+ )),
217204 Icon (Icons .arrow_forward_ios)
218205 ],
219206 ),
@@ -228,13 +215,11 @@ class _DashboardPageState extends State<DashboardPage> {
228215 return const Center (
229216 child: CircularProgressIndicator (),
230217 );
231- } else if (transactionsState
232- is TransactionsStateError ) {
218+ } else if (transactionsState is TransactionsStateError ) {
233219 return Center (
234220 child: Text (transactionsState.message),
235221 );
236- } else if (transactionsState
237- is TransactionsStateLoaded ) {
222+ } else if (transactionsState is TransactionsStateLoaded ) {
238223 if (transactionsState.transactions.isEmpty) {
239224 return Center (
240225 child: Column (
@@ -263,10 +248,9 @@ class _DashboardPageState extends State<DashboardPage> {
263248 }
264249 return ListView .separated (
265250 padding: EdgeInsets .zero,
266- itemCount:
267- transactionsState.transactions.length <= 30
268- ? transactionsState.transactions.length
269- : 30 ,
251+ itemCount: transactionsState.transactions.length <= 30
252+ ? transactionsState.transactions.length
253+ : 30 ,
270254 itemBuilder: (context, index) {
271255 var item = transactionsState.transactions[index];
272256 return Row (
@@ -275,26 +259,25 @@ class _DashboardPageState extends State<DashboardPage> {
275259 Container (
276260 padding: const EdgeInsets .all (10 ),
277261 decoration: BoxDecoration (
278- color: Theme .of (context)
279- .colorScheme
280- .surfaceBright,
262+ color: Theme .of (context).colorScheme.surfaceBright,
281263 borderRadius:
282- BorderRadius .circular (10 )),
264+ BorderRadius .circular (10 )),
283265 child: Icon (
284266 getCategoryIcon (
285267 item.category,
286268 defaultIcon:
287- item.type == TransactionType .expense
288- ? Icons .payments_rounded
289- : Icons .file_download_rounded,
269+ item.type ==
270+ TransactionType .expense
271+ ? Icons .payments_rounded
272+ : Icons .file_download_rounded,
290273 ),
291274 size: 25 ,
292275 ),
293276 ),
294277 Expanded (
295278 child: Column (
296279 crossAxisAlignment:
297- CrossAxisAlignment .start,
280+ CrossAxisAlignment .start,
298281 children: [
299282 Text (item.name),
300283 Text (
@@ -306,17 +289,17 @@ class _DashboardPageState extends State<DashboardPage> {
306289 ],
307290 ),
308291 ),
309- if (item.type == TransactionType .expense)
292+ if (item.type ==
293+ TransactionType .expense)
310294 Text (
311295 "-${formatMoneyWithContext (context , item .amount )}" ,
312296 style: TextStyle (
313- color: Theme .of (context)
314- .colorScheme
315- .primary,
297+ color: Theme .of (context).colorScheme.primary,
316298 fontSize: 17 ,
317299 fontWeight: FontWeight .bold),
318300 )
319- else if (item.type == TransactionType .income)
301+ else if (item.type ==
302+ TransactionType .income)
320303 Text (
321304 "+${formatMoneyWithContext (context , item .amount )}" ,
322305 style: const TextStyle (
@@ -330,10 +313,7 @@ class _DashboardPageState extends State<DashboardPage> {
330313 separatorBuilder:
331314 (BuildContext context, int index) {
332315 return Divider (
333- color: Theme .of (context)
334- .colorScheme
335- .surfaceBright,
336- height: 20 );
316+ color: Theme .of (context).colorScheme.surfaceBright, height: 20 );
337317 },
338318 );
339319 }
@@ -347,7 +327,7 @@ class _DashboardPageState extends State<DashboardPage> {
347327 )
348328 ],
349329 );
350- });
351- } );
330+ }
331+ );
352332 }
353333}
0 commit comments