Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
back press and exit
Browse files Browse the repository at this point in the history
  • Loading branch information
gamer-1478 committed Jun 22, 2021
1 parent 7cbaf60 commit c2c8b25
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 30 deletions.
53 changes: 48 additions & 5 deletions lib/screens/mainGame.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'dart:math';
import 'package:flutter/services.dart';
import 'homepage.dart';

class MainGame extends StatefulWidget {
final List players;
Expand All @@ -10,6 +12,48 @@ class MainGame extends StatefulWidget {
}

class _MainGameState extends State<MainGame> {
Future<bool> _onWillPop() {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text('Do you want to exit the app?'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
TextButton(
onPressed: () => SystemNavigator.pop(),
child: Text('Yes'),
),
],
),
) ??
false;
}

Future<bool> _endGame() {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text('Do you want to End the Game?'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
TextButton(
onPressed: () => HomePage(),
child: Text('Yes'),
),
],
),
) ??
false;
}

String player1Initials;
String player2Initials;

Expand All @@ -32,8 +76,9 @@ class _MainGameState extends State<MainGame> {

@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
return WillPopScope(
onWillPop: _onWillPop,
child: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
Expand Down Expand Up @@ -175,9 +220,7 @@ class _MainGameState extends State<MainGame> {
),
MaterialButton(
onPressed: () {
setState(() {
newDiceImage = Random().nextInt(6) + 1;
});
_endGame();
},
height: 50.0,
padding: EdgeInsets.symmetric(horizontal: 40.0),
Expand Down
22 changes: 18 additions & 4 deletions lib/screens/monument.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:http/http.dart' as http;
import 'package:cached_network_image/cached_network_image.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
import 'package:flutter/services.dart';

class MapUtils {
MapUtils._();
Expand All @@ -38,10 +39,23 @@ class Monument extends StatefulWidget {
class _MonumentState extends State<Monument> {
Future<bool> _onWillPop() {
return showDialog(
context: context,
builder: (context) {
Navigator.of(context).pop(true);
});
context: context,
builder: (context) => AlertDialog(
title: Text('Are you sure?'),
content: Text('Do you want to exit the app?'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
TextButton(
onPressed: () => SystemNavigator.pop(),
child: Text('Yes'),
),
],
),
) ??
false;
}

@override
Expand Down
42 changes: 21 additions & 21 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.7.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -42,7 +42,7 @@ packages:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.5.1"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -119,7 +119,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.3"
curved_navigation_bar:
dependency: "direct main"
description:
Expand All @@ -140,14 +140,14 @@ packages:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "1.1.2"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "5.2.1"
version: "6.1.2"
firebase_auth:
dependency: "direct main"
description:
Expand Down Expand Up @@ -208,7 +208,7 @@ packages:
name: flutter_cache_manager
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
flutter_image:
dependency: transitive
description:
Expand Down Expand Up @@ -358,7 +358,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.4.0"
mgrs_dart:
dependency: transitive
description:
Expand All @@ -379,7 +379,7 @@ packages:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
version: "1.0.0"
octo_image:
dependency: transitive
description:
Expand All @@ -400,7 +400,7 @@ packages:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.27"
version: "1.6.28"
path_provider_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -428,14 +428,14 @@ packages:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+3"
version: "0.0.5"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.2"
version: "1.11.1"
petitparser:
dependency: transitive
description:
Expand All @@ -449,7 +449,7 @@ packages:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
version: "3.0.0"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -470,7 +470,7 @@ packages:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.13"
version: "4.2.1"
proj4dart:
dependency: transitive
description:
Expand Down Expand Up @@ -552,21 +552,21 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
sqflite:
dependency: transitive
description:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2+3"
version: "2.0.0+3"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3+1"
version: "2.0.0+2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -594,7 +594,7 @@ packages:
name: synchronized
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0+2"
version: "3.0.0"
term_glyph:
dependency: transitive
description:
Expand All @@ -608,7 +608,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.4.0"
transparent_image:
dependency: transitive
description:
Expand Down Expand Up @@ -713,7 +713,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.4+1"
version: "2.2.2"
wkt_parser:
dependency: transitive
description:
Expand Down Expand Up @@ -743,5 +743,5 @@ packages:
source: hosted
version: "7.0.0+7"
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.22.2"
dart: ">=2.13.0 <3.0.0"
flutter: ">=1.24.0-10"

0 comments on commit c2c8b25

Please sign in to comment.