Skip to content

Commit 9a22b47

Browse files
thamaraiselvamthamaraiselvam
authored andcommitted
code refactor
1 parent ed7cb2e commit 9a22b47

File tree

7 files changed

+177
-164
lines changed

7 files changed

+177
-164
lines changed

lib/component/ScoreCard.dart

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:numbers/utils/constants.dart';
33
import 'package:numbers/widgets/dashedLine.dart';
4+
import 'package:numbers/widgets/tableRow.dart';
45

56
class ScoreBoard extends StatelessWidget {
67
String title;
@@ -29,11 +30,11 @@ class ScoreBoard extends StatelessWidget {
2930
Table(
3031
columnWidths: {
3132
0: FractionColumnWidth(0.2),
32-
1: FractionColumnWidth(0.6),
33+
1: FractionColumnWidth(0.7),
3334
2: FractionColumnWidth(0.2)
3435
},
3536
children: [
36-
_buildTableRow("Rank,Name,Score"),
37+
buildTableRow("Rank,Name,Score"),
3738
],
3839
),
3940
ListView.builder(
@@ -64,22 +65,4 @@ class ScoreBoard extends StatelessWidget {
6465
),
6566
);
6667
}
67-
68-
TableRow _buildTableRow(String listOfNames) {
69-
return TableRow(
70-
children: listOfNames.split(',').map((name) {
71-
return Container(
72-
child: Text(
73-
name,
74-
style: TextStyle(
75-
fontSize: 13.0,
76-
color: greyFontColor,
77-
fontWeight: FontWeight.bold),
78-
textAlign: TextAlign.left,
79-
),
80-
padding: EdgeInsets.only(top: 15.0, left: 10),
81-
);
82-
}).toList(),
83-
);
84-
}
8568
}

lib/screens/GameScreen/GameScreen.dart

Lines changed: 10 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'dart:async';
22
import 'package:numbers/schema/blackSchema.dart';
3-
import 'package:numbers/utils/constants.dart';
3+
import 'package:numbers/screens/GameScreen/summaryModel.dart';
44
import 'package:numbers/widgets/bgGradient.dart';
55
import 'package:numbers/provider/BlockDataStream.dart';
6-
import 'package:numbers/widgets/targetBlockBuilder.dart';
76
import 'package:flutter/material.dart';
7+
import 'headerInfo.widget.dart';
8+
import 'numberBlocks.widget.dart';
9+
import 'targetBlock.widget.dart';
810

911
class GameScreen extends StatefulWidget {
1012
@override
@@ -42,7 +44,7 @@ class _GameScreenState extends State<GameScreen> {
4244
SizedBox(
4345
height: 10,
4446
),
45-
_headerInfo(),
47+
headerInfo(this.secCounter, this.gameHistory),
4648
SizedBox(
4749
height: 10,
4850
),
@@ -64,7 +66,7 @@ class _GameScreenState extends State<GameScreen> {
6466
if (this.secCounter < 1) {
6567
this.isTimeUp = true;
6668
this.gameTimerObject.cancel();
67-
_showSummary();
69+
showSummary(context, gameHistory);
6870
}
6971
});
7072
});
@@ -158,73 +160,25 @@ class _GameScreenState extends State<GameScreen> {
158160
this.blocks[selectedIndex].color = color;
159161
}
160162

161-
Row _headerInfo() {
162-
return Row(
163-
mainAxisAlignment: MainAxisAlignment.center,
164-
children: <Widget>[
165-
Container(
166-
padding: const EdgeInsets.only(left: 15, right: 10),
167-
width: 100,
168-
color: blackLowOpacity,
169-
child: Row(
170-
children: <Widget>[
171-
Text(
172-
'TIMER : ',
173-
style: TextStyle(
174-
color: Colors.white,
175-
),
176-
textAlign: TextAlign.center,
177-
),
178-
Text(
179-
this.secCounter.toString(),
180-
style: TextStyle(color: Colors.white),
181-
),
182-
],
183-
)),
184-
Container(
185-
margin: const EdgeInsets.only(left: 10),
186-
padding: const EdgeInsets.only(left: 15, right: 10),
187-
width: 100,
188-
color: blackLowOpacity,
189-
child: Row(
190-
children: <Widget>[
191-
Text(
192-
'SCORE : ',
193-
style: TextStyle(
194-
color: Colors.white,
195-
),
196-
textAlign: TextAlign.center,
197-
),
198-
Text(
199-
this.gameHistory['success'].toString(),
200-
style: TextStyle(color: Colors.white),
201-
),
202-
],
203-
))
204-
],
205-
);
206-
}
207-
208163
Container buildNumberBlocks() {
209164
return Container(
210165
// alignment: Alignment.centerLeft,
211166
alignment: Alignment(0.0, 0.0),
212167
// color: Colors.grey,
213168
padding: const EdgeInsets.all(30),
214-
child: Center(
215-
child: Wrap(spacing: 40, runSpacing: 40, children: _generateBlocks(6)),
216-
),
169+
child: Wrap(spacing: 40, runSpacing: 40, children: _generateBlocks(6)),
217170
);
218171
}
219172

