@@ -2,6 +2,7 @@ import 'dart:async';
2
2
import 'package:flutter/material.dart' ;
3
3
import 'package:flutter/services.dart' ;
4
4
import 'package:intl/intl.dart' ;
5
+ import 'colors.dart' ;
5
6
6
7
class HomeScreen extends StatefulWidget {
7
8
@override
@@ -15,8 +16,7 @@ class _HomeScreenState extends State<HomeScreen> {
15
16
StreamSubscription tipSubscription;
16
17
17
18
NumberFormat formatter = NumberFormat ("##0.00" );
18
- TextEditingController billTotalController =
19
- TextEditingController (text: "0.00" );
19
+ TextEditingController billTotalController = TextEditingController ();
20
20
int tipPercent = 10 , tipSplit = 1 ;
21
21
double billTotal = 0.0 ;
22
22
double totalWithTip = 0.0 ;
@@ -42,118 +42,192 @@ class _HomeScreenState extends State<HomeScreen> {
42
42
Widget build (BuildContext context) {
43
43
return Scaffold (
44
44
appBar: AppBar (
45
- title: Text ("Tip Calculator" ),
45
+ brightness: Brightness .light,
46
+ elevation: 0.0 ,
47
+ title: Text (
48
+ "Tip Calculator" ,
49
+ style: Theme .of (context).textTheme.headline,
50
+ ),
46
51
),
47
- body: Container (
48
- margin: EdgeInsets .all (30.0 ),
49
- padding: EdgeInsets .all (20.0 ),
50
- child: Column (
51
- crossAxisAlignment: CrossAxisAlignment .stretch,
52
- mainAxisAlignment: MainAxisAlignment .start,
53
- children: < Widget > [
54
- TextField (
55
- controller: billTotalController,
56
- keyboardType: TextInputType .numberWithOptions (decimal: true ),
57
- decoration: InputDecoration (
58
- labelText: "Bill Total" ,
59
- suffixIcon: IconButton (
60
- onPressed: () {
61
- FocusScope .of (context).requestFocus (new FocusNode ());
62
- calculateBill (double .tryParse (billTotalController.text));
63
- },
64
- icon: Icon (
65
- Icons .thumb_up,
66
- color: Theme .of (context).textTheme.body1.color,
52
+ body: SingleChildScrollView (
53
+ child: Container (
54
+ margin: EdgeInsets .all (20.0 ),
55
+ padding: EdgeInsets .fromLTRB (10.0 , 5.0 , 10.0 , 5.0 ),
56
+ child: Column (
57
+ crossAxisAlignment: CrossAxisAlignment .stretch,
58
+ mainAxisAlignment: MainAxisAlignment .start,
59
+ children: < Widget > [
60
+ TextField (
61
+ controller: billTotalController,
62
+ keyboardType: TextInputType .numberWithOptions (decimal: true ),
63
+ decoration: InputDecoration (
64
+ labelText: "Bill Total" ,
65
+ suffixIcon: IconButton (
66
+ onPressed: () {
67
+ FocusScope .of (context).requestFocus (new FocusNode ());
68
+ calculateBill (double .tryParse (billTotalController.text));
69
+ },
70
+ icon: Icon (
71
+ Icons .keyboard_return,
72
+ color: Theme .of (context).textTheme.body1.color,
73
+ ),
74
+ )),
75
+ ),
76
+
77
+ Padding (
78
+ padding: EdgeInsets .fromLTRB (5.0 , 10.0 , 5.0 , 10.0 ),
79
+ child: Text (
80
+ "Enter the total amount of your bill above and press the 'Return' icon." ,
81
+ style: Theme .of (context).textTheme.body1,
82
+ ),
83
+ ),
84
+
85
+ Padding (
86
+ padding: EdgeInsets .fromLTRB (5.0 , 10.0 , 5.0 , 10.0 ),
87
+ child: Text (
88
+ "Alter Tip and Split Between to update the bill breakdown." ,
89
+ style: Theme .of (context).textTheme.body1,
90
+ ),
91
+ ),
92
+
93
+ Row (
94
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
95
+ children: < Widget > [
96
+ Container (
97
+ width: 110.0 ,
98
+ child: Text (
99
+ "Tip" ,
100
+ textAlign: TextAlign .left,
101
+ style: Theme .of (context).primaryTextTheme.subhead,
102
+ ),
67
103
),
68
- )),
69
- ),
70
- Row (
71
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
72
- children: < Widget > [
73
- Text (
74
- "Tip Percentage" ,
75
- style: Theme .of (context).primaryTextTheme.title,
76
- ),
77
- IconButton (
78
- onPressed: () {
79
- if (tipPercent > 0 ) {
80
- tipPercent-- ;
81
- calculateBill (null );
82
- }
83
- },
84
- icon: Icon (Icons .remove_circle_outline),
85
- ),
86
- Text (
87
- "$tipPercent %" ,
88
- style: Theme .of (context).textTheme.title,
89
- textAlign: TextAlign .center,
90
- ),
91
- IconButton (
92
- onPressed: () {
93
- if (tipPercent < 50 ) {
94
- tipPercent++ ;
95
- calculateBill (null );
96
- }
97
- },
98
- icon: Icon (Icons .add_circle_outline),
99
- ),
100
- ]),
101
- Row (
102
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
103
- children: < Widget > [
104
- Text (
105
- "Split Between" ,
106
- style: Theme .of (context).primaryTextTheme.title,
107
- ),
108
- IconButton (
109
- onPressed: () {
110
- if (tipSplit > 1 ) {
111
- tipSplit-- ;
112
- calculateBill (null );
113
- }
114
- },
115
- icon: Icon (Icons .remove_circle_outline),
116
- ),
117
- Text (
118
- "$tipSplit " ,
119
- style: Theme .of (context).textTheme.title,
120
- textAlign: TextAlign .center,
121
- ),
122
- IconButton (
123
- onPressed: () {
124
- if (tipSplit < 50 ) {
125
- tipSplit++ ;
126
- calculateBill (null );
127
- }
128
- },
129
- icon: Icon (Icons .add_circle_outline),
130
- ),
131
- ]),
132
- Row (
133
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
134
- children: < Widget > [
135
- Text (
136
- "Total with tip" ,
137
- style: Theme .of (context).primaryTextTheme.title,
138
- ),
139
- Text (
140
- "${formatter .format (totalWithTip )}" ,
141
- style: Theme .of (context).textTheme.title,
142
- ),
143
- ]),
144
- Row (
145
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
146
- children: < Widget > [
147
- Text (
148
- "Total cost each" ,
149
- style: Theme .of (context).primaryTextTheme.title,
150
- ),
151
- Text (
152
- "${formatter .format (totalEach )}" ,
153
- style: Theme .of (context).textTheme.title,
104
+
105
+ IconButton (
106
+ onPressed: () {
107
+ if (tipPercent > 0 ) {
108
+ tipPercent-- ;
109
+ calculateBill (null );
110
+ }
111
+ },
112
+ icon: Icon (Icons .remove),
113
+ ),
114
+
115
+ Container (
116
+ width: 40.0 ,
117
+ child: Text (
118
+ "$tipPercent %" ,
119
+ style: Theme .of (context).textTheme.subhead,
120
+ textAlign: TextAlign .center,
121
+ ),
122
+ ),
123
+
124
+ IconButton (
125
+ onPressed: () {
126
+ if (tipPercent < 50 ) {
127
+ tipPercent++ ;
128
+ calculateBill (null );
129
+ }
130
+ },
131
+ icon: Icon (Icons .add),
132
+ ),
133
+
134
+
135
+ ]),
136
+ Row (
137
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
138
+ children: < Widget > [
139
+ Container (
140
+ width: 110.0 ,
141
+ child: Text (
142
+ "Split Between" ,
143
+ textAlign: TextAlign .left,
144
+ style: Theme .of (context).primaryTextTheme.subhead,
145
+ ),
146
+ ),
147
+ IconButton (
148
+ onPressed: () {
149
+ if (tipSplit > 1 ) {
150
+ tipSplit-- ;
151
+ calculateBill (null );
152
+ }
153
+ },
154
+ icon: Icon (Icons .remove),
155
+ ),
156
+ Container (
157
+ width: 40.0 ,
158
+ child: Text (
159
+ "$tipSplit " ,
160
+ style: Theme .of (context).textTheme.subhead,
161
+ textAlign: TextAlign .center,
162
+ ),
163
+ ),
164
+ IconButton (
165
+ onPressed: () {
166
+ if (tipSplit < 50 ) {
167
+ tipSplit++ ;
168
+ calculateBill (null );
169
+ }
170
+ },
171
+ icon: Icon (Icons .add),
172
+ ),
173
+
174
+ ]),
175
+
176
+ Container (
177
+ decoration: BoxDecoration (
178
+ border: Border .all (
179
+ color: appPrimaryTextColor,
180
+ width: 2.0
154
181
),
155
- ]),
156
- ],
182
+ borderRadius: BorderRadius .all ( Radius .circular (5.0 ))
183
+ ),
184
+ padding: EdgeInsets .all (8.0 ),
185
+ child: Column (
186
+ children: < Widget > [
187
+ Row (
188
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
189
+ children: < Widget > [
190
+ Text (
191
+ "Bill total" ,
192
+ style: Theme .of (context).primaryTextTheme.subhead,
193
+ ),
194
+ Text (
195
+ "${formatter .format (billTotal )}" ,
196
+ style: Theme .of (context).textTheme.subhead,
197
+ ),
198
+ ],
199
+ ),
200
+ Row (
201
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
202
+ children: < Widget > [
203
+ Text (
204
+ "With tip" ,
205
+ style: Theme .of (context).primaryTextTheme.subhead,
206
+ ),
207
+ Text (
208
+ "${formatter .format (totalWithTip )}" ,
209
+ style: Theme .of (context).textTheme.subhead,
210
+ ),
211
+ ],
212
+ ),
213
+ Row (
214
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
215
+ children: < Widget > [
216
+ Text (
217
+ "Cost each" ,
218
+ style: Theme .of (context).primaryTextTheme.subhead,
219
+ ),
220
+ Text (
221
+ "${formatter .format (totalEach )}" ,
222
+ style: Theme .of (context).textTheme.subhead,
223
+ ),
224
+ ]
225
+ ),
226
+ ],
227
+ ),
228
+ ),
229
+ ],
230
+ ),
157
231
),
158
232
),
159
233
);
@@ -188,13 +262,14 @@ class _HomeScreenState extends State<HomeScreen> {
188
262
});
189
263
}
190
264
191
- /// Get the set device locale so we can correctly format the currency
265
+ /// Get the device locale so we can correctly format the currency
192
266
setupDeviceLocale () async {
193
267
List locales = await platform.invokeMethod ("preferredLanguages" );
194
268
debugPrint ("$locales " );
195
269
if (locales.length> 0 ){
196
270
formatter = NumberFormat .simpleCurrency (locale: locales[0 ]);
197
- setState (() {});
198
271
}
272
+ billTotalController.text = formatter.format (0.0 );
273
+ setState ((){});
199
274
}
200
275
}
0 commit comments