Skip to content

Commit d2c7d94

Browse files
thamaraiselvamthamaraiselvam
authored andcommitted
removed unwanted files and dynamic blocks added
1 parent 6afe030 commit d2c7d94

File tree

6 files changed

+129
-82
lines changed

6 files changed

+129
-82
lines changed

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Flutter",
9+
"request": "launch",
10+
"type": "dart"
11+
}
12+
]
13+
}

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MyApp extends StatelessWidget
1010
@override
1111
Widget build(BuildContext context) {
1212
return new MaterialApp(
13-
home: new GameScreen(),
13+
home: new LoadingScreen(),
1414
);
1515
}
1616
}

lib/provider/BlockDataStream.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'dart:async';
2+
class NumberCreater {
3+
var _count = 1;
4+
5+
void setCount(int count){
6+
this._count = count;
7+
_controller.sink.add(count);
8+
}
9+
10+
final _controller = StreamController<int>();
11+
12+
Stream<int> get stream => _controller.stream;
13+
}

lib/screens/GameScreen.dart

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import 'dart:async';
21
import 'package:add_numbers/widgets/bgGradient.dart';
3-
import 'package:add_numbers/widgets/numberBlockBuilder.dart';
2+
import 'package:add_numbers/provider/BlockDataStream.dart';
43
import 'package:add_numbers/widgets/targetBlockBuilder.dart';
54
import 'package:flutter/material.dart';
65

@@ -12,11 +11,17 @@ class GameScreen extends StatefulWidget {
1211
class _GameScreenState extends State<GameScreen> {
1312
NumberCreater numberCreater = NumberCreater();
1413

14+
List blocks = getBlocks();
15+
1516
@override
1617
void initState() {
1718
super.initState();
1819
numberCreater.stream.listen((data) {
19-
print(data);
20+
setState(() {
21+
if (this.blocks[data].color != Colors.green) {
22+
this.blocks[data].color = Colors.green;
23+
}
24+
});
2025
});
2126
}
2227

@@ -36,11 +41,82 @@ class _GameScreenState extends State<GameScreen> {
3641
SizedBox(
3742
height: 6,
3843
),
39-
buildNumberBlocks(numberCreater)
44+
buildNumberBlocks()
4045
],
4146
),
4247
),
4348
),
4449
));
4550
}
51+
52+
Container buildNumberBlocks() {
53+
return Container(
54+
// alignment: Alignment.centerLeft,
55+
alignment: Alignment(0.0, 0.0),
56+
// color: Colors.grey,
57+
padding: const EdgeInsets.all(30),
58+
child: Wrap(
59+
spacing: 40,
60+
runSpacing: 40,
61+
children: <Widget>[
62+
_numberBlock(
63+
bgColor: this.blocks[0].color, value: this.blocks[0].value),
64+
_numberBlock(
65+
bgColor: this.blocks[1].color, value: this.blocks[1].value),
66+
_numberBlock(
67+
bgColor: this.blocks[2].color, value: this.blocks[2].value),
68+
_numberBlock(
69+
bgColor: this.blocks[3].color, value: this.blocks[3].value),
70+
_numberBlock(
71+
bgColor: this.blocks[4].color, value: this.blocks[4].value),
72+
_numberBlock(
73+
bgColor: this.blocks[5].color, value: this.blocks[5].value),
74+
],
75+
),
76+
);
77+
}
78+
79+
Widget _numberBlock({Color borderColor, Color bgColor, int value}) {
80+
bool isSelected = false;
81+
return Material(
82+
child: InkWell(
83+
onTap: () {
84+
isSelected = isSelected ? false : true;
85+
numberCreater.setCount(value);
86+
}, // handle your onTap here
87+
child: Container(
88+
width: 120,
89+
height: 120,
90+
alignment: Alignment(0.0, 0.0),
91+
decoration: BoxDecoration(
92+
color: bgColor,
93+
border: Border.all(color: Colors.white, width: 5),
94+
borderRadius: BorderRadius.circular(10)),
95+
child: Text(
96+
value.toString(),
97+
style: TextStyle(
98+
color: Colors.white, fontSize: 40, fontWeight: FontWeight.bold),
99+
),
100+
),
101+
),
102+
);
103+
}
104+
}
105+
106+
class Block {
107+
Color color;
108+
int value;
109+
int index;
110+
Block(this.color, this.value);
111+
}
112+
113+
List<Block> getBlocks() {
114+
return [
115+
new Block(Colors.yellow, 0),
116+
new Block(Colors.red, 1),
117+
new Block(Colors.blue, 2),
118+
new Block(Colors.yellow, 3),
119+
new Block(Colors.red, 4),
120+
new Block(Colors.blue, 5)
121+
];
46122
}

lib/screens/LoadingScreen.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ class _LoadingScreenState extends State<LoadingScreen>
2727
_timer = Timer.periodic(
2828
oneSec,
2929
(Timer timer) => setState(() {
30-
if (_startCounter < 1) {
30+
if (_startCounter < 2) {
3131
timer.cancel();
32+
Navigator.push(
33+
context,
34+
MyCustomRoute(builder: (context) => GameScreen()),
35+
);
3236
return;
3337
}
3438

@@ -64,15 +68,6 @@ class _LoadingScreenState extends State<LoadingScreen>
6468
style: TextStyle(
6569
color: Colors.grey, fontWeight: FontWeight.w600),
6670
),
67-
RaisedButton(
68-
child: Text('Start'),
69-
onPressed: () {
70-
Navigator.push(
71-
context,
72-
MaterialPageRoute(builder: (context) => GameScreen()),
73-
);
74-
},
75-
)
7671
],
7772
),
7873
),
@@ -81,3 +76,20 @@ class _LoadingScreenState extends State<LoadingScreen>
8176
);
8277
}
8378
}
79+
80+
class MyCustomRoute<T> extends MaterialPageRoute<T> {
81+
MyCustomRoute({ WidgetBuilder builder, RouteSettings settings })
82+
: super(builder: builder, settings: settings);
83+
84+
@override
85+
Widget buildTransitions(BuildContext context,
86+
Animation<double> animation,
87+
Animation<double> secondaryAnimation,
88+
Widget child) {
89+
if (settings.isInitialRoute)
90+
return child;
91+
// Fades between routes. (If you don't want any animation,
92+
// just return child.)
93+
return new FadeTransition(opacity: animation, child: child);
94+
}
95+
}

lib/widgets/numberBlockBuilder.dart

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)