220173
List<Widget> _generateBlocks(int size) {
221174
List<Widget> blocks = [];
222175

223176
for (var i = 0; i < size; i++) {
224-
blocks.add(_numberBlock(
177+
blocks.add(numberBlock(
225178
bgColor: this.blocks[i].color,
226179
index: this.blocks[i].index,
227-
value: this.blocks[i].value));
180+
value: this.blocks[i].value,
181+
blockDataStream: this.blockDataStream));
228182
}
229183

230184
return blocks;
@@ -251,92 +205,4 @@ class _GameScreenState extends State<GameScreen> {
251205
},
252206
);
253207
}
254-
255-
Future<void> _showSummary() async {
256-
return showDialog<void>(
257-
context: context,
258-
barrierDismissible: false, // user must tap button!
259-
builder: (BuildContext context) {
260-
return AlertDialog(
261-
content: SingleChildScrollView(
262-
child: Container(
263-
child: Column(
264-
mainAxisAlignment: MainAxisAlignment.center,
265-
children: <Widget>[
266-
Row(
267-
mainAxisAlignment: MainAxisAlignment.center,
268-
children: <Widget>[
269-
Text(
270-
'Score: ',
271-
style: TextStyle(
272-
fontWeight: FontWeight.bold, fontSize: 30),
273-
),
274-
Text(
275-
this.gameHistory['success'].toString(),
276-
style: TextStyle(
277-
fontWeight: FontWeight.bold, fontSize: 30),
278-
),
279-
]),
280-
Row(
281-
mainAxisAlignment: MainAxisAlignment.center,
282-
children: <Widget>[
283-
IconButton(
284-
alignment: Alignment.center,
285-
icon: Icon(Icons.home),
286-
iconSize: 40,
287-
color: Colors.blue,
288-
tooltip: 'Home',
289-
onPressed: () {
290-
Navigator.of(context).pushNamedAndRemoveUntil(
291-
'/home', (Route<dynamic> route) => false);
292-
},
293-
),
294-
IconButton(
295-
alignment: Alignment.center,
296-
icon: Icon(Icons.refresh),
297-
iconSize: 40,
298-
color: Colors.green,
299-
tooltip: 'Restart',
300-
onPressed: () {
301-
Navigator.of(context).pushNamedAndRemoveUntil(
302-
'/loading', (Route<dynamic> route) => false);
303-
},
304-
),
305-
],
306-
)
307-
],
308-
),
309-
),
310-
),
311-
);
312-
},
313-
);
314-
}
315-
316-
Widget _numberBlock(
317-
{Color borderColor, Color bgColor, int index, int value}) {
318-
bool isSelected = false;
319-
return Material(
320-
child: InkWell(
321-
onTap: () {
322-
isSelected = isSelected ? false : true;
323-
blockDataStream.setCount(index: index, value: value);
324-
}, // handle your onTap here
325-
child: Container(
326-
width: 120,
327-
height: 120,
328-
alignment: Alignment(0.0, 0.0),
329-
decoration: BoxDecoration(
330-
color: bgColor,
331-
border: Border.all(color: Colors.white, width: 5),
332-
borderRadius: BorderRadius.circular(10)),
333-
child: Text(
334-
value.toString(),
335-
style: TextStyle(
336-
color: Colors.white, fontSize: 40, fontWeight: FontWeight.bold),
337-
),
338-
),
339-
),
340-
);
341-
}
342208
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:numbers/utils/constants.dart';
3+
4+
Row headerInfo(int secCounter, Map<String, int> gameHistory) {
5+
return Row(
6+
mainAxisAlignment: MainAxisAlignment.center,
7+
children: <Widget>[
8+
Container(
9+
padding: const EdgeInsets.only(left: 15, right: 10),
10+
width: 100,
11+
color: blackLowOpacity,
12+
child: Row(
13+
children: <Widget>[
14+
Text(
15+
'TIMER : ',
16+
style: TextStyle(
17+
color: Colors.white,
18+
),
19+
textAlign: TextAlign.center,
20+
),
21+
Text(
22+
secCounter.toString(),
23+
style: TextStyle(color: Colors.white),
24+
),
25+
],
26+
)),
27+
Container(
28+
margin: const EdgeInsets.only(left: 10),
29+
padding: const EdgeInsets.only(left: 15, right: 10),
30+
width: 100,
31+
color: blackLowOpacity,
32+
child: Row(
33+
children: <Widget>[
34+
Text(
35+
'SCORE : ',
36+
style: TextStyle(
37+
color: Colors.white,
38+
),
39+
textAlign: TextAlign.center,
40+
),
41+
Text(
42+
gameHistory['success'].toString(),
43+
style: TextStyle(color: Colors.white),
44+
),
45+
],
46+
))
47+
],
48+
);
49+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:numbers/provider/BlockDataStream.dart';
3+
4+
Widget numberBlock(
5+
{Color borderColor,
6+
Color bgColor,
7+
int index,
8+
int value,
9+
BlockDataStream blockDataStream}) {
10+
bool isSelected = false;
11+
return Material(
12+
child: InkWell(
13+
onTap: () {
14+
isSelected = isSelected ? false : true;
15+
blockDataStream.setCount(index: index, value: value);
16+
}, // handle your onTap here
17+
child: Container(
18+
width: 120,
19+
height: 120,
20+
alignment: Alignment(0.0, 0.0),
21+
decoration: BoxDecoration(
22+
color: bgColor,
23+
border: Border.all(color: Colors.white, width: 5),
24+
borderRadius: BorderRadius.circular(10)),
25+
child: Text(
26+
value.toString(),
27+
style: TextStyle(
28+
color: Colors.white, fontSize: 40, fontWeight: FontWeight.bold),
29+
),
30+
),
31+
),
32+
);
33+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:flutter/material.dart';
2+
3+
Future<void> showSummary(BuildContext context, Map<String, int> gameHistory, ) async {
4+
return showDialog<void>(
5+
context: context,
6+
barrierDismissible: false, // user must tap button!
7+
builder: (BuildContext context) {
8+
return AlertDialog(
9+
content: SingleChildScrollView(
10+
child: Container(
11+
child: Column(
12+
mainAxisAlignment: MainAxisAlignment.center,
13+
children: <Widget>[
14+
Row(
15+
mainAxisAlignment: MainAxisAlignment.center,
16+
children: <Widget>[
17+
Text(
18+
'Score: ',
19+
style: TextStyle(
20+
fontWeight: FontWeight.bold, fontSize: 30),
21+
),
22+
Text(
23+
gameHistory['success'].toString(),
24+
style: TextStyle(
25+
fontWeight: FontWeight.bold, fontSize: 30),
26+
),
27+
]),
28+
Row(
29+
mainAxisAlignment: MainAxisAlignment.center,
30+
children: <Widget>[
31+
IconButton(
32+
alignment: Alignment.center,
33+
icon: Icon(Icons.home),
34+
iconSize: 40,
35+
color: Colors.blue,
36+
tooltip: 'Home',
37+
onPressed: () {
38+
Navigator.of(context).pushNamedAndRemoveUntil(
39+
'/home', (Route<dynamic> route) => false);
40+
},
41+
),
42+
IconButton(
43+
alignment: Alignment.center,
44+
icon: Icon(Icons.refresh),
45+
iconSize: 40,
46+
color: Colors.green,
47+
tooltip: 'Restart',
48+
onPressed: () {
49+
Navigator.of(context).pushNamedAndRemoveUntil(
50+
'/loading', (Route<dynamic> route) => false);
51+
},
52+
),
53+
],
54+
)
55+
],
56+
),
57+
),
58+
),
59+
);
60+
},
61+
);
62+
}
File renamed without changes.

0 commit comments

Comments
 (0)