mirror of
https://github.com/flutter/samples.git
synced 2026-04-05 03:01:19 +00:00
Add game_template (#1180)
Adds a template / sample for games built in Flutter, with all the bells and whistles, like ads, in-app purchases, audio, main menu, settings, and so on. Co-authored-by: Parker Lougheed Co-authored-by: Shams Zakhour
This commit is contained in:
73
game_template/lib/src/win_game/win_game_screen.dart
Normal file
73
game_template/lib/src/win_game/win_game_screen.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright 2022, the Flutter project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../ads/ads_controller.dart';
|
||||
import '../ads/banner_ad_widget.dart';
|
||||
import '../games_services/score.dart';
|
||||
import '../in_app_purchase/in_app_purchase.dart';
|
||||
import '../style/palette.dart';
|
||||
import '../style/responsive_screen.dart';
|
||||
|
||||
class WinGameScreen extends StatelessWidget {
|
||||
final Score score;
|
||||
|
||||
const WinGameScreen({
|
||||
Key? key,
|
||||
required this.score,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final adsControllerAvailable = context.watch<AdsController?>() != null;
|
||||
final adsRemoved =
|
||||
context.watch<InAppPurchaseController?>()?.adRemoval.active ?? false;
|
||||
final palette = context.watch<Palette>();
|
||||
|
||||
const gap = SizedBox(height: 10);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: palette.backgroundPlaySession,
|
||||
body: ResponsiveScreen(
|
||||
squarishMainArea: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
if (adsControllerAvailable && !adsRemoved) ...[
|
||||
const Expanded(
|
||||
child: Center(
|
||||
child: BannerAdWidget(),
|
||||
),
|
||||
),
|
||||
],
|
||||
gap,
|
||||
const Center(
|
||||
child: Text(
|
||||
'You won!',
|
||||
style: TextStyle(fontFamily: 'Permanent Marker', fontSize: 50),
|
||||
),
|
||||
),
|
||||
gap,
|
||||
Center(
|
||||
child: Text(
|
||||
'Score: ${score.score}\n'
|
||||
'Time: ${score.formattedTime}',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Permanent Marker', fontSize: 20),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
rectangularMenuArea: ElevatedButton(
|
||||
onPressed: () {
|
||||
GoRouter.of(context).pop();
|
||||
},
|
||||
child: const Text('Continue'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user