Ver código fonte

Sprint 2 // User Story

Mas files
carlos.perez25 4 anos atrás
pai
commit
a6b3726900
3 arquivos alterados com 75 adições e 0 exclusões
  1. 21
    0
      Carlos/custom_router.dart
  2. 51
    0
      Carlos/localization.dart
  3. 3
    0
      Carlos/route_constants.dart

+ 21
- 0
Carlos/custom_router.dart Ver arquivo

@@ -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
+}

+ 51
- 0
Carlos/localization.dart Ver arquivo

@@ -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
+}

+ 3
- 0
Carlos/route_constants.dart Ver arquivo

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