Procházet zdrojové kódy

carlos sprint 2 parcial

Oniel Mendez před 3 roky
rodič
revize
2ffc69efb3

+ 17
- 0
fast_med_flutter/lib/classes/language.dart Zobrazit soubor

@@ -0,0 +1,17 @@
1
+class Language {
2
+  final int id;
3
+  final String flag;
4
+  final String name;
5
+  final String languageCode;
6
+
7
+  Language(this.id, this.flag, this.name, this.languageCode);
8
+
9
+  static List<Language> languageList() {
10
+    return <Language>[
11
+      Language(1, "🇦🇫", "فارسی", "fa"),
12
+      Language(2, "🇺🇸", "English", "en"),
13
+      Language(3, "🇺🇸", "Español", "es"),
14
+      Language(4, "🇮🇳", "हिंदी", "hi"),
15
+    ];
16
+  }
17
+}

+ 15
- 0
fast_med_flutter/lib/languages/en.json Zobrazit soubor

@@ -0,0 +1,15 @@
1
+{
2
+  "home_page": "Home Page",
3
+  "personal_information": "Personal Information",
4
+  "name": "Name",
5
+  "name_hint": "Enter your name",
6
+  "email": "Email",
7
+  "email_hint": "Enter your email",
8
+  "date_of_birth": "Date of Birth",
9
+  "required_field": "Required Field",
10
+  "submit_info": "Submit Info",
11
+  "about_us": "About Us",
12
+  "settings": "Settings",
13
+  "change_language": "Change Language",
14
+  "about": "This user story translate for our FastMed app in CCOM4030."
15
+}

+ 15
- 0
fast_med_flutter/lib/languages/es.json Zobrazit soubor

@@ -0,0 +1,15 @@
1
+{
2
+  "home_page": "Pagina Inicio",
3
+  "personal_information": "Informacion Personal",
4
+  "name": "Nombre",
5
+  "name_hint": "Entra tu nombre",
6
+  "email": "Correo electronico",
7
+  "email_hint": "Entra tu correo electronico",
8
+  "date_of_birth": "Fecha de nacimiento",
9
+  "required_field": "Campo requerido",
10
+  "submit_info": "Somete informacion",
11
+  "about_us": "Acerca de nosotros",
12
+  "settings": "Configuracion",
13
+  "change_language": "Cambia el lenguaje",
14
+  "about": "Este user story traduce para nuestro FastMed app en CCOM4030."
15
+}

+ 42
- 0
fast_med_flutter/lib/localization/language_constants.dart Zobrazit soubor

@@ -0,0 +1,42 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:userstory2translate/localization/localization.dart';
3
+import 'package:shared_preferences/shared_preferences.dart';
4
+
5
+const String LAGUAGE_CODE = 'languageCode';
6
+
7
+//languages code
8
+const String ENGLISH = 'en';
9
+const String FARSI = 'fa';
10
+const String SPANISH = 'es';
11
+const String HINDI = 'hi';
12
+
13
+Future<Locale> setLocale(String languageCode) async {
14
+  SharedPreferences _prefs = await SharedPreferences.getInstance();
15
+  await _prefs.setString(LAGUAGE_CODE, languageCode);
16
+  return _locale(languageCode);
17
+}
18
+
19
+Future<Locale> getLocale() async {
20
+  SharedPreferences _prefs = await SharedPreferences.getInstance();
21
+  String languageCode = _prefs.getString(LAGUAGE_CODE) ?? "en";
22
+  return _locale(languageCode);
23
+}
24
+
25
+Locale _locale(String languageCode) {
26
+  switch (languageCode) {
27
+    case ENGLISH:
28
+      return Locale(ENGLISH, 'US');
29
+    case FARSI:
30
+      return Locale(FARSI, "IR");
31
+    case SPANISH:
32
+      return Locale(SPANISH, "SP");
33
+    case HINDI:
34
+      return Locale(HINDI, "IN");
35
+    default:
36
+      return Locale(ENGLISH, 'US');
37
+  }
38
+}
39
+
40
+String getTranslated(BuildContext context, String key) {
41
+  return DemoLocalization.of(context).translate(key);
42
+}

+ 51
- 0
fast_med_flutter/lib/localization/localization.dart Zobrazit soubor

