From 287cb37048023509fda815e50ffdbd8e7e89f341 Mon Sep 17 00:00:00 2001 From: Vusumuzi Khoza Date: Fri, 29 May 2026 15:23:02 +0200 Subject: [PATCH] minor home screen fix --- lib/screens/home/home_screen.dart | 215 ++++++++++-------- .../transactions/transaction_model.dart | 10 +- .../transactions/transaction_model.g.dart | 2 +- 3 files changed, 124 insertions(+), 103 deletions(-) diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 6bff606..75a3e49 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -113,6 +113,17 @@ class _HomeScreenState extends State with TickerProviderStateMixin { await homeController.getTransactions(prefs.getString("userId")!); } + Future _onRefresh() async { + await homeController.getAccounts(); + await homeController.getCategories(); + await homeController.getProviders(); + + prefs = await SharedPreferences.getInstance(); + if (prefs.getString("userId") != null) { + await homeController.getTransactions(prefs.getString("userId")!); + } + } + void _onRouteChanged() async { final location = router.routerDelegate.currentConfiguration.uri.toString(); if (location.startsWith('/home')) { @@ -159,117 +170,120 @@ class _HomeScreenState extends State with TickerProviderStateMixin { body: ListenableBuilder( listenable: homeController, builder: (context, child) { - return CustomScrollView( - physics: const BouncingScrollPhysics(), - slivers: [ - SliverAppBar( - pinned: false, - floating: true, - stretch: true, - surfaceTintColor: Colors.transparent, - backgroundColor: isDark - ? const Color(0xFF0D0D0D) - : const Color(0xFFF8F9FA), - title: constraints.maxWidth < ResponsivePolicy.md - ? Image( - image: const AssetImage('assets/velocity.png'), - width: 130, - ) - : null, - actions: [ - if (_isLoggedIn) ...[ - Container( - width: 30, - height: 30, - margin: const EdgeInsets.only(right: 4), - decoration: BoxDecoration( - border: Border.all( - color: isDark - ? Colors.white.withValues(alpha: 0.12) - : Colors.black87.withAlpha(20), + return RefreshIndicator( + onRefresh: _onRefresh, + child: CustomScrollView( + physics: const BouncingScrollPhysics(), + slivers: [ + SliverAppBar( + pinned: false, + floating: true, + stretch: true, + surfaceTintColor: Colors.transparent, + backgroundColor: isDark + ? const Color(0xFF0D0D0D) + : const Color(0xFFF8F9FA), + title: constraints.maxWidth < ResponsivePolicy.md + ? Image( + image: const AssetImage('assets/velocity.png'), + width: 130, + ) + : null, + actions: [ + if (_isLoggedIn) ...[ + Container( + width: 30, + height: 30, + margin: const EdgeInsets.only(right: 4), + decoration: BoxDecoration( + border: Border.all( + color: isDark + ? Colors.white.withValues(alpha: 0.12) + : Colors.black87.withAlpha(20), + ), + shape: BoxShape.circle, + gradient: LinearGradient( + colors: [ + theme.colorScheme.primary.withValues( + alpha: 0.15, + ), + theme.colorScheme.tertiary.withValues( + alpha: 0.05, + ), + ], + stops: const [0.3, 0.7], + begin: Alignment.topRight, + end: Alignment.bottomLeft, + ), ), - shape: BoxShape.circle, - gradient: LinearGradient( - colors: [ - theme.colorScheme.primary.withValues( - alpha: 0.15, + child: Center( + child: Text( + initials, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, + color: isDark ? Colors.white : Colors.black87, ), - theme.colorScheme.tertiary.withValues( - alpha: 0.05, - ), - ], - stops: const [0.3, 0.7], - begin: Alignment.topRight, - end: Alignment.bottomLeft, - ), - ), - child: Center( - child: Text( - initials, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.bold, - color: isDark ? Colors.white : Colors.black87, ), ), ), - ), - IconButton( - icon: Icon( - Icons.logout_rounded, - color: isDark ? Colors.white54 : Colors.black54, - size: 20, + IconButton( + icon: Icon( + Icons.logout_rounded, + color: isDark ? Colors.white54 : Colors.black54, + size: 20, + ), + onPressed: _showLogoutDialog, ), - onPressed: _showLogoutDialog, - ), + ], ], - ], - ), - SliverToBoxAdapter( - child: Center( - child: SizedBox( - width: constraints.maxWidth > 600 - ? 600 - : constraints.maxWidth, - child: Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 16, 32), - child: LayoutBuilder( - builder: (context, innerConstraints) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - FadeTransition( - opacity: _providersFadeAnimation, - child: SlideTransition( - position: _providersSlideAnimation, - child: _buildProvidersSection( - theme, - isDark, - innerConstraints, + ), + SliverToBoxAdapter( + child: Center( + child: SizedBox( + width: constraints.maxWidth > 600 + ? 600 + : constraints.maxWidth, + child: Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 16, 32), + child: LayoutBuilder( + builder: (context, innerConstraints) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + FadeTransition( + opacity: _providersFadeAnimation, + child: SlideTransition( + position: _providersSlideAnimation, + child: _buildProvidersSection( + theme, + isDark, + innerConstraints, + ), ), ), - ), - const SizedBox(height: 24), - FadeTransition( - opacity: _transactionsFadeAnimation, - child: SlideTransition( - position: _transactionsSlideAnimation, - child: _buildTransactionsSection( - theme, - isDark, - innerConstraints, + const SizedBox(height: 24), + FadeTransition( + opacity: _transactionsFadeAnimation, + child: SlideTransition( + position: _transactionsSlideAnimation, + child: _buildTransactionsSection( + theme, + isDark, + innerConstraints, + ), ), ), - ), - ], - ); - }, + ], + ); + }, + ), ), ), ), ), - ), - ], + ], + ), ); }, ), @@ -299,6 +313,15 @@ class _HomeScreenState extends State with TickerProviderStateMixin { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ _buildSectionLabel(theme, isDark, Icons.grid_view_rounded, "Pay"), + IconButton( + icon: Icon( + Icons.refresh_rounded, + color: isDark ? Colors.white54 : Colors.black54, + size: 20, + ), + onPressed: _onRefresh, + tooltip: 'Refresh', + ), ], ), const SizedBox(height: 12), diff --git a/lib/screens/transactions/transaction_model.dart b/lib/screens/transactions/transaction_model.dart index eaea708..eb51b67 100644 --- a/lib/screens/transactions/transaction_model.dart +++ b/lib/screens/transactions/transaction_model.dart @@ -34,9 +34,7 @@ class AdditionalDataJsonConverter @override List>? fromJson(List? json) { - return json - ?.map((e) => Map.from(e as Map)) - .toList(); + return json?.map((e) => Map.from(e as Map)).toList(); } @override @@ -61,7 +59,7 @@ class TransactionModel { final Decimal totalAmount; final String reference; final String paymentProcessorLabel; - final String integrationProcessorLabel; + final String? integrationProcessorLabel; final String confirmationProcessorLabel; final String providerLabel; final String debitPhone; @@ -109,7 +107,7 @@ class TransactionModel { required this.totalAmount, required this.reference, required this.paymentProcessorLabel, - required this.integrationProcessorLabel, + this.integrationProcessorLabel, required this.confirmationProcessorLabel, required this.providerLabel, required this.debitPhone, @@ -150,4 +148,4 @@ class TransactionModel { _$TransactionModelFromJson(json); Map toJson() => _$TransactionModelToJson(this); -} \ No newline at end of file +} diff --git a/lib/screens/transactions/transaction_model.g.dart b/lib/screens/transactions/transaction_model.g.dart index c8cce0e..f7f7b48 100644 --- a/lib/screens/transactions/transaction_model.g.dart +++ b/lib/screens/transactions/transaction_model.g.dart @@ -26,7 +26,7 @@ TransactionModel _$TransactionModelFromJson(Map json) => ), reference: json['reference'] as String, paymentProcessorLabel: json['paymentProcessorLabel'] as String, - integrationProcessorLabel: json['integrationProcessorLabel'] as String, + integrationProcessorLabel: json['integrationProcessorLabel'] as String?, confirmationProcessorLabel: json['confirmationProcessorLabel'] as String, providerLabel: json['providerLabel'] as String, debitPhone: json['debitPhone'] as String,