-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.dart
751 lines (679 loc) · 24.3 KB
/
main.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart';
import 'package:meta/meta.dart';
import 'dart:async';
import 'package:fluro/fluro.dart';
import 'package:redux/redux.dart';
import 'package:flutter_redux/flutter_redux.dart';
class SetFirstNameAction {
final String firsName;
SetFirstNameAction(this.firsName);
}
class StoreSingleton {
static final StoreSingleton _singleton = new StoreSingleton._internal();
factory StoreSingleton() {
return _singleton;
}
StoreSingleton._internal();
Child _child = new Child();
String firstNameReducer(String state, SetFirstNameAction action) {
_child.firstName = state;
return state;
}
}
class Child {
String firstName;
}
class Routes {
static final Router router = configureRoutes(new Router());
static Router configureRoutes(Router router) {
// Define our home page.
router.define('/', handler: new Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params) {
return new HomePage();
}));
// Define our about page.
router.define('/kids/register/1', handler: new Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params) {
return new MyInheritedWidget(
data: MediaQuery.of(context),
child: new RegisterKidPage1(),
);
}));
// Define our about page.
router.define('/kids/register/2', handler: new Handler(
handlerFunc: (BuildContext context, Map<String, dynamic> params) {
return new MyInheritedWidget(
data: MediaQuery.of(context),
child: new RegisterKidPage2(),
);
}));
return router;
}
}
void main() {
runApp(new MaterialApp(
onGenerateRoute: Routes.router.generator,
));
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Teddycare HomePage"),
backgroundColor: Colors.deepOrange),
body: new Container(
child: new Center(
child: new Column(
children: [
new RaisedButton(
child: new Text('Registration page'),
onPressed: () {
Navigator.of(context).pushNamed("/kids/register/1");
},
),
],
))));
}
}
class MyInheritedWidget extends InheritedWidget {
static MyInheritedWidget of(BuildContext context) =>
context.inheritFromWidgetOfExactType(MyInheritedWidget);
final MediaQueryData _data;
String get deviceWidth => _data.size.width.toString();
Orientation get orientation => _data.orientation;
MyInheritedWidget({
Key key,
MediaQueryData data,
Widget child,
})
: _data = data,
super(key: key, child: child);
@override
bool updateShouldNotify(MyInheritedWidget oldWidget) =>
_data != oldWidget._data;
}
class RegisterKidPage1 extends StatefulWidget {
RegisterKidPage1({Key key}) : super(key: key);
@override
_RegisterKidPage1 createState() => new _RegisterKidPage1();
}
class _RegisterKidPage1 extends State<RegisterKidPage1> {
static final StoreSingleton singletonStore = new StoreSingleton();
final Store store = new Store(singletonStore.firstNameReducer, initialState: "");
var numberOfHorizontalCell = 2;
var ratio = 4.5;
TextEditingController childFirstNameController = new TextEditingController();
FocusNode childFirstNameFocus = new FocusNode();
Widget _buildForm(BuildContext context, Store store) {
return new Form(
child: new Container(
child: new Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new Flexible(
child: new GridView.count(
crossAxisCount: numberOfHorizontalCell,
childAspectRatio: ratio,
padding: const EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
children: [
new StoreConnector<String, String>(
converter: (store) => store.state,
builder: (context, count) => new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Firstname",
),
controller: childFirstNameController,
focusNode: childFirstNameFocus,
initialValue: count,
//onChanged: _setFirstName,
// initialValue: child.firstName,
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Lastname",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Relationship",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Phone",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Address Line 1",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Address Line 2",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "City",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "State",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Zip",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Email Address",
),
),
),
]),
),
new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
new Padding(
padding: const EdgeInsets.all(16.0),
child: new RaisedButton(
onPressed: () {
Routes.router.navigateTo(context, "/kids/register/2",
transition: TransitionType.inFromLeft);
//Navigator.of(context).pushNamed("/kids/register/2");
},
child: new Text('Next'),
),
)
],
)
],
)));
}
@override
Widget build(BuildContext context) {
childFirstNameController.addListener(() {
return () =>
store.dispatch(new SetFirstNameAction(childFirstNameController.text));
});
childFirstNameFocus.addListener(() {
return () =>
store.dispatch(new SetFirstNameAction(childFirstNameController.text));
});
if (MyInheritedWidget.of(context).orientation == Orientation.portrait) {
numberOfHorizontalCell = 1;
} else {
numberOfHorizontalCell = 2;
}
return new StoreProvider (
store: this.store,
child: new Scaffold(
appBar: new AppBar(
title: new Text('Step 1: Family Details'),
),
body: _buildForm(context, store),
resizeToAvoidBottomPadding: true,
)
);
}
}
class RegisterKidPage2 extends StatefulWidget {
RegisterKidPage2({Key key}) : super(key: key);
@override
_RegisterKidPage2 createState() => new _RegisterKidPage2();
}
class _RegisterKidPage2 extends State<RegisterKidPage2> {
var numberOfHorizontalCell = 2;
var ratio = 4.5;
String radioValue = "male";
bool addressSameAsParent = false;
var _datetime = new DateTime.now();
// Age Range dropdown
dynamic ddAgeRange;
// Allergies
bool chkAllergyDairy = false;
bool chkAllergyNuts = false;
bool chkAllergyGluten = false;
// Special instructions
bool chkVegetarian = false;
bool chkBringsOwnFood = false;
void handleRadioValueChanged(String value) {
setState(() {
radioValue = value;
});
}
void handleCheckboxValueChanged(bool value) {
setState(() {
addressSameAsParent = value;
});
}
void chkAllergyDairyChanged(bool value) {
setState(() {
chkAllergyDairy = value;
});
}
void chkAllergyNutsChanged(bool value) {
setState(() {
chkAllergyNuts = value;
});
}
void chkAllergyGlutenChanged(bool value) {
setState(() {
chkAllergyGluten = value;
});
}
void chkVegetarianChanged(bool value) {
setState(() {
chkVegetarian = value;
});
}
void chkBringsOwnFoodChanged(bool value) {
setState(() {
chkBringsOwnFood = value;
});
}
void ddAgeRangeChanged(dynamic value) {
setState(() {
ddAgeRange = value;
});
}
void handleDropDownValueChanged(dynamic value) {
setState(() {});
}
void uploadPictureButton() {}
void _submit() {}
Widget _buildForm() {
return new Form(
child: new Container(
child: new Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new Flexible(
child: new GridView.count(
crossAxisCount: numberOfHorizontalCell,
childAspectRatio: ratio,
padding: const EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
children: [
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Firstname",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Lastname",
),
),
),
new Row(
children: <Widget>[
new Flexible(
child: new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "BirthDate",
),
),
)),
new Flexible(
child: new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Birth month",
),
),
)),
new Flexible(
child: new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Birth Year",
),
),
)),
],
),
new Row(children: [
new Flexible(
child: new DropdownButton(
onChanged: ddAgeRangeChanged,
hint: new Text("zdzd"),
value: ddAgeRange,
items: [
new DropdownMenuItem(
child: new Text("2 years"),
)
]))
]),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Class Name",
),
),
),
new ListTile(
title: new TextFormField(
decoration: new InputDecoration(
hintText: "Teacher Name",
),
),
),
new Row(
children: <Widget>[
new Radio<String>(
value: "Male",
groupValue: radioValue,
onChanged: handleRadioValueChanged),
new Text("Male"),
new Divider(),
new Radio<String>(
value: "Female",
groupValue: radioValue,
onChanged: handleRadioValueChanged),
new Text("Female"),
],
),
new Row(
children: [
new Checkbox(
value: addressSameAsParent,
onChanged: handleCheckboxValueChanged),
new Text("Same address as "),
new Flexible(
child: new DropdownButton(
onChanged: handleDropDownValueChanged,
items: new List.generate(20, (int index) {
return new DropdownMenuItem(
child: new Container(
child: new Text("Item#$index"),
));
}),
),
),
],
),
new Text(
"Allergies",
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 25.5),
),
new Row(
children: [
new Checkbox(
value: chkAllergyDairy,
onChanged: chkAllergyDairyChanged),
new Text("Dairy"),
new Checkbox(
value: chkAllergyNuts,
onChanged: chkAllergyNutsChanged),
new Text("Nuts"),
new Checkbox(
value: chkAllergyGluten,
onChanged: chkAllergyGlutenChanged),
new Text("Gluten"),
],
),
new Container(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)),
child: new TextFormField(
decoration: new InputDecoration(
hintText:
"For EACH allergy, explain what the parent/guardian wants to do (if there is a reaction)",
),
maxLines: 5,
keyboardType: TextInputType.multiline,
),
),
new Text(
"Special Instructions",
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 25.5),
),
new Row(
children: [
new Checkbox(
value: chkVegetarian, onChanged: chkVegetarianChanged),
new Text("Vegetarian"),
new Checkbox(
value: chkBringsOwnFood,
onChanged: chkBringsOwnFoodChanged),
new Text("Brings own food"),
],
),
new Row(
children: [
new Text(
"Picture",
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 25.5),
),
new RaisedButton(
onPressed: uploadPictureButton,
child: new Text("Upload"))
],
),
new Container(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)),
child: new TextFormField(
decoration: new InputDecoration(
hintText: "Notes",
),
maxLines: 6,
keyboardType: TextInputType.multiline,
),
),
new Text(
"Start Date",
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 25.5),
),
new Row(
children: [
new Flexible(
child: new DateTimeItem(
dateTime: _datetime,
onChanged: (dateTime) =>
setState(() => _datetime = dateTime),
),
),
],
),
]),
),
new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
new Padding(
padding: const EdgeInsets.all(16.0),
child: new RaisedButton(
onPressed: _submit,
child: new Text('Done'),
),
)
],
)
],
)));
}
@override
Widget build(BuildContext context) {
if (MyInheritedWidget.of(context).orientation == Orientation.portrait) {
numberOfHorizontalCell = 1;
} else {
numberOfHorizontalCell = 2;
}
return new Scaffold(
appBar: new AppBar(
title: new Text("Step 2: Kid's Details"),
),
body: _buildForm(),
resizeToAvoidBottomPadding: true,
);
}
}
/*
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _ipAddress = 'Unknown';
_getIPAddress() async {
HttpClient client = new HttpClient();
String result;
client.getUrl(Uri.parse("http://35.205.143.130/api/v1/children"))
.then((HttpClientRequest request) {
request.headers.add("Auth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dkXtUWJp8DfULo2R1Ya-fPOB4bjRVGL4XiX3i2Vksq2XK6GEmHIg1vjNTtq401rdAIS7mOXcfYEu9GdPL2OyuV6EdmZvrHMuFGdlziTUiv8Xzviy1bvIxJc2cVkLyUAMOUZuT6kGBxPKtXIG6GJccH6dOL07W9NJBDaC_BS5lklt-H7lWTMsqfPcT3322oIAftGUVfjmuSAzUwPN0CID-xncD8v0eCe_doEdWlQp3LYsAVKhRRoM_4j1TQ");
// Optionally write to the request object...
// Then call close.
return request.close();
}).then((HttpClientResponse response) {
if (response.statusCode == HttpStatus.OK) {
response.transform(UTF8.decoder).listen((contents) {
// handle data
var decoded = JSON.decode(contents);
print(decoded);
var user = new Child.fromJson(decoded);
print(user);
});
}else {
result =
'Error getting children:\nHttp status ${response.statusCode}';
}
});
// If the widget was removed from the tree while the message was in flight,
// we want to discard the reply rather than calling setState to update our
// non-existent appearance.
if (!mounted) return;
setState(() {
_ipAddress = result;
});
}
@override
Widget build(BuildContext context) {
var spacer = new SizedBox(height: 32.0);
return new Container(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('Children:'),
new Text('$_ipAddress.'),
spacer,
new RaisedButton(
onPressed: _getIPAddress,
child: new Text('Get children'),
),
],
),
);
}
}
*/
class DateTimeItem extends StatelessWidget {
DateTimeItem({Key key, DateTime dateTime, @required this.onChanged})
: assert(onChanged != null),
date = dateTime == null
? new DateTime.now()
: new DateTime(dateTime.year, dateTime.month, dateTime.day),
time = dateTime == null
? new DateTime.now()
: new TimeOfDay(hour: dateTime.hour, minute: dateTime.minute),
super(key: key);
final DateTime date;
final TimeOfDay time;
final ValueChanged<DateTime> onChanged;
@override
Widget build(BuildContext context) {
return new Row(
children: <Widget>[
new Expanded(
child: new InkWell(
onTap: (() => _showDatePicker(context)),
child: new ListTile(
title: new Text(new DateFormat('EEEE, MMMM d').format(date)),
leading: new IconButton(
icon: new Icon(Icons.calendar_today),
onPressed: () {},
),
),
),
),
/* new InkWell(
onTap: (() => _showTimePicker(context)),
child: new Padding(
padding: new EdgeInsets.symmetric(vertical: 8.0),
child: new Text('$time')),
),*/
],
);
}
Future _showDatePicker(BuildContext context) async {
DateTime dateTimePicked = await showDatePicker(
context: context,
initialDate: date,
firstDate: date.subtract(const Duration(days: 20000)),
lastDate: new DateTime.now());
if (dateTimePicked != null) {
onChanged(new DateTime(dateTimePicked.year, dateTimePicked.month,
dateTimePicked.day, time.hour, time.minute));
}
}
Future _showTimePicker(BuildContext context) async {
TimeOfDay timeOfDay =
await showTimePicker(context: context, initialTime: time);
if (timeOfDay != null) {
onChanged(new DateTime(
date.year, date.month, date.day, timeOfDay.hour, timeOfDay.minute));
}
}
}