1+ import 'dart:async' ;
2+
13import 'package:flutter/material.dart' ;
24
3- Container buildNumberBlocks () {
5+ Container buildNumberBlocks (NumberCreater numberCreater ) {
46 return Container (
57 // alignment: Alignment.centerLeft,
68 alignment: Alignment (0.0 , 0.0 ),
@@ -10,30 +12,56 @@ Container buildNumberBlocks() {
1012 spacing: 40 ,
1113 runSpacing: 40 ,
1214 children: < Widget > [
13- numberBlock (Colors .white, Colors .yellow, 4 ),
14- numberBlock (Colors .white, Colors .red, 9 ),
15- numberBlock (Colors .white, Colors .blue, 1 ),
16- numberBlock (Colors .white, Colors .yellow, 1 ),
17- numberBlock (Colors .white, Colors .red, 1 ),
18- numberBlock (Colors .white, Colors .blue, 1 ),
15+ numberBlock (numberCreater, Colors .white, Colors .yellow, 1 ),
16+ numberBlock (numberCreater, Colors .white, Colors .red, 3 ),
17+ numberBlock (numberCreater, Colors .white, Colors .blue, 4 ),
18+ numberBlock (numberCreater, Colors .white, Colors .yellow, 2 ),
19+ numberBlock (numberCreater, Colors .white, Colors .red, 10 ),
20+ numberBlock (numberCreater, Colors .white, Colors .blue, 9 ),
1921 ],
2022 ),
2123 );
2224}
2325
24- Container numberBlock (Color borderColor, Color bgColor, int value) {
25- return Container (
26- width: 120 ,
27- height: 120 ,
28- alignment: Alignment (0.0 , 0.0 ),
29- decoration: BoxDecoration (
30- color: bgColor,
31- border: Border .all (color: borderColor, width: 5 ),
32- borderRadius: new BorderRadius .circular (10 )),
33- child: Text (
34- value.toString (),
35- style: TextStyle (
36- color: Colors .white, fontSize: 40 , fontWeight: FontWeight .bold),
26+ Widget numberBlock (NumberCreater numberCreater, Color borderColor, Color bgColor, int value) {
27+ bool isSelected = false ;
28+ return Material (
29+ child: InkWell (
30+ onTap: () {
31+ isSelected = isSelected ? false : true ;
32+ print (isSelected);
33+ bgColor = Colors .red;
34+ print (bgColor);
35+ numberCreater.setCount (value);
36+ }, // handle your onTap here
37+ child: Container (
38+ width: 120 ,
39+ height: 120 ,
40+ alignment: Alignment (0.0 , 0.0 ),
41+ decoration: BoxDecoration (
42+ color: bgColor,
43+ border: Border .all (color: borderColor, width: 5 ),
44+ borderRadius: BorderRadius .circular (10 )),
45+ child: Text (
46+ value.toString (),
47+ style: TextStyle (
48+ color: Colors .white, fontSize: 40 , fontWeight: FontWeight .bold),
49+ ),
50+ // child: ,
51+ ),
3752 ),
3853 );
3954}
55+
56+ class NumberCreater {
57+ var _count = 1 ;
58+
59+ void setCount (int count){
60+ this ._count = count;
61+ _controller.sink.add (count);
62+ }
63+
64+ final _controller = StreamController <int >();
65+
66+ Stream <int > get stream => _controller.stream;
67+ }
0 commit comments