From c2c8b25d69fd3d7f562df8a8383ffd1499220377 Mon Sep 17 00:00:00 2001 From: gamer-12748 Date: Tue, 22 Jun 2021 23:23:41 +0530 Subject: [PATCH] back press and exit --- lib/screens/mainGame.dart | 53 +++++++++++++++++++++++++++++++++++---- lib/screens/monument.dart | 22 +++++++++++++--- pubspec.lock | 42 +++++++++++++++---------------- 3 files changed, 87 insertions(+), 30 deletions(-) diff --git a/lib/screens/mainGame.dart b/lib/screens/mainGame.dart index 6db8a12..5afc18f 100644 --- a/lib/screens/mainGame.dart +++ b/lib/screens/mainGame.dart @@ -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; @@ -10,6 +12,48 @@ class MainGame extends StatefulWidget { } class _MainGameState extends State { + Future _onWillPop() { + return showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Are you sure?'), + content: Text('Do you want to exit the app?'), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: Text('No'), + ), + TextButton( + onPressed: () => SystemNavigator.pop(), + child: Text('Yes'), + ), + ], + ), + ) ?? + false; + } + + Future _endGame() { + return showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Are you sure?'), + content: Text('Do you want to End the Game?'), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: Text('No'), + ), + TextButton( + onPressed: () => HomePage(), + child: Text('Yes'), + ), + ], + ), + ) ?? + false; + } + String player1Initials; String player2Initials; @@ -32,8 +76,9 @@ class _MainGameState extends State { @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, @@ -175,9 +220,7 @@ class _MainGameState extends State { ), MaterialButton( onPressed: () { - setState(() { - newDiceImage = Random().nextInt(6) + 1; - }); + _endGame(); }, height: 50.0, padding: EdgeInsets.symmetric(horizontal: 40.0), diff --git a/lib/screens/monument.dart b/lib/screens/monument.dart index 978198f..64a5ced 100644 --- a/lib/screens/monument.dart +++ b/lib/screens/monument.dart @@ -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._(); @@ -38,10 +39,23 @@ class Monument extends StatefulWidget { class _MonumentState extends State { Future _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: [ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: Text('No'), + ), + TextButton( + onPressed: () => SystemNavigator.pop(), + child: Text('Yes'), + ), + ], + ), + ) ?? + false; } @override diff --git a/pubspec.lock b/pubspec.lock index b9607b2..660058d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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"