mirror of
https://github.com/johrpan/christmas_cats.git
synced 2025-10-28 03:07:25 +01:00
Add basic shop screen
This removes the "support me" button on the home screen and replaces it with a link to the future shop. The rewarded video ad can be reached from there. I also cleaned up the localizations and reformated lib/screens/home.dart.
This commit is contained in:
parent
07046d8c05
commit
72aa6d7183
3 changed files with 98 additions and 50 deletions
|
|
@ -15,16 +15,15 @@ class ChristmasCatsLocalizations {
|
||||||
'records3': '3. %i',
|
'records3': '3. %i',
|
||||||
'back': 'Back',
|
'back': 'Back',
|
||||||
'intro': 'Introduction',
|
'intro': 'Introduction',
|
||||||
'ad': 'Support me',
|
'shop': 'Shop',
|
||||||
|
'coins': '%i Coins',
|
||||||
|
'getCoins': 'Get coins',
|
||||||
|
'adLoading': 'Ad loading',
|
||||||
'noAds': 'No ads available',
|
'noAds': 'No ads available',
|
||||||
'poem': 'Cats are climbing Christmas trees,\n'
|
'poem': 'Cats are climbing Christmas trees,\n'
|
||||||
'The trees are getting wiggly,\n'
|
'The trees are getting wiggly,\n'
|
||||||
'You\'ll get a lot of trouble,\n'
|
'You\'ll get a lot of trouble,\n'
|
||||||
'If you don\'t tap them quickly.',
|
'If you don\'t tap them quickly.',
|
||||||
'intro1': 'Cats are climbing Christmas trees,',
|
|
||||||
'intro2': 'The trees are getting wiggly,',
|
|
||||||
'intro3': 'You\'ll get a lot of trouble,',
|
|
||||||
'intro4': 'If You don\'t tap them quickly.',
|
|
||||||
'paused': 'Paused',
|
'paused': 'Paused',
|
||||||
'unpause': 'Continue',
|
'unpause': 'Continue',
|
||||||
'exit': 'Exit',
|
'exit': 'Exit',
|
||||||
|
|
@ -42,16 +41,15 @@ class ChristmasCatsLocalizations {
|
||||||
'records3': '3. %i',
|
'records3': '3. %i',
|
||||||
'back': 'Zurück',
|
'back': 'Zurück',
|
||||||
'intro': 'Einführung',
|
'intro': 'Einführung',
|
||||||
'ad': 'Mich unterstützen',
|
'shop': 'Laden',
|
||||||
|
'coins': '%i Münzen',
|
||||||
|
'adLoading': 'Werbung wird geladen',
|
||||||
'noAds': 'Keine Werbung verfügbar',
|
'noAds': 'Keine Werbung verfügbar',
|
||||||
|
'getCoins': 'Münzen bekommen',
|
||||||
'poem': 'Katzen, die auf Tannen steigen,\n'
|
'poem': 'Katzen, die auf Tannen steigen,\n'
|
||||||
'Welche sich gefährlich neigen,\n'
|
'Welche sich gefährlich neigen,\n'
|
||||||
'Du musst auf die Tannen tippen,\n'
|
'Du musst auf die Tannen tippen,\n'
|
||||||
'Denn sonst werden diese kippen!',
|
'Denn sonst werden diese kippen!',
|
||||||
'intro1': 'Katzen, die auf Tannen steigen,',
|
|
||||||
'intro2': 'Welche sich gefährlich neigen,',
|
|
||||||
'intro3': 'Du musst auf die Tannen tippen,',
|
|
||||||
'intro4': 'Denn sonst werden diese kippen!',
|
|
||||||
'paused': 'Pausiert',
|
'paused': 'Pausiert',
|
||||||
'unpause': 'Weiter',
|
'unpause': 'Weiter',
|
||||||
'exit': 'Beenden',
|
'exit': 'Beenden',
|
||||||
|
|
@ -77,13 +75,12 @@ class ChristmasCatsLocalizations {
|
||||||
String get records3 => localizedStrings['records3'];
|
String get records3 => localizedStrings['records3'];
|
||||||
String get back => localizedStrings['back'];
|
String get back => localizedStrings['back'];
|
||||||
String get intro => localizedStrings['intro'];
|
String get intro => localizedStrings['intro'];
|
||||||
String get ad => localizedStrings['ad'];
|
String get shop => localizedStrings['shop'];
|
||||||
|
String get coins => localizedStrings['coins'];
|
||||||
|
String get adLoading => localizedStrings['adLoading'];
|
||||||
String get noAds => localizedStrings['noAds'];
|
String get noAds => localizedStrings['noAds'];
|
||||||
|
String get getCoins => localizedStrings['getCoins'];
|
||||||
String get poem => localizedStrings['poem'];
|
String get poem => localizedStrings['poem'];
|
||||||
String get intro1 => localizedStrings['intro1'];
|
|
||||||
String get intro2 => localizedStrings['intro2'];
|
|
||||||
String get intro3 => localizedStrings['intro3'];
|
|
||||||
String get intro4 => localizedStrings['intro4'];
|
|
||||||
String get paused => localizedStrings['paused'];
|
String get paused => localizedStrings['paused'];
|
||||||
String get unpause => localizedStrings['unpause'];
|
String get unpause => localizedStrings['unpause'];
|
||||||
String get exit => localizedStrings['exit'];
|
String get exit => localizedStrings['exit'];
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:firebase_admob/firebase_admob.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
|
@ -9,6 +8,7 @@ import '../widgets/menu_entry.dart';
|
||||||
import 'game.dart';
|
import 'game.dart';
|
||||||
import 'intro.dart';
|
import 'intro.dart';
|
||||||
import 'records.dart';
|
import 'records.dart';
|
||||||
|
import 'shop.dart';
|
||||||
|
|
||||||
class HomeScreen extends StatelessWidget {
|
class HomeScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -24,51 +24,39 @@ class HomeScreen extends StatelessWidget {
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
text: localizations.play,
|
text: localizations.play,
|
||||||
onTap: () => Navigator.push(
|
onTap: () => Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => GameScreen(),
|
builder: (context) => GameScreen(),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
text: localizations.records,
|
text: localizations.records,
|
||||||
onTap: () => Navigator.push(
|
onTap: () => Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => RecordsScreen(),
|
builder: (context) => RecordsScreen(),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
text: localizations.intro,
|
text: localizations.intro,
|
||||||
onTap: () => Navigator.push(
|
onTap: () => Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => IntroScreen(),
|
builder: (context) => IntroScreen(),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Builder(
|
Builder(
|
||||||
builder: (context) => MenuEntry(
|
builder: (context) => MenuEntry(
|
||||||
text: localizations.ad,
|
text: localizations.shop,
|
||||||
onTap: () {
|
onTap: () => Navigator.push(
|
||||||
final ad = RewardedVideoAd.instance;
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
ad.listener = (event, {rewardAmount, rewardType}) {
|
builder: (context) => ShopScreen(),
|
||||||
if (event == RewardedVideoAdEvent.loaded) {
|
),
|
||||||
ad.show();
|
),
|
||||||
} else if (event == RewardedVideoAdEvent.failedToLoad) {
|
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
|
||||||
content: Text(localizations.noAds),
|
|
||||||
duration: const Duration(seconds: 2),
|
|
||||||
));
|
|
||||||
} else if (event == RewardedVideoAdEvent.rewarded) {
|
|
||||||
// TODO: Reward user
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ad.load(
|
|
||||||
adUnitId: 'ca-app-pub-4129701777413448/6712208196',
|
|
||||||
targetingInfo: MobileAdTargetingInfo(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
|
|
|
||||||
63
lib/screens/shop.dart
Normal file
63
lib/screens/shop.dart
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
import 'package:firebase_admob/firebase_admob.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:sprintf/sprintf.dart';
|
||||||
|
|
||||||
|
import '../localizations.dart';
|
||||||
|
import '../storage.dart';
|
||||||
|
import '../widgets/menu.dart';
|
||||||
|
import '../widgets/menu_entry.dart';
|
||||||
|
|
||||||
|
class ShopScreen extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final localizations = ChristmasCatsLocalizations.of(context);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
resizeToAvoidBottomInset: false,
|
||||||
|
body: StreamBuilder(
|
||||||
|
stream: storage.coins,
|
||||||
|
builder: (context, snapshot) => Menu(
|
||||||
|
title: localizations.shop,
|
||||||
|
subtitle: sprintf(localizations.coins, [snapshot?.data ?? 0]),
|
||||||
|
children: <Widget>[
|
||||||
|
MenuEntry(
|
||||||
|
text: localizations.getCoins,
|
||||||
|
onTap: () {
|
||||||
|
final scaffold = Scaffold.of(context);
|
||||||
|
scaffold.showSnackBar(SnackBar(
|
||||||
|
content: Text(localizations.adLoading),
|
||||||
|
// Show it until the ad is loaded
|
||||||
|
duration: Duration(minutes: 1),
|
||||||
|
));
|
||||||
|
|
||||||
|
final ad = RewardedVideoAd.instance;
|
||||||
|
ad.listener = (event, {rewardAmount, rewardType}) {
|
||||||
|
scaffold.removeCurrentSnackBar();
|
||||||
|
if (event == RewardedVideoAdEvent.loaded) {
|
||||||
|
ad.show();
|
||||||
|
} else if (event == RewardedVideoAdEvent.failedToLoad) {
|
||||||
|
scaffold.showSnackBar(SnackBar(
|
||||||
|
content: Text(localizations.noAds),
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
));
|
||||||
|
} else if (event == RewardedVideoAdEvent.rewarded) {
|
||||||
|
storage.addCoins(rewardAmount);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ad.load(
|
||||||
|
adUnitId: kReleaseMode
|
||||||
|
? 'ca-app-pub-4129701777413448/6712208196'
|
||||||
|
: 'ca-app-pub-3940256099942544/5224354917',
|
||||||
|
targetingInfo: MobileAdTargetingInfo(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
showBackButton: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue