-
Notifications
You must be signed in to change notification settings - Fork 7
/
scorecard_fix.dart
105 lines (95 loc) · 2.4 KB
/
scorecard_fix.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
// This demo shows that using AnimatedOpacity instead of animating the Opacity
// widget directly can avoid rebuilding its sub-tree in every frame of the
// animation.
import 'package:flutter/material.dart';
import '../color_list.dart';
class ScorecardFix extends StatefulWidget {
@override
ScorecardFixState createState() {
return new ScorecardFixState();
}
}
class ScorecardFixState extends State<ScorecardFix>
with SingleTickerProviderStateMixin {
var opacityVal = 1.0;
bool scoreVisible = false;
@override
void initState() {
super.initState();
}
void showScore() {
setState(() {
opacityVal = 0.3;
scoreVisible = true;
});
}
void dismissScore() {
if (scoreVisible) {
setState(() {
opacityVal = 1.0;
scoreVisible = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Scorecard Optimized"),
),
body: Stack(
children: <Widget>[
GestureDetector(
onTap: dismissScore,
child: AnimatedOpacity(
duration: Duration(milliseconds: 500),
opacity: opacityVal,
child: Column(
children: <Widget>[
Flexible(
flex: 9,
child: new GridView.count(
primary: false,
padding: const EdgeInsets.all(20.0),
crossAxisSpacing: 10.0,
crossAxisCount: 3,
children: new List<Widget>.generate(15, createItem),
),
),
Flexible(
flex: 1,
child: ElevatedButton(
onPressed: showScore,
child: Text("Show Score"),
),
)
],
),
),
),
buildScoreOverlay(),
],
),
);
}
Widget buildScoreOverlay() {
if (scoreVisible) {
return Center(
child: Text("Your Score is 100!"),
);
} else {
return Placeholder(
color: const Color(0xFFFFFF),
);
}
}
Widget createItem(index) {
final colorList = getColorList();
if (index >= 9) {
index = index - 9;
}
return Container(
color: colorList[index],
);
}
}