This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d19c01f
commit 7cbaf60
Showing
12 changed files
with
413 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import 'package:flutter/services.dart'; | ||
import 'package:bharat_mystery/screens/mainGame.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class Game extends StatefulWidget { | ||
const Game({Key pagekey, this.title}) : super(key: pagekey); | ||
final String title; | ||
|
||
@override | ||
_GameState createState() => _GameState(); | ||
} | ||
|
||
class _GameState extends State<Game> with AutomaticKeepAliveClientMixin { | ||
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; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
super.build(context); | ||
//exit app on back pressed | ||
return WillPopScope(onWillPop: _onWillPop, child: GameContent()); | ||
} | ||
|
||
@override | ||
// TODO: implement wantKeepAlive | ||
bool get wantKeepAlive => true; | ||
} | ||
|
||
class GameContent extends StatefulWidget { | ||
@override | ||
_GameContentState createState() => _GameContentState(); | ||
} | ||
|
||
class _GameContentState extends State<GameContent> { | ||
String _player1Name, _player2Name; | ||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); | ||
List players = []; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
backgroundColor: Theme.of(context).focusColor, | ||
body: SingleChildScrollView( | ||
child: Container( | ||
width: MediaQuery.of(context).size.width, | ||
height: MediaQuery.of(context).size.height, | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).accentColor, | ||
), | ||
child: Stack( | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.fromLTRB(10.0, 200.0, 10.0, 20.0), | ||
child: Column( | ||
children: <Widget>[ | ||
Text( | ||
"Player Info", | ||
style: TextStyle( | ||
color: Theme.of(context).highlightColor, | ||
fontFamily: 'LexendDeca', | ||
fontSize: 25.0, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
SizedBox( | ||
height: 30.0, | ||
), | ||
Form( | ||
key: _formKey, | ||
child: Column( | ||
children: <Widget>[ | ||
//textfield player1 | ||
TextFormField( | ||
autocorrect: false, | ||
autofocus: false, | ||
validator: (input) { | ||
if (input.isEmpty) { | ||
return "Please provide Player's Name"; | ||
} | ||
return null; | ||
}, | ||
style: TextStyle(color: Colors.black), | ||
decoration: InputDecoration( | ||
hintText: "Player 1 Name", | ||
hintStyle: TextStyle(color: Colors.grey), | ||
border: OutlineInputBorder( | ||
borderSide: | ||
BorderSide(color: Colors.grey[50]), | ||
borderRadius: BorderRadius.circular(30.0), | ||
), | ||
fillColor: Colors.white, | ||
filled: true, | ||
contentPadding: EdgeInsets.all(20.0)), | ||
onSaved: (input) => _player1Name = input, | ||
keyboardType: TextInputType.emailAddress, | ||
), | ||
SizedBox( | ||
height: 20.0, | ||
), | ||
|
||
//textfield player1 | ||
TextFormField( | ||
autocorrect: false, | ||
autofocus: false, | ||
validator: (input) { | ||
if (input.isEmpty) { | ||
return "Please provide Player's Name"; | ||
} | ||
return null; | ||
}, | ||
style: TextStyle(color: Colors.black), | ||
decoration: InputDecoration( | ||
hintText: "Player 2 Name", | ||
hintStyle: TextStyle(color: Colors.grey), | ||
border: OutlineInputBorder( | ||
borderSide: | ||
BorderSide(color: Colors.grey[50]), | ||
borderRadius: BorderRadius.circular(30.0), | ||
), | ||
fillColor: Colors.white, | ||
filled: true, | ||
contentPadding: EdgeInsets.all(20.0)), | ||
onSaved: (input) => _player2Name = input, | ||
keyboardType: TextInputType.emailAddress, | ||
), | ||
SizedBox( | ||
height: 20.0, | ||
), | ||
|
||
MaterialButton( | ||
onPressed: addUser, | ||
height: 50.0, | ||
padding: EdgeInsets.symmetric(horizontal: 40.0), | ||
shape: StadiumBorder(), | ||
child: Text( | ||
"Start Game", | ||
style: TextStyle( | ||
fontFamily: 'LexendDeca', | ||
fontSize: 16.0, | ||
color: Theme.of(context).cardColor), | ||
), | ||
color: Theme.of(context).highlightColor, | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
Positioned( | ||
bottom: 0, | ||
child: Container( | ||
width: MediaQuery.of(context).size.width, | ||
height: 20.0, | ||
color: Theme.of(context).focusColor, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
void addUser() { | ||
final formState = _formKey.currentState; | ||
if (formState.validate()) { | ||
formState.save(); | ||
players.add(_player1Name); | ||
players.add(_player2Name); | ||
|
||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => MainGame( | ||
players: players, | ||
), | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.