@@ -0,0 +1,51 @@
1
+import 'dart:convert';
2
+
3
+import 'package:flutter/material.dart';
4
+import 'package:flutter/services.dart';
5
+
6
+class DemoLocalization {
7
+  DemoLocalization(this.locale);
8
+
9
+  final Locale locale;
10
+  static DemoLocalization of(BuildContext context) {
11
+    return Localizations.of<DemoLocalization>(context, DemoLocalization);
12
+  }
13
+
14
+  Map<String, String> _localizedValues;
15
+
16
+  Future<void> load() async {
17
+    String jsonStringValues =
18
+    await rootBundle.loadString('lib/languages/${locale.languageCode}.json');
19
+    Map<String, dynamic> mappedJson = json.decode(jsonStringValues);
20
+    _localizedValues =
21
+        mappedJson.map((key, value) => MapEntry(key, value.toString()));
22
+  }
23
+
24
+  String translate(String key) {
25
+    return _localizedValues[key];
26
+  }
27
+
28
+  // static member to have simple access to the delegate from Material App
29
+  static const LocalizationsDelegate<DemoLocalization> delegate =
30
+  _DemoLocalizationsDelegate();
31
+}
32
+
33
+class _DemoLocalizationsDelegate
34
+    extends LocalizationsDelegate<DemoLocalization> {
35
+  const _DemoLocalizationsDelegate();
36
+
37
+  @override
38
+  bool isSupported(Locale locale) {
39
+    return ['en', 'es', 'fa', 'hi'].contains(locale.languageCode);
40
+  }
41
+
42
+  @override
43
+  Future<DemoLocalization> load(Locale locale) async {
44
+    DemoLocalization localization = new DemoLocalization(locale);
45
+    await localization.load();
46
+    return localization;
47
+  }
48
+
49
+  @override
50
+  bool shouldReload(LocalizationsDelegate<DemoLocalization> old) => false;
51
+}

+ 26
- 0
fast_med_flutter/lib/pages/about_page.dart Zobrazit soubor

@@ -0,0 +1,26 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:userstory2translate/localization/language_constants.dart';
3
+
4
+class AboutPage extends StatefulWidget {
5
+  AboutPage({Key key}) : super(key: key);
6
+
7
+  @override
8
+  _AboutPageState createState() => _AboutPageState();
9
+}
10
+
11
+class _AboutPageState extends State<AboutPage> {
12
+  @override
13
+  Widget build(BuildContext context) {
14
+    return Scaffold(
15
+      appBar: AppBar(
16
+        title: Text(getTranslated(context, 'about_us')),
17
+      ),
18
+      body: Container(
19
+        padding: EdgeInsets.all(20),
20
+        child: Center(
21
+          child: Text(getTranslated(context, 'about')),
22
+        ),
23
+      ),
24
+    );
25
+  }
26
+}

+ 217
- 0
fast_med_flutter/lib/pages/home_page.dart Zobrazit soubor

