-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice5_app_dice.dart
237 lines (220 loc) · 8.58 KB
/
practice5_app_dice.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
///////////////////////////////////////////// main.dart /////////////////////////////////////////////
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:dice_app/dice.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Dice Game',
home: Login(),
);
}
}
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
TextEditingController controller = TextEditingController();
TextEditingController controller2 = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.black,
title: Text('Log in'),
leading: Icon(Icons.menu),
actions: [Icon(Icons.search)],
),
body: GestureDetector(
// Focus tree/node/scope
onTap: (){
FocusScope.of(context).unfocus();
},
child: SingleChildScrollView(
child: Column(
children: [
Form(
child: Theme(
data: ThemeData(
primaryColor: Colors.grey[700],
inputDecorationTheme: InputDecorationTheme(
labelStyle: TextStyle(
color: Colors.grey[400],
fontSize: 17,
))),
child: Container(
padding: EdgeInsets.all(20.0),
child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(padding: EdgeInsets.only(top: 50)),
Image(
image: AssetImage('assets/main2.gif'),
height: 250,
),
Text(
'Sign In',
style: TextStyle(
fontSize: 30,
color: Colors.grey[200],
fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
TextField(
controller: controller,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
filled: true,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey[700], width: 0.5),
),
hintText: 'Enter dice',
hintStyle: TextStyle(
color: Colors.grey[500],
)),
keyboardType: TextInputType.text,
),
SizedBox(height: 10),
TextField(
controller: controller2,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
filled: true,
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.grey[700]),
),
hintText: 'Enter Password',
hintStyle:
TextStyle(color: Colors.grey[500])),
keyboardType: TextInputType.text,
obscureText: true,
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Forgot your password?',
style: TextStyle(color: Colors.grey[300])),
Container(),
Text('Sign in',
style: TextStyle(color: Colors.grey[300]))
],
),
SizedBox(height: 10),
ElevatedButton(
style: ButtonStyle(),
child: Icon(Icons.arrow_forward_ios_sharp),
onPressed: () {
if (controller.text == 'dice' && controller2.text == '1234') {Navigator.push(context,MaterialPageRoute(builder: (context) => Dice()));}
else if (controller.text == 'dice' && controller2.text != '1234') {showSnackBar2(context);}
else if (controller.text != 'dice' && controller2.text == '1234') {showSnackBar3(context);}
else {showSnackBar(context);}
},
),
],
),
)))
],
),
),
));
}
}
void showSnackBar(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'로그인 정보를 다시 확인하세요',
textAlign: TextAlign.center,
),
duration: Duration(seconds: 2),
backgroundColor: Colors.blue,
));
}
void showSnackBar2(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Password does not match',
textAlign: TextAlign.center,
),
duration: Duration(seconds: 2),
backgroundColor: Colors.blue,
));
}
void showSnackBar3(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Check the spelling of "dice".',
textAlign: TextAlign.center,
),
duration: Duration(seconds: 2),
backgroundColor: Colors.blue,
));
}
///////////////////////////////////////////// dice.dart /////////////////////////////////////////////
import 'package:flutter/material.dart';
import 'dart:math';
// import 'package:fluttertoast/fluttertoast.dart';
import 'package:toast/toast.dart';
class Dice extends StatefulWidget {
@override
_DiceState createState() => _DiceState();
}
class _DiceState extends State<Dice> {
int leftDice = 1;
int rightDice = 1;
int sumDice = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.black,
title: Text('Dice game'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(32.0),
child: Row(
// mainAxisAlignment:MainAxisAlignment.center,
children: [
Expanded(child: Image.asset('assets/dice$leftDice.png')),
SizedBox(
width: 20.0,
),
Expanded(child: Image.asset('assets/dice$rightDice.png')),
],
),
),
SizedBox(height: 40),
ConstrainedBox(
constraints: BoxConstraints.tightFor(width: 70, height: 40),
child: ElevatedButton(
style: ButtonStyle(),
child: Icon(Icons.arrow_forward_ios_sharp),
onPressed: () {
setState(() {
leftDice = Random().nextInt(6) + 1;
rightDice = Random().nextInt(6) + 1;
sumDice = leftDice + rightDice;
});
Toast.show('Sum of values $sumDice ', context, duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);
},
),
),
],
),
),
);
}
}