feat(iap): settings screen with remove-ads purchase and restore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-13 14:17:28 +09:00
parent 40c2204d7b
commit 70f87ab8f2
4 changed files with 161 additions and 78 deletions
+6 -1
View File
@@ -54,5 +54,10 @@
}, },
"newBest": "NEW BEST!", "newBest": "NEW BEST!",
"adventure": "Adventure", "adventure": "Adventure",
"classic": "Classic" "classic": "Classic",
"removeAds": "Remove ads",
"removeAdsDescription": "Removes banners and full-screen ads. Reward ads stay available.",
"restorePurchases": "Restore purchases",
"adsRemovedThanks": "Ads removed — thank you!",
"purchaseUnavailable": "Purchases are unavailable right now."
} }
+6 -1
View File
@@ -26,5 +26,10 @@
"bestScore": "최고 {score}", "bestScore": "최고 {score}",
"newBest": "신기록!", "newBest": "신기록!",
"adventure": "어드벤처", "adventure": "어드벤처",
"classic": "클래식" "classic": "클래식",
"removeAds": "광고 제거",
"removeAdsDescription": "배너와 전면 광고를 제거합니다. 보상형 광고는 계속 사용할 수 있습니다.",
"restorePurchases": "구매 복원",
"adsRemovedThanks": "광고가 제거되었습니다 — 감사합니다!",
"purchaseUnavailable": "지금은 구매를 사용할 수 없습니다."
} }
+91 -76
View File
@@ -9,6 +9,7 @@ import '../widgets/banner_ad_slot.dart';
import '../widgets/season_background.dart'; import '../widgets/season_background.dart';
import 'game_screen.dart'; import 'game_screen.dart';
import 'season_map_screen.dart'; import 'season_map_screen.dart';
import 'settings_screen.dart';
class HomeScreen extends ConsumerWidget { class HomeScreen extends ConsumerWidget {
const HomeScreen({super.key}); const HomeScreen({super.key});
@@ -33,89 +34,103 @@ class HomeScreen extends ConsumerWidget {
children: [ children: [
const SeasonBackground(theme: SeasonTheme.fallback), const SeasonBackground(theme: SeasonTheme.fallback),
SafeArea( SafeArea(
child: Column( child: Stack(
children: [ children: [
Expanded( Column(
child: Center( children: [
child: Column( Expanded(
mainAxisAlignment: MainAxisAlignment.center, child: Center(
children: [ child: Column(
_logoMark(), mainAxisAlignment: MainAxisAlignment.center,
const SizedBox(height: 18), children: [
Text( _logoMark(),
l10n.appTitle, const SizedBox(height: 18),
style: Theme.of(context) Text(
.textTheme l10n.appTitle,
.displaySmall style: Theme.of(context)
?.copyWith(fontWeight: FontWeight.w900), .textTheme
), .displaySmall
if (streak.current > 0) ...[ ?.copyWith(fontWeight: FontWeight.w900),
const SizedBox(height: 10),
Chip(
avatar: const Icon(
Icons.local_fire_department,
color: Colors.deepOrange,
size: 20,
), ),
label: Text( if (streak.current > 0) ...[
'${streak.current}', const SizedBox(height: 10),
style: Theme.of(context).textTheme.titleMedium, Chip(
), avatar: const Icon(
), Icons.local_fire_department,
], color: Colors.deepOrange,
const SizedBox(height: 44), size: 20,
FilledButton( ),
style: FilledButton.styleFrom( label: Text(
padding: const EdgeInsets.symmetric( '${streak.current}',
horizontal: 56, vertical: 18), style: Theme.of(context).textTheme.titleMedium,
textStyle: Theme.of(context).textTheme.titleLarge, ),
), ),
onPressed: () { ],
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return; const SizedBox(height: 44),
Navigator.of(context).push( FilledButton(
MaterialPageRoute( style: FilledButton.styleFrom(
builder: (_) => const SeasonMapScreen()), padding: const EdgeInsets.symmetric(
); horizontal: 56, vertical: 18),
}, textStyle: Theme.of(context).textTheme.titleLarge,
child: Text(l10n.adventure), ),
), onPressed: () {
const SizedBox(height: 14), if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
OutlinedButton( Navigator.of(context).push(
style: OutlinedButton.styleFrom( MaterialPageRoute(
padding: const EdgeInsets.symmetric( builder: (_) => const SeasonMapScreen()),
horizontal: 40, vertical: 14),
textStyle: Theme.of(context).textTheme.titleMedium,
),
onPressed: () {
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
ref.read(seasonFlowProvider.notifier).clear();
ref.read(analyticsProvider).endlessStart();
ref.read(gameSessionProvider.notifier).startStage(
StageConfig.endless(
seed: DateTime.now().millisecondsSinceEpoch,
),
); );
Navigator.of(context).push( },
MaterialPageRoute( child: Text(l10n.adventure),
builder: (_) => const GameScreen()),
);
},
child: Text(l10n.classic),
),
if (best > 0) ...[
const SizedBox(height: 10),
Text(
l10n.bestScore(best),
style: TextStyle(
color: Colors.white.withValues(alpha: 0.55),
), ),
), const SizedBox(height: 14),
], OutlinedButton(
], style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 40, vertical: 14),
textStyle: Theme.of(context).textTheme.titleMedium,
),
onPressed: () {
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
ref.read(seasonFlowProvider.notifier).clear();
ref.read(analyticsProvider).endlessStart();
ref.read(gameSessionProvider.notifier).startStage(
StageConfig.endless(
seed: DateTime.now().millisecondsSinceEpoch,
),
);
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const GameScreen()),
);
},
child: Text(l10n.classic),
),
if (best > 0) ...[
const SizedBox(height: 10),
Text(
l10n.bestScore(best),
style: TextStyle(
color: Colors.white.withValues(alpha: 0.55),
),
),
],
],
),
),
),
const BannerAdSlot(),
],
),
Positioned(
top: 8,
right: 8,
child: IconButton(
icon: const Icon(Icons.settings, color: Colors.white70),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const SettingsScreen()),
), ),
), ),
), ),
const BannerAdSlot(),
], ],
), ),
), ),
+58
View File
@@ -0,0 +1,58 @@
// lib/ui/screens/settings_screen.dart
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../l10n/gen/app_localizations.dart';
import '../../state/providers.dart';
class SettingsScreen extends ConsumerWidget {
const SettingsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context)!;
final adsRemoved = ref.watch(adsRemovedProvider);
final iap = ref.read(iapServiceProvider);
ref.listen<bool>(adsRemovedProvider, (prev, next) {
if (next && !(prev ?? false)) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.adsRemovedThanks)),
);
}
});
return Scaffold(
appBar: AppBar(title: Text(l10n.settings)),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
ListTile(
title: Text(l10n.removeAds),
subtitle: Text(l10n.removeAdsDescription),
trailing: adsRemoved
? const Icon(Icons.check_circle, color: Colors.green)
: Text(iap.product?.price ?? ''),
onTap: adsRemoved
? null
: () async {
if (!iap.available || iap.product == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(l10n.purchaseUnavailable)),
);
return;
}
await iap.buyRemoveAds();
},
),
const Divider(),
ListTile(
leading: const Icon(Icons.restore),
title: Text(l10n.restorePurchases),
onTap: () => iap.restorePurchases(),
),
],
),
);
}
}