diff --git a/prediqo_mobile/lib/features/home/presentation/home_screen.dart b/prediqo_mobile/lib/features/home/presentation/home_screen.dart index b9e20c99..36537255 100644 --- a/prediqo_mobile/lib/features/home/presentation/home_screen.dart +++ b/prediqo_mobile/lib/features/home/presentation/home_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import '../../../core/di/injection.dart'; @@ -6,6 +7,7 @@ import '../../../core/errors/app_exception.dart'; import '../../../core/theme/app_colors.dart'; import '../../../core/utils/amount_utils.dart'; import '../../../data/models/advertisement_models.dart'; +import '../../../data/models/balance_model.dart'; import '../../../data/models/game_catalog_models.dart'; import '../../../data/models/referral_models.dart'; import '../../../domain/repositories/advertisement_repository.dart'; @@ -16,6 +18,7 @@ import '../../../domain/repositories/repositories.dart'; import '../../../l10n/app_strings.dart'; import '../../../shared/utils/app_update.dart'; import '../../../shared/widgets/app_snackbar.dart'; +import '../../../shared/widgets/balance_hero_card.dart'; import '../../../shared/widgets/language_toggle_button.dart'; import '../../../shared/widgets/pred_card.dart'; import '../../../shared/widgets/pred_skeleton.dart'; @@ -46,10 +49,8 @@ class _HomeScreenState extends State { bool _adsLoading = true; bool _gamesLoading = true; bool _referralLoading = false; - bool _adsRetrying = false; bool _gamesRetrying = false; bool _referralRetrying = false; - String? _adsError; String? _gamesError; String? _referralError; @@ -115,8 +116,6 @@ class _HomeScreenState extends State { if (!keep) { setState(() { _adsLoading = true; - _adsError = null; - _adsRetrying = force; }); } try { @@ -128,18 +127,11 @@ class _HomeScreenState extends State { setState(() { _heroAds = ads; _adsLoading = false; - _adsError = null; - _adsRetrying = false; }); - } catch (e) { + } catch (_) { if (!mounted) return; - setState(() { - _adsLoading = false; - _adsRetrying = false; - if (_heroAds.isEmpty) { - _adsError = AppException.connectionFailedMessage; - } - }); + // Soft-fail: keep last ads or empty carousel placeholder. + setState(() => _adsLoading = false); } }(); _adsInFlight = future.whenComplete(() => _adsInFlight = null); @@ -231,6 +223,9 @@ class _HomeScreenState extends State { } Future _load({bool force = false}) async { + if (force && mounted) { + context.read().add(const WalletLoadRequested()); + } await Future.wait([ _loadAds(force: force), _loadGames(force: force), @@ -253,186 +248,270 @@ class _HomeScreenState extends State { context.go(gamePlayRoute(game)); } + BalanceModel? _usdtBalance(List balances) { + for (final b in balances) { + if (b.walletType.code.toUpperCase().contains('USDT')) return b; + } + return balances.isEmpty ? null : balances.first; + } + @override Widget build(BuildContext context) { final s = context.strings; - return RefreshIndicator( - onRefresh: () => _load(force: true), - child: CustomScrollView( - physics: const AlwaysScrollableScrollPhysics( - parent: BouncingScrollPhysics(), - ), - slivers: [ - SliverAppBar( - floating: true, - pinned: false, - centerTitle: false, - title: Row( - children: [ - const PrediqoLogo(size: 28, showWordmark: false), - const SizedBox(width: 10), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, + final bottomInset = MediaQuery.paddingOf(context).bottom; + + return AnnotatedRegion( + value: const SystemUiOverlayStyle( + statusBarColor: Colors.transparent, + statusBarIconBrightness: Brightness.light, + statusBarBrightness: Brightness.dark, + ), + child: Column( + children: [ + DecoratedBox( + decoration: const BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + Color(0xFF059669), + Color(0xFF047857), + Color(0xFF0F172A), + ], + ), + ), + child: SafeArea( + bottom: false, + child: SizedBox( + height: kToolbarHeight, + child: Padding( + padding: const EdgeInsets.only(left: 16, right: 4), + child: Row( children: [ + const PrediqoLogo(size: 28, showWordmark: false), + const SizedBox(width: 10), Text( s.appName, - style: const TextStyle(fontWeight: FontWeight.w900, letterSpacing: 0.2), + style: const TextStyle( + fontWeight: FontWeight.w900, + letterSpacing: 0.4, + color: Colors.white, + fontSize: 20, + ), ), - Text( - s.tagline, - style: Theme.of(context).textTheme.labelSmall?.copyWith( - color: AppColors.textMuted, - ), + const Spacer(), + const LanguageToggleButton(), + _HeaderIconButton( + tooltip: s.appUpdate, + icon: Icons.system_update_alt_rounded, + foregroundColor: Colors.white, + showBadge: _updateAvailable, + badgeColor: AppColors.warning, + onPressed: _onUpdateTap, + ), + _HeaderIconButton( + tooltip: s.notificationsTitle, + icon: Icons.notifications_none_rounded, + foregroundColor: Colors.white, + showBadge: _unreadNotifications > 0, + badgeLabel: + _unreadNotifications > 9 ? '9+' : '$_unreadNotifications', + onPressed: () async { + await context.push('/notifications'); + if (mounted) _refreshUnread(); + }, ), ], ), ), - ], + ), ), - actions: [ - const LanguageToggleButton(), - _HeaderIconButton( - tooltip: s.appUpdate, - icon: Icons.system_update_alt_rounded, - showBadge: _updateAvailable, - badgeColor: AppColors.warning, - onPressed: _onUpdateTap, - ), - _HeaderIconButton( - tooltip: s.notificationsTitle, - icon: Icons.notifications_none_rounded, - showBadge: _unreadNotifications > 0, - badgeLabel: _unreadNotifications > 9 ? '9+' : '$_unreadNotifications', - onPressed: () async { - await context.push('/notifications'); - if (mounted) _refreshUnread(); - }, - ), - const SizedBox(width: 4), - ], ), - SliverPadding( - padding: const EdgeInsets.fromLTRB(20, 8, 20, 32), - sliver: SliverList( - delegate: SliverChildListDelegate([ - if (_adsError != null && _heroAds.isEmpty) - SectionError( - message: _adsError!, - retrying: _adsRetrying, - onRetry: () => _loadAds(force: true), - ) - else - HomeAdCarousel( - ads: _heroAds, - loading: _adsLoading && _heroAds.isEmpty, - ), - const SizedBox(height: 22), - _SectionTitle(title: s.playNow, subtitle: s.playNowSubtitle), - const SizedBox(height: 12), - if (_gamesError != null && _games.isEmpty) - SectionError( - message: _gamesError!, - retrying: _gamesRetrying, - onRetry: () => _loadGames(force: true), - ) - else if (_games.isNotEmpty) - ..._games.take(4).map( - (g) => Padding( - padding: const EdgeInsets.only(bottom: 10), - child: _GameCard(game: g, onTap: () => _openGame(g)), + Expanded( + child: RefreshIndicator( + onRefresh: () => _load(force: true), + child: CustomScrollView( + physics: const AlwaysScrollableScrollPhysics( + parent: BouncingScrollPhysics(), + ), + slivers: [ + SliverPadding( + padding: EdgeInsets.fromLTRB(20, 12, 20, 24 + bottomInset), + sliver: SliverList( + delegate: SliverChildListDelegate([ + BlocBuilder( + builder: (context, wallet) { + final balance = _usdtBalance(wallet.balances); + final loading = + wallet.isLoading && wallet.balances.isEmpty; + if (loading) { + return const PredSkeletonCard(height: 132); + } + final code = balance?.walletType.code ?? 'USDT'; + final decimals = balance?.walletType.decimals ?? 6; + final amountLabel = balance == null + ? '— $code' + : '${rawAmountToHuman(balance.available, decimals)} $code'; + final subtitle = balance == null + ? s.navWallet + : code.toUpperCase().contains('USDT') + ? 'USDT' + : code; + return BalanceHeroCard( + key: const Key('home_balance_hero'), + amountLabel: amountLabel, + subtitle: subtitle, + trailing: TextButton( + onPressed: () => context.push('/deposit'), + style: TextButton.styleFrom( + foregroundColor: AppColors.primary, + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 8, + ), + backgroundColor: + AppColors.primary.withValues(alpha: 0.14), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + child: Text( + s.deposit, + style: const TextStyle(fontWeight: FontWeight.w800), + ), + ), + ); + }, + ), + const SizedBox(height: 16), + HomeAdCarousel( + ads: _heroAds, + loading: _adsLoading && _heroAds.isEmpty, + ), + const SizedBox(height: 22), + _SectionTitle( + title: s.playNow, + subtitle: s.playNowSubtitle, + ), + const SizedBox(height: 12), + if (_gamesError != null && _games.isEmpty) + SectionError( + message: _gamesError!, + retrying: _gamesRetrying, + onRetry: () => _loadGames(force: true), + ) + else if (_games.isNotEmpty) + ..._games.take(4).map( + (g) => Padding( + padding: const EdgeInsets.only(bottom: 10), + child: _GameCard( + game: g, + onTap: () => _openGame(g), + ), + ), + ) + else if (_gamesLoading) + const Column( + children: [ + PredSkeletonCard(height: 88), + SizedBox(height: 10), + PredSkeletonCard(height: 88), + ], + ) + else + _FeaturedPredictCard( + onTap: () => context.go('/predict'), ), - ) - else if (_gamesLoading) - const Column( - children: [ - PredSkeletonCard(height: 88), - SizedBox(height: 10), - PredSkeletonCard(height: 88), - ], - ) - else - _FeaturedPredictCard(onTap: () => context.go('/predict')), - const SizedBox(height: 8), - _SectionTitle(title: s.shortcuts, subtitle: s.shortcutsSubtitle), - const SizedBox(height: 12), - _ShortcutGrid( - items: [ - _Shortcut( - icon: predictionGamesNavIcon, - label: s.navPredict, - color: AppColors.primary, - onTap: () => context.go('/predict'), - ), - _Shortcut( - icon: Icons.add_rounded, - label: s.deposit, - color: AppColors.info, - onTap: () => context.push('/deposit'), - ), - _Shortcut( - icon: Icons.groups_rounded, - label: s.referralTitle, - color: AppColors.accentGold, - onTap: () => context.push('/referral'), - ), - _Shortcut( - icon: Icons.help_outline_rounded, - label: s.helpCenter, - color: AppColors.walletBonus, - onTap: _openHelp, - ), - ], + const SizedBox(height: 8), + _SectionTitle( + title: s.shortcuts, + subtitle: s.shortcutsSubtitle, + ), + const SizedBox(height: 12), + _ShortcutGrid( + items: [ + _Shortcut( + icon: predictionGamesNavIcon, + label: s.navPredict, + color: AppColors.primary, + onTap: () => context.go('/predict'), + ), + _Shortcut( + icon: Icons.add_rounded, + label: s.deposit, + color: AppColors.info, + onTap: () => context.push('/deposit'), + ), + _Shortcut( + icon: Icons.groups_rounded, + label: s.referralTitle, + color: AppColors.accentGold, + onTap: () => context.push('/referral'), + ), + _Shortcut( + icon: Icons.help_outline_rounded, + label: s.helpCenter, + color: AppColors.walletBonus, + onTap: _openHelp, + ), + ], + ), + if (_totpKnown && !_totpEnabled) ...[ + const SizedBox(height: 22), + _SectionTitle( + title: s.homeSecurity, + subtitle: s.homeTwoFaTitle, + ), + const SizedBox(height: 12), + _TwoFaPromptCard( + onTap: () async { + await context.push('/totp-setup'); + if (mounted) _refreshTotp(); + }, + ), + ], + if (_referralError != null && _referral == null) ...[ + const SizedBox(height: 22), + _SectionTitle( + title: s.yourNetwork, + subtitle: s.yourNetworkSubtitle, + ), + const SizedBox(height: 12), + SectionError( + message: _referralError!, + compact: true, + retrying: _referralRetrying, + onRetry: () => _loadReferral(force: true), + ), + ] else if (_referralLoading && _referral == null) ...[ + const SizedBox(height: 22), + _SectionTitle( + title: s.yourNetwork, + subtitle: s.yourNetworkSubtitle, + ), + const SizedBox(height: 12), + const PredSkeletonCard(height: 96), + ] else if (_referral != null) ...[ + const SizedBox(height: 22), + _SectionTitle( + title: s.yourNetwork, + subtitle: s.yourNetworkSubtitle, + ), + const SizedBox(height: 12), + _ReferralTeaser( + dashboard: _referral!, + onTap: () => context.push('/referral'), + ), + ], + const SizedBox(height: 22), + _HowItWorksCard(onTap: _openHelp), + ]), + ), ), - if (_totpKnown && !_totpEnabled) ...[ - const SizedBox(height: 22), - _SectionTitle(title: s.homeSecurity, subtitle: s.homeTwoFaTitle), - const SizedBox(height: 12), - _TwoFaPromptCard( - onTap: () async { - await context.push('/totp-setup'); - if (mounted) _refreshTotp(); - }, - ), - ], - if (_referralError != null && _referral == null) ...[ - const SizedBox(height: 22), - _SectionTitle( - title: s.yourNetwork, - subtitle: s.yourNetworkSubtitle, - ), - const SizedBox(height: 12), - SectionError( - message: _referralError!, - compact: true, - retrying: _referralRetrying, - onRetry: () => _loadReferral(force: true), - ), - ] else if (_referralLoading && _referral == null) ...[ - const SizedBox(height: 22), - _SectionTitle( - title: s.yourNetwork, - subtitle: s.yourNetworkSubtitle, - ), - const SizedBox(height: 12), - const PredSkeletonCard(height: 96), - ] else if (_referral != null) ...[ - const SizedBox(height: 22), - _SectionTitle( - title: s.yourNetwork, - subtitle: s.yourNetworkSubtitle, - ), - const SizedBox(height: 12), - _ReferralTeaser( - dashboard: _referral!, - onTap: () => context.push('/referral'), - ), - ], - const SizedBox(height: 22), - _HowItWorksCard(onTap: _openHelp), - ]), + ], ), ), + ), ], ), ); @@ -447,6 +526,7 @@ class _HeaderIconButton extends StatelessWidget { this.showBadge = false, this.badgeLabel, this.badgeColor = AppColors.danger, + this.foregroundColor, }); final IconData icon; @@ -455,6 +535,7 @@ class _HeaderIconButton extends StatelessWidget { final bool showBadge; final String? badgeLabel; final Color badgeColor; + final Color? foregroundColor; @override Widget build(BuildContext context) { @@ -464,7 +545,7 @@ class _HeaderIconButton extends StatelessWidget { icon: Stack( clipBehavior: Clip.none, children: [ - Icon(icon), + Icon(icon, color: foregroundColor), if (showBadge) Positioned( right: -4, @@ -504,6 +585,7 @@ class _SectionTitle extends StatelessWidget { @override Widget build(BuildContext context) { + final isDark = Theme.of(context).brightness == Brightness.dark; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -518,7 +600,9 @@ class _SectionTitle extends StatelessWidget { Text( subtitle!, style: Theme.of(context).textTheme.bodySmall?.copyWith( - color: AppColors.textMuted, + color: isDark + ? AppColors.textMuted + : const Color(0xFF64748B), ), ), ], @@ -534,13 +618,15 @@ class _FeaturedPredictCard extends StatelessWidget { @override Widget build(BuildContext context) { final s = context.strings; + final isDark = Theme.of(context).brightness == Brightness.dark; + final endColor = isDark ? AppColors.surfaceCard : Colors.white; return PredCard( onTap: onTap, padding: const EdgeInsets.all(18), gradient: LinearGradient( colors: [ - AppColors.primary.withValues(alpha: 0.2), - AppColors.surfaceCard, + AppColors.primary.withValues(alpha: isDark ? 0.2 : 0.12), + endColor, ], ), child: Row( @@ -564,13 +650,18 @@ class _FeaturedPredictCard extends StatelessWidget { Text( s.predictionGamesSubtitle, style: Theme.of(context).textTheme.bodySmall?.copyWith( - color: AppColors.textSecondary, + color: isDark + ? AppColors.textSecondary + : const Color(0xFF475569), ), ), ], ), ), - const Icon(Icons.chevron_right_rounded, color: AppColors.textMuted), + Icon( + Icons.chevron_right_rounded, + color: isDark ? AppColors.textMuted : const Color(0xFF94A3B8), + ), ], ), ); @@ -699,13 +790,15 @@ class _TwoFaPromptCard extends StatelessWidget { @override Widget build(BuildContext context) { final s = context.strings; + final isDark = Theme.of(context).brightness == Brightness.dark; + final endColor = isDark ? AppColors.surfaceCard : Colors.white; return PredCard( onTap: onTap, padding: const EdgeInsets.all(16), gradient: LinearGradient( colors: [ - AppColors.warning.withValues(alpha: 0.18), - AppColors.surfaceCard, + AppColors.warning.withValues(alpha: isDark ? 0.18 : 0.12), + endColor, ], ), child: Row( @@ -731,7 +824,9 @@ class _TwoFaPromptCard extends StatelessWidget { Text( s.homeTwoFaSubtitle, style: Theme.of(context).textTheme.bodySmall?.copyWith( - color: AppColors.textSecondary, + color: isDark + ? AppColors.textSecondary + : const Color(0xFF475569), ), ), const SizedBox(height: 8), @@ -746,7 +841,10 @@ class _TwoFaPromptCard extends StatelessWidget { ], ), ), - const Icon(Icons.chevron_right_rounded, color: AppColors.textMuted), + Icon( + Icons.chevron_right_rounded, + color: isDark ? AppColors.textMuted : const Color(0xFF94A3B8), + ), ], ), ); diff --git a/prediqo_mobile/lib/features/home/presentation/widgets/home_ad_carousel.dart b/prediqo_mobile/lib/features/home/presentation/widgets/home_ad_carousel.dart index 00a3520a..eaa25cb7 100644 --- a/prediqo_mobile/lib/features/home/presentation/widgets/home_ad_carousel.dart +++ b/prediqo_mobile/lib/features/home/presentation/widgets/home_ad_carousel.dart @@ -75,8 +75,9 @@ class _HomeAdCarouselState extends State { return const PredSkeletonCarousel(height: 168); } + final isDark = Theme.of(context).brightness == Brightness.dark; return Container( - height: 180, + height: 168, padding: const EdgeInsets.all(24), decoration: BoxDecoration( borderRadius: BorderRadius.circular(22), @@ -84,18 +85,22 @@ class _HomeAdCarouselState extends State { begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ - AppColors.primary.withValues(alpha: 0.22), - AppColors.surfaceCard, + AppColors.primary.withValues(alpha: isDark ? 0.22 : 0.14), + isDark ? AppColors.surfaceCard : Colors.white, ], ), - border: Border.all(color: AppColors.border), + border: Border.all( + color: isDark ? AppColors.border : const Color(0xFFE2E8F0), + ), ), alignment: Alignment.center, child: Text( s.promotionsComingSoon, textAlign: TextAlign.center, style: Theme.of(context).textTheme.bodyMedium?.copyWith( - color: AppColors.textSecondary, + color: isDark + ? AppColors.textSecondary + : const Color(0xFF475569), ), ), ); @@ -154,6 +159,14 @@ class _AdSlide extends StatelessWidget { final cta = ad.ctaLabel?.trim(); final hasImage = ad.imageUrl != null && ad.imageUrl!.trim().isNotEmpty; final subtitle = ad.subtitle?.trim(); + final isDark = Theme.of(context).brightness == Brightness.dark; + final mid = isDark ? AppColors.surfaceCard : Colors.white; + final deep = isDark + ? AppColors.bgDark.withValues(alpha: 0.9) + : const Color(0xFFF1F5F9); + final scrim = isDark + ? AppColors.bgDark.withValues(alpha: 0.85) + : Colors.white.withValues(alpha: 0.88); return Material( color: Colors.transparent, child: InkWell( @@ -173,9 +186,9 @@ class _AdSlide extends StatelessWidget { begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ - accent.withValues(alpha: 0.35), - AppColors.surfaceCard, - AppColors.bgDark.withValues(alpha: 0.9), + accent.withValues(alpha: isDark ? 0.35 : 0.22), + mid, + deep, ], ), ), @@ -205,7 +218,7 @@ class _AdSlide extends StatelessWidget { end: Alignment.bottomCenter, colors: [ Colors.transparent, - AppColors.bgDark.withValues(alpha: 0.85), + scrim, ], ), ), @@ -221,10 +234,11 @@ class _AdSlide extends StatelessWidget { ad.title, maxLines: 2, overflow: TextOverflow.ellipsis, - style: const TextStyle( + style: TextStyle( fontWeight: FontWeight.w900, fontSize: 20, height: 1.15, + color: isDark ? null : const Color(0xFF0F172A), ), ), if (subtitle != null && subtitle.isNotEmpty) ...[ @@ -234,7 +248,9 @@ class _AdSlide extends StatelessWidget { maxLines: 3, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.bodyMedium?.copyWith( - color: AppColors.textSecondary, + color: isDark + ? AppColors.textSecondary + : const Color(0xFF475569), height: 1.35, ), ), diff --git a/prediqo_mobile/lib/shared/layout/app_shell.dart b/prediqo_mobile/lib/shared/layout/app_shell.dart index a4ebb0f3..6da4ba8c 100644 --- a/prediqo_mobile/lib/shared/layout/app_shell.dart +++ b/prediqo_mobile/lib/shared/layout/app_shell.dart @@ -61,15 +61,32 @@ class AppShell extends StatelessWidget { final isAdmin = auth.isAdmin; final selected = _selectedIndex(auth); final connectivity = sl(); + // No top SafeArea: tabs paint edge-to-edge (Home gradient / AppBar primary). + // OfflineBanner owns status-bar padding when visible; child top inset is + // cleared while offline so nested AppBars do not double-pad. return Scaffold( - body: SafeArea( - bottom: false, - child: Column( - children: [ - OfflineBanner(controller: connectivity), - Expanded(child: child), - ], - ), + body: Column( + children: [ + OfflineBanner( + controller: connectivity, + includeStatusBarPadding: true, + ), + Expanded( + child: ListenableBuilder( + listenable: connectivity, + builder: (context, _) { + final media = MediaQuery.of(context); + final top = connectivity.isOnline ? media.padding.top : 0.0; + return MediaQuery( + data: media.copyWith( + padding: media.padding.copyWith(top: top), + ), + child: child, + ); + }, + ), + ), + ], ), bottomNavigationBar: PredBottomNav( selectedIndex: isAdmin ? selected : selected.clamp(0, 3), diff --git a/prediqo_mobile/lib/shared/widgets/balance_hero_card.dart b/prediqo_mobile/lib/shared/widgets/balance_hero_card.dart index 510f5d85..5720aa7a 100644 --- a/prediqo_mobile/lib/shared/widgets/balance_hero_card.dart +++ b/prediqo_mobile/lib/shared/widgets/balance_hero_card.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_animate/flutter_animate.dart'; import '../../core/theme/app_colors.dart'; import '../../l10n/app_strings.dart'; import 'pred_card.dart'; @@ -46,7 +45,7 @@ class BalanceHeroCard extends StatelessWidget { style: Theme.of(context).textTheme.headlineLarge?.copyWith( color: isDark ? AppColors.textPrimary : const Color(0xFF0F172A), ), - ).animate().fadeIn(duration: 400.ms).slideY(begin: 0.1, end: 0), + ), ), if (trailing != null) trailing!, ], diff --git a/prediqo_mobile/lib/shared/widgets/offline_banner.dart b/prediqo_mobile/lib/shared/widgets/offline_banner.dart index 6d695d9b..f4f2c7c3 100644 --- a/prediqo_mobile/lib/shared/widgets/offline_banner.dart +++ b/prediqo_mobile/lib/shared/widgets/offline_banner.dart @@ -6,10 +6,18 @@ import '../../l10n/app_strings.dart'; /// Compact strip shown under chrome when the device reports no connectivity. /// Stays visible for the whole offline period; collapses when back online. class OfflineBanner extends StatelessWidget { - const OfflineBanner({super.key, required this.controller}); + const OfflineBanner({ + super.key, + required this.controller, + this.includeStatusBarPadding = false, + }); final ConnectivityController controller; + /// When true (AppShell), pads below the status bar so the strip is readable + /// when the shell no longer applies a top [SafeArea]. + final bool includeStatusBarPadding; + @override Widget build(BuildContext context) { return ListenableBuilder( @@ -17,11 +25,13 @@ class OfflineBanner extends StatelessWidget { builder: (context, _) { if (controller.isOnline) return const SizedBox.shrink(); final s = context.strings; + final topInset = + includeStatusBarPadding ? MediaQuery.paddingOf(context).top : 0.0; return Material( key: const Key('offline_banner'), color: AppColors.warning.withValues(alpha: 0.22), child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10), + padding: EdgeInsets.fromLTRB(14, 10 + topInset, 14, 10), child: Row( children: [ const Icon(Icons.cloud_off_rounded, size: 20, color: AppColors.warning), diff --git a/prediqo_mobile/test/home_section_load_test.dart b/prediqo_mobile/test/home_section_load_test.dart index 6a8c02da..25bbca6f 100644 --- a/prediqo_mobile/test/home_section_load_test.dart +++ b/prediqo_mobile/test/home_section_load_test.dart @@ -28,7 +28,6 @@ import 'package:prediqo_mobile/features/prediction/bloc/prediction_bloc.dart'; import 'package:prediqo_mobile/features/wallet/bloc/wallet_bloc.dart'; import 'package:prediqo_mobile/l10n/locale_controller.dart'; import 'package:prediqo_mobile/shared/widgets/pred_skeleton.dart'; -import 'package:prediqo_mobile/shared/widgets/section_error.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'support/e2e_fixtures.dart'; @@ -212,12 +211,13 @@ void main() { sortOrder: 0, ), ]); - await tester.pumpAndSettle(); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); expect(find.text('Welcome bonus'), findsOneWidget); expect(find.byType(PredSkeletonCarousel), findsNothing); }); - testWidgets('Home shows section error for ads without blanking games', (tester) async { + testWidgets('Home soft-fails ads without blanking games', (tester) async { final ads = _ControllableAds()..failWith = Exception('ads down'); final games = _ControllableGames( cached: const [ @@ -248,15 +248,18 @@ void main() { ), ), ); - await tester.pumpAndSettle(); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); - expect(find.byType(SectionError), findsWidgets); + // Soft-fail: empty promo placeholder, games remain; no ads SectionError. + expect(find.textContaining('promotions coming soon'), findsOneWidget); expect(find.text('Candle Predict'), findsOneWidget); expect(find.text('Shortcuts'), findsOneWidget); }); - testWidgets('Home ads retry does not launch parallel duplicate fetches', (tester) async { - final ads = _ControllableAds()..failWith = Exception('ads down'); + testWidgets('Home ads in-flight dedupes parallel list calls', (tester) async { + final adsHold = Completer>(); + final ads = _ControllableAds()..hold = adsHold; final games = _ControllableGames( cached: const [ GameCatalogItem( @@ -288,26 +291,15 @@ void main() { ); await tester.pump(); await tester.pump(const Duration(milliseconds: 50)); - expect(find.byType(SectionError), findsWidgets); - final before = ads.listCalls; + expect(ads.listCalls, 1); - ads.failWith = null; - ads.hold = Completer>(); - final retry = find.descendant( - of: find.byType(SectionError), - matching: find.byType(IconButton), - ); - expect(retry, findsWidgets); - await tester.ensureVisible(retry.first); - await tester.tap(retry.first); + // Pull-to-refresh while first fetch still held reuses the in-flight future. + await tester.fling(find.byType(CustomScrollView), const Offset(0, 400), 1000); await tester.pump(); - // Second tap while in-flight must not start another fetch. - if (retry.evaluate().isNotEmpty) { - await tester.tap(retry.first); - await tester.pump(); - } - expect(ads.listCalls, before + 1); - ads.hold!.complete(const [ + await tester.pump(const Duration(milliseconds: 100)); + expect(ads.listCalls, 1); + + adsHold.complete(const [ AdvertisementModel( id: 'a1', placement: 'home_hero', @@ -317,7 +309,7 @@ void main() { ), ]); await tester.pump(); - await tester.pump(const Duration(milliseconds: 50)); + await tester.pump(const Duration(milliseconds: 500)); expect(find.text('Welcome bonus'), findsOneWidget); }); }