-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
197 lines (151 loc) · 7.14 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
import "dart:html" as dom;
import 'package:logging/logging.dart';
import 'package:console_log_handler/console_log_handler.dart';
import 'package:m4d_core/m4d_ioc.dart' as ioc;
import 'package:m4d_core/services.dart' as coreService;
import 'package:m4d_components/m4d_components.dart';
import 'package:m4d_dialog/m4d_dialog.dart';
import "package:m4d_dialog_sample/customdialog1.dart";
import "package:m4d_dialog_sample/customdialog2.dart";
// For Date- and TimePicker
import 'package:l10n/l10n.dart';
import 'package:intl/intl.dart';
import 'package:intl/intl_browser.dart';
import 'package:m4d_dialog_sample/_l10n/messages_all.dart';
///// Simple Translation-Table for testing (see L10N for more)
//final L10NTranslate translate = new L10NTranslate.withTranslations( {
// "de": {
// "Cancel": "Abbrechen"
// },
//
// "en": {
// "Must not be empty": ""
// }
//});
class Application extends MaterialApplication {
final Logger _logger = new Logger('dialog.Application');
int _mangoCounter = 0;
final MaterialAlertDialog alertDialog = new MaterialAlertDialog();
final MdlConfirmDialog confirmDialog = new MdlConfirmDialog();
final CustomDialog1 customDialog1 = new CustomDialog1();
final CustomDialog2 customDialog2 = new CustomDialog2();
final MaterialTimePicker timePicker = new MaterialTimePicker();
final MaterialDatePicker datePicker = new MaterialDatePicker();
@override
run() => Future(_bindEvents);
//- private --------------------------------------------------------------------------------------------------------
void _bindEvents() {
final btnAlertDialog = MaterialButton.widget(dom.querySelector("#alertdialog"));
final btnConfirmDialog = MaterialButton.widget(dom.querySelector("#confirmdialog"));
final btnCustomDialog1 = MaterialButton.widget(dom.querySelector("#customdialog1"));
final btnCustomDialog2 = MaterialButton.widget(dom.querySelector("#customdialog2"));
final _dateInput = MaterialTextfield.widget(dom.querySelector("#date_input"));
final _timeInput = MaterialTextfield.widget(dom.querySelector("#time_input"));
final _btnShowDatePicker = MaterialButton.widget(dom.querySelector("#date-picker"));
final _btnShowTimePicker = MaterialButton.widget(dom.querySelector("#time-picker"));
final _btnClear = MaterialButton.widget(dom.querySelector("#clear"));
btnAlertDialog.onClick.listen((_) {
_logger.info("Click on AlertButton");
alertDialog(l10n("Testmessage")).show().then((final MdlDialogStatus status) {
_logger.info(status);
});
});
btnConfirmDialog.onClick.listen((_) {
_logger.info("Click on ConfirmButton");
confirmDialog(l10n("Testmessage")).show().then((final MdlDialogStatus status) {
_logger.info(status);
});
});
btnCustomDialog1.onClick.listen((_) {
_logger.info("Click on ConfirmButton");
customDialog1(
title: l10n("Mango #[counter] (Fruit)",{ "counter" : _mangoCounter }),
yesButton: l10n("I buy it!"),
noButton: l10n("Not now"))
.show().then((final MdlDialogStatus status) {
_logger.info(status);
_mangoCounter++;
});
});
btnCustomDialog2.onClick.listen((_) {
_logger.info("Click on ConfirmButton");
customDialog2(
title: l10n("Form-Sample")).show().then((final MdlDialogStatus status) {
_logger.info(status);
if(status == MdlDialogStatus.OK) {
_logger.info("You entered: ${customDialog2.name.value}");
}
});
});
_btnShowDatePicker.onClick.listen((_) {
// Not necessary but makes sense if you reuse the dialog
datePicker.dateTime = new DateTime.now();
datePicker.show().then((final MdlDialogStatus status) {
if(status == MdlDialogStatus.OK) {
final MaterialSnackbar snackbar = new MaterialSnackbar();
final String date = new DateFormat.yMd().format(datePicker.dateTime);
final String time = new DateFormat("HH:mm:ss").format(timePicker.dateTime);
snackbar(date).show();
_logger.info("Seleted date: ${date} / ${time}");
}
});
});
_btnShowTimePicker.onClick.listen((_) {
// Not necessary but makes sense if you reuse the dialog
timePicker.dateTime = (new DateTime.now().add(new Duration(days: 1)));
timePicker.show().then((final MdlDialogStatus status) {
if(status == MdlDialogStatus.OK) {
final MaterialSnackbar snackbar = new MaterialSnackbar();
final String date = new DateFormat("dd.MM.yyyy").format(timePicker.dateTime);
final String time = new DateFormat.Hm().format(timePicker.dateTime);
snackbar(time).show();
_logger.info("Seleted time: ${time} / ${date} (Today + one additional day)");
}
});
});
_dateInput.onClick.listen((_) {
// Not necessary but makes sense if you reuse the dialog
datePicker.dateTime = new DateTime.now();
datePicker.show().then((final MdlDialogStatus status) {
if(status == MdlDialogStatus.OK) {
final String date = new DateFormat("dd.MM.yyyy").format(datePicker.dateTime);
final String time = new DateFormat("HH:mm:ss").format(timePicker.dateTime);
_dateInput.value = date;
_logger.info("Seleted date: ${date} / ${time}");
}
});
});
_timeInput.onClick.listen((_) {
// Not necessary but makes sense if you reuse the dialog
timePicker.dateTime = new DateTime.now();
timePicker.show().then((final MdlDialogStatus status) {
if(status == MdlDialogStatus.OK) {
final String time = new DateFormat("HH:mm").format(timePicker.dateTime);
_timeInput.value = time;
_logger.info("Seleted time: ${time}");
}
});
});
_btnClear.onClick.listen((final dom.Event event) {
event.preventDefault();
_dateInput.value = "";
_timeInput.value = "";
});
}
}
main() async {
configLogging(show: Level.INFO);
// initLanguageSettings checks the browser url if it finds
// a "lang" query param and sets the locale accordingly
final String locale = await initLanguageSettings(
() => findSystemLocale(),
(final String locale) => initializeMessages(locale)
);
(dom.querySelector("head") as dom.HeadElement).lang = locale;
// Initialize M4D
ioc.Container.bindModules([
DialogModule()
]).bind(coreService.Application).to(Application());
final Application app = await componentHandler().upgrade();
app.run();
}