-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.dart
177 lines (157 loc) · 4.23 KB
/
first.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
import 'package:flutter/material.dart';
import 'dart:math';
//import './jindal.dart';
import './quiz1.dart';
var b=0;
class Go extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'PressStart',
),
home: ColorGame(),
);
}
}
class ColorGame extends StatefulWidget {
ColorGame({Key key}) : super(key: key);
createState() => ColorGameState();
}
class ColorGameState extends State<ColorGame> {
/// Map to keep track of score
final Map<String, bool> score = {};
/// Choices for game
final Map choices = {
'🍏': Colors.green,
'🍋': Colors.yellow,
'🍅': Colors.red,
'🍇': Colors.purple,
'🥥': Colors.brown,
'🥕': Colors.orange
};
// Random seed to shuffle order of items.
int seed = 0;
int a=0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SCORE ${score.length}/6, $a' ),
backgroundColor: Colors.blue),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.skip_next),
onPressed: () {
Navigator.push(context,new MaterialPageRoute(builder: (context)=>new SecoundRoute()));
/*setState(() {
//score.clear();
seed++;
});*/
},
),
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: choices.keys.map((emoji) {
return Draggable<String>(
data: emoji,
child: Emoji(emoji: score[emoji] == true ? '✅' : emoji),
feedback: Emoji(emoji: emoji),
childWhenDragging: Emoji(emoji: '🌱'),
);
}).toList()),
Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children:
choices.keys.map((emoji) => _buildDragTarget(emoji)).toList()
..shuffle(Random(seed)),
)
],
),
);
}
Widget _buildDragTarget(emoji) {
return DragTarget<String>(
builder: (BuildContext context, List<String> incoming, List rejected) {
if (score[emoji] == true) {
return Container(
color: Colors.white,
child: Text('Correct!'),
alignment: Alignment.center,
height: 80,
width: 200,
);
} else {
return Container(color: choices[emoji], height: 80, width: 200);
}
},
onWillAccept: (data) => data == emoji,
onAccept: (data) {
setState(() {
score[emoji] = true;
//plyr.play('success.mp3');
});
},
onLeave: (data) {
//add();
setState(() {a++;
b=a;
}
);
},
);
}
}
ColorGameState d=new ColorGameState();
class Emoji extends StatelessWidget {
Emoji({Key key, this.emoji}) : super(key: key);
final String emoji;
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: Container(
alignment: Alignment.center,
height: 50,
padding: EdgeInsets.all(10),
child: Text(
emoji,
style: TextStyle(color: Colors.black, fontSize: 50),
),
),
);
}
}
//var ss=d.a;
var v=b+re;
class SecoundRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Final Result'),
),
body: new Center(child:Column( children: <Widget>[
new Text( "result: ${v.toString()}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
),
),
new Text("result in 0 to 14: safe\n"
"result greater then 15: consult a doctor",
style: TextStyle(fontSize: 20),
),
]
,
),
)
,
);
}