/
calculator.rfwtxt
149 lines (143 loc) · 3.99 KB
/
calculator.rfwtxt
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
import core.widgets;
widget root = Calculator();
widget Calculator = SafeArea(
child: Center(
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: "stretch",
children: [
Display(text: data.value.string),
Expanded(
child: FittedBox(
alignment: { x: 0.0, y: 1.0 },
child: CalculatorPad(),
),
),
],
),
),
),
);
widget CalculatorPad = Column(
children: [
Row(
children: [
// The "#docregion" pragma here allows us to inline this as an example
// in the "rfw" package's README.md file. It is unrelated to what this
// example is otherwise trying to show and can be disregarded.
// #docregion button7
CalculatorButton(label: "7", onPressed: event "digit" { arguments: [7] }),
// #enddocregion button7
CalculatorButton(label: "8", onPressed: event "digit" { arguments: [8] }),
CalculatorButton(label: "9", onPressed: event "digit" { arguments: [9] }),
SizedBox(width: 116.0, height: 116.0),
],
),
Row(
children: [
CalculatorButton(label: "4", onPressed: event "digit" { arguments: [4] }),
CalculatorButton(label: "5", onPressed: event "digit" { arguments: [5] }),
CalculatorButton(label: "6", onPressed: event "digit" { arguments: [6] }),
CalculatorButton(label: "+", onPressed: event "add" { }),
],
),
Row(
children: [
CalculatorButton(label: "1", onPressed: event "digit" { arguments: [1] }),
CalculatorButton(label: "2", onPressed: event "digit" { arguments: [2] }),
CalculatorButton(label: "3", onPressed: event "digit" { arguments: [3] }),
CalculatorButton(label: "=", onPressed: event "equals" { }),
],
),
Row(
children: [
SizedBox(width: 116.0, height: 116.0),
CalculatorButton(label: "0", onPressed: event "digit" { arguments: [0] }),
SizedBox(width: 116.0, height: 116.0),
SizedBox(width: 116.0, height: 116.0),
],
),
],
);
// #docregion CalculatorButton
widget CalculatorButton = Padding(
padding: [8.0],
child: SizedBox(
width: 100.0,
height: 100.0,
child: Button(
child: FittedBox(child: Text(text: args.label)),
onPressed: args.onPressed,
),
),
);
// #enddocregion CalculatorButton
// #docregion Button
widget Button { down: false } = GestureDetector(
onTap: args.onPressed,
onTapDown: set state.down = true,
onTapUp: set state.down = false,
onTapCancel: set state.down = false,
child: Container(
duration: 50,
margin: switch state.down {
false: [ 0.0, 0.0, 2.0, 2.0 ],
true: [ 2.0, 2.0, 0.0, 0.0 ],
},
padding: [ 12.0, 8.0 ],
decoration: {
type: "shape",
shape: {
type: "stadium",
side: { width: 1.0 },
},
gradient: {
type: "linear",
begin: { x: -0.5, y: -0.25 },
end: { x: 0.0, y: 0.5 },
colors: [ 0xFFFFFF99, 0xFFEEDD00 ],
stops: [ 0.0, 1.0 ],
tileMode: "mirror",
},
shadows: switch state.down {
false: [ { blurRadius: 4.0, spreadRadius: 0.5, offset: { x: 1.0, y: 1.0, } } ],
default: [],
},
},
child: DefaultTextStyle(
style: {
color: 0xFF000000,
fontSize: 32.0,
},
child: args.child,
),
),
);
// #enddocregion Button
widget Display = Container(
height: 80.0,
margin: [18.0],
padding: [20.0, 12.0],
decoration: {
type: 'shape',
gradient: {
type: "linear",
begin: { x: 0.0, y: -0.5 },
end: { x: 0.05, y: 1.0 },
colors: [ 0xFFFFFFFF, 0xFFDDDDDD ],
stops: [ 0.0, 1.0 ],
tileMode: "mirror",
},
shape: {
type: "stadium",
borderRadius: [ { x: 40.0 } ],
side: { color: 0xFFCCCCCC, },
}
},
child: SizedBoxExpand(
child: FittedBox(
alignment: { x: 1.0, y: 0.0, },
child: Text(text: args.text, style: { color: 0xFF000000 }),
),
),
);