431 lines
15 KiB
Dart
431 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../core/di/injection.dart';
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../data/models/advertisement_models.dart';
|
|
import '../../../data/models/game_catalog_models.dart';
|
|
import '../../../domain/repositories/advertisement_repository.dart';
|
|
import '../../../domain/repositories/game_catalog_repository.dart';
|
|
import '../../../l10n/app_strings.dart';
|
|
import '../../../shared/utils/app_update.dart';
|
|
import '../../../shared/widgets/language_toggle_button.dart';
|
|
import '../../../shared/widgets/pred_button.dart';
|
|
import '../../../shared/widgets/pred_card.dart';
|
|
import '../../../shared/widgets/prediqo_logo.dart';
|
|
import '../../home/presentation/widgets/home_ad_carousel.dart';
|
|
import '../../home/utils/home_navigation.dart';
|
|
import '../../prediction/utils/game_catalog_ui.dart';
|
|
|
|
/// Public marketing landing for guests (no personal / sensitive data).
|
|
class WelcomeScreen extends StatefulWidget {
|
|
const WelcomeScreen({super.key});
|
|
|
|
@override
|
|
State<WelcomeScreen> createState() => _WelcomeScreenState();
|
|
}
|
|
|
|
class _WelcomeScreenState extends State<WelcomeScreen> {
|
|
bool _loading = true;
|
|
bool _updateAvailable = false;
|
|
List<AdvertisementModel> _heroAds = [];
|
|
List<GameCatalogItem> _games = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final cachedGames = sl<GameCatalogRepository>().peekLast();
|
|
if (cachedGames != null && cachedGames.isNotEmpty) {
|
|
_games = cachedGames;
|
|
}
|
|
final cachedAds = sl<AdvertisementRepository>().peekLast(placement: 'home_hero');
|
|
if (cachedAds != null && cachedAds.isNotEmpty) {
|
|
_heroAds = cachedAds;
|
|
}
|
|
if (_heroAds.isNotEmpty || _games.isNotEmpty) {
|
|
_loading = false;
|
|
}
|
|
_load();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!mounted) return;
|
|
_checkAppUpdate();
|
|
});
|
|
}
|
|
|
|
Future<void> _checkAppUpdate() async {
|
|
final available = await checkAppUpdateAvailable();
|
|
if (!mounted) return;
|
|
setState(() => _updateAvailable = available);
|
|
}
|
|
|
|
Future<void> _load({bool force = false}) async {
|
|
final keep = (_heroAds.isNotEmpty || _games.isNotEmpty) && !force;
|
|
if (!keep) {
|
|
setState(() => _loading = true);
|
|
}
|
|
try {
|
|
final adsFuture = sl<AdvertisementRepository>()
|
|
.list(placement: 'home_hero', force: force)
|
|
.catchError((_) => _heroAds);
|
|
final gamesFuture =
|
|
sl<GameCatalogRepository>().list(force: force).catchError((_) => _games);
|
|
|
|
adsFuture.then((ads) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_heroAds = ads;
|
|
_loading = false;
|
|
});
|
|
});
|
|
gamesFuture.then((games) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_games = games;
|
|
_loading = false;
|
|
});
|
|
});
|
|
|
|
await Future.wait([adsFuture, gamesFuture]);
|
|
if (!mounted) return;
|
|
setState(() => _loading = false);
|
|
} catch (_) {
|
|
if (!mounted) return;
|
|
setState(() => _loading = false);
|
|
}
|
|
}
|
|
|
|
void _goLogin() => context.go('/login');
|
|
void _openHelp() => context.push('/faq');
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = context.strings;
|
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
|
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
|
|
|
return Scaffold(
|
|
key: const Key('welcome_screen'),
|
|
body: RefreshIndicator(
|
|
onRefresh: _load,
|
|
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,
|
|
children: [
|
|
Text(
|
|
s.appName,
|
|
style: const TextStyle(fontWeight: FontWeight.w900, letterSpacing: 0.2),
|
|
),
|
|
Text(
|
|
s.tagline,
|
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
|
color: AppColors.textMuted,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
const LanguageToggleButton(),
|
|
IconButton(
|
|
key: const Key('welcome_app_update'),
|
|
tooltip: s.appUpdate,
|
|
onPressed: () => handleAppUpdateTap(
|
|
context,
|
|
updateAvailable: _updateAvailable,
|
|
),
|
|
icon: Badge(
|
|
isLabelVisible: _updateAvailable,
|
|
smallSize: 8,
|
|
backgroundColor: AppColors.warning,
|
|
child: const Icon(Icons.system_update_alt_rounded),
|
|
),
|
|
),
|
|
IconButton(
|
|
key: const Key('welcome_help'),
|
|
tooltip: s.helpCenter,
|
|
onPressed: _openHelp,
|
|
icon: const Icon(Icons.help_outline_rounded),
|
|
),
|
|
const SizedBox(width: 4),
|
|
],
|
|
),
|
|
SliverPadding(
|
|
padding: EdgeInsets.fromLTRB(20, 8, 20, 48 + bottomInset),
|
|
sliver: SliverList(
|
|
delegate: SliverChildListDelegate([
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(22),
|
|
decoration: BoxDecoration(
|
|
gradient: AppColors.heroGradient(isDark),
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(color: AppColors.border),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const PrediqoLogo(size: 48, showWordmark: false),
|
|
const SizedBox(height: 14),
|
|
Text(
|
|
s.welcomeHeroTitle,
|
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
|
fontWeight: FontWeight.w900,
|
|
height: 1.2,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
s.welcomeHeroSubtitle,
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: AppColors.textSecondary,
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
PredPrimaryButton(
|
|
key: const Key('welcome_get_started'),
|
|
label: s.welcomeGetStarted,
|
|
icon: Icons.login_rounded,
|
|
onPressed: _goLogin,
|
|
),
|
|
],
|
|
),
|
|
).animate().fadeIn(duration: 400.ms).slideY(begin: 0.04, end: 0),
|
|
const SizedBox(height: 22),
|
|
HomeAdCarousel(
|
|
ads: _heroAds,
|
|
loading: _loading && _heroAds.isEmpty,
|
|
onAdTap: (_) => _goLogin(),
|
|
),
|
|
const SizedBox(height: 22),
|
|
Text(
|
|
s.welcomeWhyTitle,
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
_BenefitTile(
|
|
icon: predictionGamesNavIcon,
|
|
color: AppColors.primary,
|
|
title: s.navPredict,
|
|
body: s.welcomeWhyPredict,
|
|
),
|
|
const SizedBox(height: 10),
|
|
_BenefitTile(
|
|
icon: Icons.account_balance_wallet_rounded,
|
|
color: AppColors.info,
|
|
title: s.navWallet,
|
|
body: s.welcomeWhyWallet,
|
|
),
|
|
const SizedBox(height: 10),
|
|
_BenefitTile(
|
|
icon: Icons.groups_rounded,
|
|
color: AppColors.accentGold,
|
|
title: s.referralTitle,
|
|
body: s.welcomeWhyReferral,
|
|
),
|
|
const SizedBox(height: 22),
|
|
Text(
|
|
s.welcomeGamesTitle,
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
s.welcomeGamesSubtitle,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: AppColors.textMuted,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
if (_games.isNotEmpty)
|
|
..._games.take(4).map(
|
|
(g) => Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: _WelcomeGameCard(
|
|
game: g,
|
|
onTap: _goLogin,
|
|
),
|
|
),
|
|
)
|
|
else if (_loading)
|
|
const SizedBox(
|
|
height: 80,
|
|
child: Center(child: CircularProgressIndicator(strokeWidth: 2.5)),
|
|
)
|
|
else
|
|
PredCard(
|
|
onTap: _goLogin,
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: [
|
|
Icon(predictionGamesNavIcon, color: AppColors.primary),
|
|
const SizedBox(width: 12),
|
|
Expanded(child: Text(s.predictionGamesSubtitle)),
|
|
Text(
|
|
s.welcomeSignInToPlay,
|
|
style: const TextStyle(
|
|
color: AppColors.primary,
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 22),
|
|
PredCard(
|
|
onTap: () => context.push('/faq'),
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.help_outline_rounded, color: AppColors.accentGold),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
s.howItWorks,
|
|
style: const TextStyle(fontWeight: FontWeight.w800),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
s.welcomeFaqCta,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: AppColors.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Icon(Icons.chevron_right_rounded, color: AppColors.textMuted),
|
|
],
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _BenefitTile extends StatelessWidget {
|
|
const _BenefitTile({
|
|
required this.icon,
|
|
required this.color,
|
|
required this.title,
|
|
required this.body,
|
|
});
|
|
|
|
final IconData icon;
|
|
final Color color;
|
|
final String title;
|
|
final String body;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return PredCard(
|
|
padding: const EdgeInsets.all(14),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(icon, color: color),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(title, style: const TextStyle(fontWeight: FontWeight.w800)),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
body,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: AppColors.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _WelcomeGameCard extends StatelessWidget {
|
|
const _WelcomeGameCard({required this.game, required this.onTap});
|
|
final GameCatalogItem game;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = context.strings;
|
|
final accent = parseHexColor(game.accentColor);
|
|
return PredCard(
|
|
onTap: onTap,
|
|
padding: const EdgeInsets.all(14),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 44,
|
|
height: 44,
|
|
decoration: BoxDecoration(
|
|
color: accent.withValues(alpha: 0.2),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Icon(gameCatalogIcon(game), color: accent),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(game.title, style: const TextStyle(fontWeight: FontWeight.w800)),
|
|
if (game.description != null && game.description!.isNotEmpty) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
game.description!,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: AppColors.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
Text(
|
|
s.welcomeSignInToPlay,
|
|
style: TextStyle(
|
|
color: accent,
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 11,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|