@@ -0,0 +1,217 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:userstory2translate/classes/language.dart';
3
+import 'package:userstory2translate/localization/language_constants.dart';
4
+import 'package:userstory2translate/main.dart';
5
+import 'package:userstory2translate/router/route_constants.dart';
6
+
7
+class HomePage extends StatefulWidget {
8
+  HomePage({Key key}) : super(key: key);
9
+
10
+  @override
11
+  _HomePageState createState() => _HomePageState();
12
+}
13
+
14
+class _HomePageState extends State<HomePage> {
15
+  final GlobalKey<FormState> _key = GlobalKey<FormState>();
16
+  void _changeLanguage(Language language) async {
17
+    Locale _locale = await setLocale(language.languageCode);
18
+    MyApp.setLocale(context, _locale);
19
+  }
20
+
21
+  void _showSuccessDialog() {
22
+    showTimePicker(context: context, initialTime: TimeOfDay.now());
23
+  }
24
+
25
+  @override
26
+  Widget build(BuildContext context) {
27
+    return Scaffold(
28
+      appBar: AppBar(
29
+        title: Text(getTranslated(context, 'home_page')),
30
+        actions: <Widget>[
31
+          Padding(
32
+            padding: const EdgeInsets.all(8.0),
33
+            child: DropdownButton<Language>(
34
+              underline: SizedBox(),
35
+              icon: Icon(
36
+                Icons.language,
37
+                color: Colors.white,
38
+              ),
39
+              onChanged: (Language language) {
40
+                _changeLanguage(language);
41
+              },
42
+              items: Language.languageList()
43
+                  .map<DropdownMenuItem<Language>>(
44
+                    (e) => DropdownMenuItem<Language>(
45
+                  value: e,
46
+                  child: Row(
47
+                    mainAxisAlignment: MainAxisAlignment.spaceAround,
48
+                    children: <Widget>[
49
+                      Text(
50
+                        e.flag,
51
+                        style: TextStyle(fontSize: 30),
52
+                      ),
53
+                      Text(e.name)
54
+                    ],
55
+                  ),
56
+                ),
57
+              )
58
+                  .toList(),
59
+            ),
60
+          ),
61
+        ],
62
+      ),
63
+      drawer: Drawer(
64
+        child: _drawerList(),
65
+      ),
66
+      body: Container(
67
+        padding: EdgeInsets.all(20),
68
+        child: _mainForm(context),
69
+      ),
70
+    );
71
+  }
72
+
73
+  Form _mainForm(BuildContext context) {
74
+    return Form(
75
+      key: _key,
76
+      child: Column(
77
+        children: <Widget>[
78
+          Container(
79
+            height: MediaQuery.of(context).size.height / 4,
80
+            child: Center(
81
+              child: Text(
82
+                getTranslated(context, 'personal_information'),
83
+                // DemoLocalization.of(context).translate('personal_information'),
84
+                textAlign: TextAlign.center,
85
+                style: TextStyle(
86
+                  fontSize: 30,
87
+                  fontWeight: FontWeight.bold,
88
+                ),
89
+              ),
90
+            ),
91
+          ),
92
+          TextFormField(
93
+            validator: (val) {
94
+              if (val.isEmpty) {
95
+                return getTranslated(context, 'required_field');
96
+                // return DemoLocalization.of(context).translate('required_fiedl');
97
+              }
98
+              return null;
99
+            },
100
+            decoration: InputDecoration(
101
+              border: OutlineInputBorder(),
102
+              labelText: getTranslated(context, 'name'),
103
+              hintText: getTranslated(context, 'name_hint'),
104
+            ),
105
+          ),
106
+          SizedBox(
107
+            height: 10,
108
+          ),
109
+          TextFormField(
110
+            validator: (val) {
111
+              if (val.isEmpty) {
112
+                return getTranslated(context, 'required_field');
113
+              }
114
+              return null;
115
+            },
116
+            decoration: InputDecoration(
117
+              border: OutlineInputBorder(),
118
+              labelText: getTranslated(context, 'email'),
119
+              hintText: getTranslated(context, 'email_hint'),
120
+            ),
121
+          ),
122
+          SizedBox(
123
+            height: 10,
124
+          ),
125
+          TextFormField(
126
+            decoration: InputDecoration(
127
+                border: OutlineInputBorder(),
128
+                hintText: getTranslated(context, 'date_of_birth')),
129
+            onTap: () async {
130
+              FocusScope.of(context).requestFocus(FocusNode());
131
+              await showDatePicker(
132
+                context: context,
133
+                initialDate: DateTime.now(),
134
+                firstDate: DateTime(DateTime.now().year),
135
+                lastDate: DateTime(DateTime.now().year + 20),
136
+              );
137
+            },
138
+          ),
139
+          SizedBox(
140
+            height: 10,
141
+          ),
142
+          MaterialButton(
143
+            onPressed: () {
144
+              if (_key.currentState.validate()) {
145
+                _showSuccessDialog();
146
+              }
147
+            },
148
+            height: 50,
149
+            shape: StadiumBorder(),
150
+            color: Theme.of(context).primaryColor,
151
+            child: Center(
152
+              child: Text(
153
+                getTranslated(context, 'submit_info'),
154
+                style: TextStyle(color: Colors.white, fontSize: 20),
155
+              ),
156
+            ),
157
+          )
158
+        ],
159
+      ),
160
+    );
161
+  }
162
+
163
+  Container _drawerList() {
164
+    TextStyle _textStyle = TextStyle(
165
+      color: Colors.white,
166
+      fontSize: 24,
167
+    );
168
+    return Container(
169
+      color: Theme.of(context).primaryColor,
170
+      child: ListView(
171
+        padding: EdgeInsets.zero,
172
+        children: <Widget>[
173
+          DrawerHeader(
174
+            child: Container(
175
+              height: 100,
176
+              child: CircleAvatar(),
177
+            ),
178
+          ),
179
+          ListTile(
180
+            leading: Icon(
181
+              Icons.info,
182
+              color: Colors.white,
183
+              size: 30,
184
+            ),
185
+            title: Text(
186
+              getTranslated(context, 'about_us'),
187
+              style: _textStyle,
188
+            ),
189
+            onTap: () {
190
+              // To close the Drawer
191
+              Navigator.pop(context);
192
+              // Navigating to About Page
193
+              Navigator.pushNamed(context, aboutRoute);
194
+            },
195
+          ),
196
+          ListTile(
197
+            leading: Icon(
198
+              Icons.settings,
199
+              color: Colors.white,
200
+              size: 30,
201
+            ),
202
+            title: Text(
203
+              getTranslated(context, 'settings'),
204
+              style: _textStyle,
205
+            ),
206
+            onTap: () {
207
+              // To close the Drawer
208
+              Navigator.pop(context);
209
+              // Navigating to About Page
210
+              Navigator.pushNamed(context, settingsRoute);
211
+            },
212
+          ),
213
+        ],
214
+      ),
215
+    );
216
+  }
217
+}

+ 24
- 0
fast_med_flutter/lib/pages/not_found_page.dart Zobrazit soubor

@@ -0,0 +1,24 @@
1
+import 'package:flutter/material.dart';
2
+
3
+class NotFoundPage extends StatefulWidget {
4
+  NotFoundPage({Key key}) : super(key: key);
5
+
6
+  @override
7
+  _NotFoundPageState createState() => _NotFoundPageState();
8
+}
9
+
10
+class _NotFoundPageState extends State<NotFoundPage> {
11
+  @override
12
+  Widget build(BuildContext context) {
13
+    return Scaffold(
14
+      appBar: AppBar(
15
+        title: Text("Not Found"),
16
+      ),
17
+      body: Container(
18
+        child: Center(
19
+          child: Text("Sorry, We couldn't found your page"),
20
+        ),
21
+      ),
22
+    );
23
+  }
24
+}

+ 54
- 0
fast_med_flutter/lib/pages/settings_page.dart Zobrazit soubor

@@ -0,0 +1,54 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:userstory2translate/classes/language.dart';
3
+import 'package:userstory2translate/localization/language_constants.dart';
4
+import 'package:userstory2translate/main.dart';
5
+
6
+class SettingsPage extends StatefulWidget {
7
+  SettingsPage({Key key}) : super(key: key);
8
+
9
+  @override
10
+  _SettingsPageState createState() => _SettingsPageState();
11
+}
12
+
13
+class _SettingsPageState extends State<SettingsPage> {
14
+  void _changeLanguage(Language language) async {
15
+    Locale _locale = await setLocale(language.languageCode);
16
+    MyApp.setLocale(context, _locale);
17
+  }
18
+
19
+  @override
20
+  Widget build(BuildContext context) {
21
+    return Scaffold(
22
+      appBar: AppBar(
23
+        title: Text(getTranslated(context, 'settings')),
24
+      ),
25
+      body: Container(
26
+        child: Center(
27
+            child: DropdownButton<Language>(
28
+              iconSize: 30,
29
+              hint: Text(getTranslated(context, 'change_language')),
30
+              onChanged: (Language language) {
31
+                _changeLanguage(language);
32
+              },
33
+              items: Language.languageList()
34
+                  .map<DropdownMenuItem<Language>>(
35
+                    (e) => DropdownMenuItem<Language>(
36
+                  value: e,
37
+                  child: Row(
38
+                    mainAxisAlignment: MainAxisAlignment.spaceAround,
39
+                    children: <Widget>[
40
+                      Text(
41
+                        e.flag,
42
+                        style: TextStyle(fontSize: 30),
43
+                      ),
44
+                      Text(e.name)
45
+                    ],
46
+                  ),
47
+                ),
48
+              )
49
+                  .toList(),
50
+            )),
51
+      ),
52
+    );
53
+  }
54
+}

+ 21
- 0
fast_med_flutter/lib/router/custom_router.dart Zobrazit soubor

@@ -0,0 +1,21 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:userstory2translate/pages/about_page.dart';
3
+import 'package:userstory2translate/pages/home_page.dart';
4
+import 'package:userstory2translate/pages/not_found_page.dart';
5
+import 'package:userstory2translate/pages/settings_page.dart';
6
+import 'package:userstory2translate/router/route_constants.dart';
7
+
8
+class CustomRouter {
9
+  static Route<dynamic> generatedRoute(RouteSettings settings) {
10
+    switch (settings.name) {
11
+      case homeRoute:
12
+        return MaterialPageRoute(builder: (_) => HomePage());
13
+      case aboutRoute:
14
+        return MaterialPageRoute(builder: (_) => AboutPage());
15
+      case settingsRoute:
16
+        return MaterialPageRoute(builder: (_) => SettingsPage());
17
+      default:
18
+        return MaterialPageRoute(builder: (_) => NotFoundPage());
19
+    }
20
+  }
21
+}

+ 3
- 0
fast_med_flutter/lib/router/route_constants.dart Zobrazit soubor

@@ -0,0 +1,3 @@
1
+const String homeRoute = "home";
2
+const String aboutRoute = "about";
3
+const String settingsRoute = "settings";