From 89f037593a7e300414a06986d60e5c8eee7c51f0 Mon Sep 17 00:00:00 2001 From: King Wu Date: Mon, 27 May 2019 01:05:55 +0800 Subject: [PATCH 1/3] Update dependency and support Flutter 1.5.4 --- ios/Runner.xcodeproj/project.pbxproj | 28 ++++++++++++++++++++-------- lib/app/bloc/HomeBloc.dart | 2 +- lib/app/ui/page/AppDetailPage.dart | 4 ++-- lib/app/ui/page/HomePage.dart | 4 ++-- pubspec.yaml | 20 +++++++++++--------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index df19593..0a9fed8 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 0FBC411A21EB4A6A000179D3 /* development.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 0FBC411821EB4A69000179D3 /* development.xcconfig */; }; 0FBC411C21EB4AF6000179D3 /* production.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 0FBC411B21EB4AF6000179D3 /* production.xcconfig */; }; 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -52,12 +51,15 @@ 0FBC411B21EB4AF6000179D3 /* production.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = production.xcconfig; path = Flutter/production.xcconfig; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; + 3869BA3A5C1AB17078566850 /* Pods-Runner.release-production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release-production.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-production.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; + 46A5597D1B2394C187A4C219 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 74C09DEB934CD08D1080A170 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7D8E3A39A7A6516A2914838E /* Pods-Runner.release-development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release-development.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-development.xcconfig"; sourceTree = ""; }; 7ECD58DBA383B8EBBA145492 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; @@ -67,6 +69,11 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C763E80E4F6EF24B95B02C49 /* Pods-Runner.debug-development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug-development.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-development.xcconfig"; sourceTree = ""; }; + CA107340ABA465041774FF12 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + E2BBAB54802AA2A60740E8F8 /* Pods-Runner.release-staging.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release-staging.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release-staging.xcconfig"; sourceTree = ""; }; + F0906D8745EEF9740E6C5433 /* Pods-Runner.debug-production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug-production.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-production.xcconfig"; sourceTree = ""; }; + F6CC6E33F9346C7274E7135B /* Pods-Runner.debug-staging.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug-staging.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug-staging.xcconfig"; sourceTree = ""; }; FEC6451D21E984D400024C55 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Main.strings; sourceTree = ""; }; FEC6451E21E984D400024C55 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/LaunchScreen.strings; sourceTree = ""; }; /* End PBXFileReference section */ @@ -99,7 +106,6 @@ 0FBC411B21EB4AF6000179D3 /* production.xcconfig */, 0FBC411821EB4A69000179D3 /* development.xcconfig */, 0FBC411721EB4A69000179D3 /* staging.xcconfig */, - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -155,6 +161,15 @@ F25004F02FF280D4545A80CB /* Pods */ = { isa = PBXGroup; children = ( + 74C09DEB934CD08D1080A170 /* Pods-Runner.debug.xcconfig */, + F0906D8745EEF9740E6C5433 /* Pods-Runner.debug-production.xcconfig */, + F6CC6E33F9346C7274E7135B /* Pods-Runner.debug-staging.xcconfig */, + C763E80E4F6EF24B95B02C49 /* Pods-Runner.debug-development.xcconfig */, + CA107340ABA465041774FF12 /* Pods-Runner.release.xcconfig */, + 3869BA3A5C1AB17078566850 /* Pods-Runner.release-production.xcconfig */, + E2BBAB54802AA2A60740E8F8 /* Pods-Runner.release-staging.xcconfig */, + 7D8E3A39A7A6516A2914838E /* Pods-Runner.release-development.xcconfig */, + 46A5597D1B2394C187A4C219 /* Pods-Runner.profile.xcconfig */, ); name = Pods; sourceTree = ""; @@ -227,7 +242,6 @@ 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 0FBC411921EB4A6A000179D3 /* staging.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 0FBC411A21EB4A6A000179D3 /* development.xcconfig in Resources */, 0FBC411C21EB4AF6000179D3 /* production.xcconfig in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, @@ -289,12 +303,11 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", "${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework", "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", "${BUILT_PRODUCTS_DIR}/flutter_stetho/flutter_stetho.framework", "${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework", - "${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework", "${BUILT_PRODUCTS_DIR}/sqflite/sqflite.framework", ); name = "[CP] Embed Pods Frameworks"; @@ -303,12 +316,11 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_stetho.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqflite.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ diff --git a/lib/app/bloc/HomeBloc.dart b/lib/app/bloc/HomeBloc.dart index b8924cd..c5d733f 100644 --- a/lib/app/bloc/HomeBloc.dart +++ b/lib/app/bloc/HomeBloc.dart @@ -30,7 +30,7 @@ class HomeBloc{ void _init(){ // Debounce search text - _searchText.debounce(const Duration(milliseconds: 500)) + _searchText.debounceTime(const Duration(milliseconds: 500)) .listen((String searchText){ _searchApps(searchText); }); diff --git a/lib/app/ui/page/AppDetailPage.dart b/lib/app/ui/page/AppDetailPage.dart index b57d323..1c3eea9 100644 --- a/lib/app/ui/page/AppDetailPage.dart +++ b/lib/app/ui/page/AppDetailPage.dart @@ -252,7 +252,7 @@ class _AppDetailPageState extends State { child: CachedNetworkImage( imageUrl: url, fit: BoxFit.fitHeight, - errorWidget: new Icon(Icons.error), + errorWidget: (context, url, error) => new Icon(Icons.error), fadeOutDuration: new Duration(seconds: 1), fadeInDuration: new Duration(seconds: 1) ) @@ -278,7 +278,7 @@ class _AppDetailPageState extends State { borderRadius: BorderRadius.circular(16.0), child: CachedNetworkImage( imageUrl: iconUrl, - errorWidget: new Icon(Icons.error), + errorWidget: (context, url, error) => new Icon(Icons.error), fadeOutDuration: new Duration(seconds: 1), fadeInDuration: new Duration(seconds: 1) ) diff --git a/lib/app/ui/page/HomePage.dart b/lib/app/ui/page/HomePage.dart index cce5100..4179602 100644 --- a/lib/app/ui/page/HomePage.dart +++ b/lib/app/ui/page/HomePage.dart @@ -225,7 +225,7 @@ class _HomePageState extends State { borderRadius: BorderRadius.circular(16.0), child: CachedNetworkImage( imageUrl: app.artworkUrl100, - errorWidget: new Icon(Icons.error), + errorWidget: (context, url, error) => new Icon(Icons.error), fadeOutDuration: new Duration(seconds: 1), fadeInDuration: new Duration(seconds: 1) ) @@ -376,7 +376,7 @@ class _HomePageState extends State { borderRadius: radius, child: CachedNetworkImage( imageUrl: iconUrl, - errorWidget: new Icon(Icons.error), + errorWidget: (context, url, error) => new Icon(Icons.error), fadeOutDuration: new Duration(seconds: 1), fadeInDuration: new Duration(seconds: 1) ) diff --git a/pubspec.yaml b/pubspec.yaml index 572b3a6..719d570 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,26 +22,28 @@ dependencies: flutter_localizations: sdk: flutter fluro: 1.4.0 - dio: 2.0.1 + dio: 2.1.5 logging: 0.11.3+2 - json_annotation: 2.0.0 - sprintf: 4.0.0 - rxdart: 0.20.0 - cached_network_image: 0.5.1 - sqflite: 0.13.0+1 - smooth_star_rating: 1.0.1 + json_annotation: 2.4.0 + sprintf: 4.0.2 + rxdart: 0.22.0 + cached_network_image: 0.8.0 + sqflite: 1.1.5 + smooth_star_rating: 1.0.2 flutter_stetho: 0.2.2 + analyzer: 0.33.3 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: 0.1.2 dev_dependencies: - intl_translation: 0.17.1 flutter_test: sdk: flutter build_runner: 1.0.0 - json_serializable: 2.0.0 + json_serializable: 3.0.0 + gen_lang: 0.1.1 + lang_table: 0.1.0 # For information on the generic Dart part of this file, see the From b81fdabe719d32689e208767a718284ff516fad1 Mon Sep 17 00:00:00 2001 From: King Wu Date: Mon, 27 May 2019 23:50:16 +0800 Subject: [PATCH 2/3] Replace flutter i18n by gen_lang and lang_table plugins --- lib/generated/i18n.dart | 155 ++++++++++---------------------- lib/generated/messages_all.dart | 136 ++++++++++++++++++++++++++++ pubspec.yaml | 2 +- res/string/string_de.json | 9 ++ res/string/string_en.json | 9 ++ res/string/string_ja.json | 9 ++ res/string/string_zh_TW.json | 9 ++ res/values/strings_de.arb | 9 -- res/values/strings_en.arb | 9 -- res/values/strings_ja.arb | 10 --- res/values/strings_zh_TW.arb | 10 --- 11 files changed, 220 insertions(+), 147 deletions(-) create mode 100644 lib/generated/messages_all.dart create mode 100644 res/string/string_de.json create mode 100644 res/string/string_en.json create mode 100644 res/string/string_ja.json create mode 100644 res/string/string_zh_TW.json delete mode 100644 res/values/strings_de.arb delete mode 100644 res/values/strings_en.arb delete mode 100644 res/values/strings_ja.arb delete mode 100644 res/values/strings_zh_TW.arb diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 45e14f8..cfcfce0 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -1,101 +1,60 @@ +// DO NOT EDIT. This is code generated via package:gen_lang/generate.dart + import 'dart:async'; -import 'package:flutter/foundation.dart'; +import 'package:intl/intl.dart'; import 'package:flutter/material.dart'; -// ignore_for_file: non_constant_identifier_names -// ignore_for_file: camel_case_types -// ignore_for_file: prefer_single_quotes - -//This file is automatically generated. DO NOT EDIT, all your changes would be lost. -class S implements WidgetsLocalizations { - const S(); - - static const GeneratedLocalizationsDelegate delegate = - GeneratedLocalizationsDelegate(); +import 'messages_all.dart'; - static S of(BuildContext context) => Localizations.of(context, S); +class S { + + static const GeneratedLocalizationsDelegate delegate = GeneratedLocalizationsDelegate(); - @override - TextDirection get textDirection => TextDirection.ltr; - - String get detailRate => "Comments"; - String get dialogLoading => "Loading ..."; - String get hello => "Hello"; - String get homeEmptyList => "No results"; - String get homeRecommend => "Recommend"; - String get homeSearchHint => "Search ..."; - String get title => "Hello world App"; -} + static S of(BuildContext context) { + return Localizations.of(context, S); + } + + static Future load(Locale locale) { + final String name = locale.countryCode == null ? locale.languageCode : locale.toString(); -class $de extends S { - const $de(); + final String localeName = Intl.canonicalizedLocale(name); - @override - TextDirection get textDirection => TextDirection.ltr; + return initializeMessages(localeName).then((bool _) { + Intl.defaultLocale = localeName; + return new S(); + }); + } + + String get hello { + return Intl.message('Hello', name: 'hello'); + } - @override - String get homeSearchHint => "Suche ..."; - @override - String get dialogLoading => "Wird geladen ..."; - @override - String get homeEmptyList => "Keine Ergebnisse"; - @override - String get hello => "Hello De"; - @override - String get detailRate => "Bemerkungen"; - @override - String get title => "Hello world De"; - @override - String get homeRecommend => "Empfehlen"; -} + String get title { + return Intl.message('Hello world App', name: 'title'); + } -class $zh_TW extends S { - const $zh_TW(); + String get dialogLoading { + return Intl.message('Loading ...', name: 'dialogLoading'); + } - @override - TextDirection get textDirection => TextDirection.ltr; + String get homeEmptyList { + return Intl.message('No results', name: 'homeEmptyList'); + } - @override - String get homeSearchHint => "搜索 ..."; - @override - String get dialogLoading => "載入中 ..."; - @override - String get homeEmptyList => "沒有結果"; - @override - String get hello => "Hello"; - @override - String get detailRate => "評論"; - @override - String get title => "Hello world App"; - @override - String get homeRecommend => "推介"; -} + String get homeSearchHint { + return Intl.message('Search ...', name: 'homeSearchHint'); + } -class $ja extends S { - const $ja(); + String get homeRecommend { + return Intl.message('Recommend', name: 'homeRecommend'); + } - @override - TextDirection get textDirection => TextDirection.ltr; + String get detailRate { + return Intl.message('Comments', name: 'detailRate'); + } - @override - String get homeSearchHint => "検索 ..."; - @override - String get dialogLoading => "読み込み中 ..."; - @override - String get homeEmptyList => "結果なし"; - @override - String get hello => "Hello"; - @override - String get detailRate => "コメント"; - @override - String get title => "Hello world アプリ"; - @override - String get homeRecommend => "おすすめ"; -} -class $en extends S { - const $en(); } class GeneratedLocalizationsDelegate extends LocalizationsDelegate { @@ -103,10 +62,11 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { List get supportedLocales { return const [ - Locale("de", ""), - Locale("zh", "TW"), - Locale("ja", ""), - Locale("en", ""), + Locale("en", ""), + Locale("ja", ""), + Locale("zh", "TW"), + Locale("de", ""), + ]; } @@ -144,22 +104,7 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { @override Future load(Locale locale) { - final String lang = getLang(locale); - if (lang != null) { - switch (lang) { - case "de": - return SynchronousFuture(const $de()); - case "zh_TW": - return SynchronousFuture(const $zh_TW()); - case "ja": - return SynchronousFuture(const $ja()); - case "en": - return SynchronousFuture(const $en()); - default: - // NO-OP. - } - } - return SynchronousFuture(const S()); + return S.load(locale); } @override @@ -169,9 +114,3 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate { @override bool shouldReload(GeneratedLocalizationsDelegate old) => false; } - -String getLang(Locale l) => l == null - ? null - : l.countryCode != null && l.countryCode.isEmpty - ? l.languageCode - : l.toString(); diff --git a/lib/generated/messages_all.dart b/lib/generated/messages_all.dart new file mode 100644 index 0000000..98c62b4 --- /dev/null +++ b/lib/generated/messages_all.dart @@ -0,0 +1,136 @@ +// DO NOT EDIT. This is code generated via package:gen_lang/generate.dart + +import 'dart:async'; + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; +// ignore: implementation_imports +import 'package:intl/src/intl_helpers.dart'; + +final _$ja = $ja(); + +class $ja extends MessageLookupByLibrary { + get localeName => 'ja'; + + final messages = { + "hello" : MessageLookupByLibrary.simpleMessage("Hello"), + "title" : MessageLookupByLibrary.simpleMessage("Hello world App"), + "dialogLoading" : MessageLookupByLibrary.simpleMessage("読み込み中 ..."), + "homeEmptyList" : MessageLookupByLibrary.simpleMessage("結果なし"), + "homeSearchHint" : MessageLookupByLibrary.simpleMessage("検索 ..."), + "homeRecommend" : MessageLookupByLibrary.simpleMessage("おすすめ"), + "detailRate" : MessageLookupByLibrary.simpleMessage("コメント"), + + }; +} + +final _$zh_TW = $zh_TW(); + +class $zh_TW extends MessageLookupByLibrary { + get localeName => 'zh_TW'; + + final messages = { + "hello" : MessageLookupByLibrary.simpleMessage("Hello"), + "title" : MessageLookupByLibrary.simpleMessage("Hello world App"), + "dialogLoading" : MessageLookupByLibrary.simpleMessage("載入中 ..."), + "homeEmptyList" : MessageLookupByLibrary.simpleMessage("沒有結果"), + "homeSearchHint" : MessageLookupByLibrary.simpleMessage("搜索 ..."), + "homeRecommend" : MessageLookupByLibrary.simpleMessage("推介"), + "detailRate" : MessageLookupByLibrary.simpleMessage("評論"), + + }; +} + +final _$en = $en(); + +class $en extends MessageLookupByLibrary { + get localeName => 'en'; + + final messages = { + "hello" : MessageLookupByLibrary.simpleMessage("Hello"), + "title" : MessageLookupByLibrary.simpleMessage("Hello world App"), + "dialogLoading" : MessageLookupByLibrary.simpleMessage("Loading ..."), + "homeEmptyList" : MessageLookupByLibrary.simpleMessage("No results"), + "homeSearchHint" : MessageLookupByLibrary.simpleMessage("Search ..."), + "homeRecommend" : MessageLookupByLibrary.simpleMessage("Recommend"), + "detailRate" : MessageLookupByLibrary.simpleMessage("Comments"), + + }; +} + +final _$de = $de(); + +class $de extends MessageLookupByLibrary { + get localeName => 'de'; + + final messages = { + "hello" : MessageLookupByLibrary.simpleMessage("Hello"), + "title" : MessageLookupByLibrary.simpleMessage("Hello world App"), + "dialogLoading" : MessageLookupByLibrary.simpleMessage("Wird geladen ..."), + "homeEmptyList" : MessageLookupByLibrary.simpleMessage("Keine Ergebnisse"), + "homeSearchHint" : MessageLookupByLibrary.simpleMessage("Suche ..."), + "homeRecommend" : MessageLookupByLibrary.simpleMessage("Empfehlen"), + "detailRate" : MessageLookupByLibrary.simpleMessage("Bemerkungen"), + + }; +} + + + +typedef Future LibraryLoader(); +Map _deferredLibraries = { + "ja": () => Future.value(null), + "zh_TW": () => Future.value(null), + "en": () => Future.value(null), + "de": () => Future.value(null), + +}; + +MessageLookupByLibrary _findExact(localeName) { + switch (localeName) { + case "ja": + return _$ja; + case "zh_TW": + return _$zh_TW; + case "en": + return _$en; + case "de": + return _$de; + + default: + return null; + } +} + +/// User programs should call this before using [localeName] for messages. +Future initializeMessages(String localeName) async { + var availableLocale = Intl.verifiedLocale( + localeName, + (locale) => _deferredLibraries[locale] != null, + onFailure: (_) => null); + if (availableLocale == null) { + return Future.value(false); + } + var lib = _deferredLibraries[availableLocale]; + await (lib == null ? Future.value(false) : lib()); + + initializeInternalMessageLookup(() => CompositeMessageLookup()); + messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor); + + return Future.value(true); +} + +bool _messagesExistFor(String locale) { + try { + return _findExact(locale) != null; + } catch (e) { + return false; + } +} + +MessageLookupByLibrary _findGeneratedMessagesFor(locale) { + var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, + onFailure: (_) => null); + if (actualLocale == null) return null; + return _findExact(actualLocale); +} diff --git a/pubspec.yaml b/pubspec.yaml index 719d570..6180074 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,7 +43,7 @@ dev_dependencies: build_runner: 1.0.0 json_serializable: 3.0.0 gen_lang: 0.1.1 - lang_table: 0.1.0 + lang_table: 0.1.1 # For information on the generic Dart part of this file, see the diff --git a/res/string/string_de.json b/res/string/string_de.json new file mode 100644 index 0000000..76c3334 --- /dev/null +++ b/res/string/string_de.json @@ -0,0 +1,9 @@ +{ + "hello":"Hello", + "title":"Hello world App", + "dialogLoading":"Wird geladen ...", + "homeEmptyList":"Keine Ergebnisse", + "homeSearchHint":"Suche ...", + "homeRecommend":"Empfehlen", + "detailRate":"Bemerkungen" +} \ No newline at end of file diff --git a/res/string/string_en.json b/res/string/string_en.json new file mode 100644 index 0000000..c0fc0ff --- /dev/null +++ b/res/string/string_en.json @@ -0,0 +1,9 @@ +{ + "hello":"Hello", + "title":"Hello world App", + "dialogLoading":"Loading ...", + "homeEmptyList":"No results", + "homeSearchHint":"Search ...", + "homeRecommend":"Recommend", + "detailRate":"Comments" +} \ No newline at end of file diff --git a/res/string/string_ja.json b/res/string/string_ja.json new file mode 100644 index 0000000..596a37b --- /dev/null +++ b/res/string/string_ja.json @@ -0,0 +1,9 @@ +{ + "hello":"Hello", + "title":"Hello world App", + "dialogLoading":"読み込み中 ...", + "homeEmptyList":"結果なし", + "homeSearchHint":"検索 ...", + "homeRecommend":"おすすめ", + "detailRate":"コメント" +} \ No newline at end of file diff --git a/res/string/string_zh_TW.json b/res/string/string_zh_TW.json new file mode 100644 index 0000000..1a9a59e --- /dev/null +++ b/res/string/string_zh_TW.json @@ -0,0 +1,9 @@ +{ + "hello":"Hello", + "title":"Hello world App", + "dialogLoading":"載入中 ...", + "homeEmptyList":"沒有結果", + "homeSearchHint":"搜索 ...", + "homeRecommend":"推介", + "detailRate":"評論" +} \ No newline at end of file diff --git a/res/values/strings_de.arb b/res/values/strings_de.arb deleted file mode 100644 index 208c4d6..0000000 --- a/res/values/strings_de.arb +++ /dev/null @@ -1,9 +0,0 @@ -{ - "title": "Hello world De", - "hello": "Hello De", - "homeSearchHint": "Suche ...", - "homeRecommend": "Empfehlen", - "dialogLoading": "Wird geladen ...", - "detailRate": "Bemerkungen", - "homeEmptyList": "Keine Ergebnisse" -} \ No newline at end of file diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb deleted file mode 100644 index 22086c5..0000000 --- a/res/values/strings_en.arb +++ /dev/null @@ -1,9 +0,0 @@ -{ - "title": "Hello world App", - "hello": "Hello", - "homeSearchHint": "Search ...", - "homeRecommend": "Recommend", - "dialogLoading": "Loading ...", - "detailRate": "Comments", - "homeEmptyList": "No results" -} \ No newline at end of file diff --git a/res/values/strings_ja.arb b/res/values/strings_ja.arb deleted file mode 100644 index 48a38f3..0000000 --- a/res/values/strings_ja.arb +++ /dev/null @@ -1,10 +0,0 @@ -{ - "title": "Hello world アプリ", - "hello": "Hello", - "homeSearchHint": "検索 ...", - "homeRecommend": "おすすめ", - "dialogLoading": "読み込み中 ...", - "detailRate": "コメント", - "homeEmptyList": "結果なし" - -} \ No newline at end of file diff --git a/res/values/strings_zh_TW.arb b/res/values/strings_zh_TW.arb deleted file mode 100644 index 15c5c4d..0000000 --- a/res/values/strings_zh_TW.arb +++ /dev/null @@ -1,10 +0,0 @@ -{ - "title": "Hello world App", - "hello": "Hello", - "homeSearchHint": "搜索 ...", - "homeRecommend": "推介", - "dialogLoading": "載入中 ...", - "detailRate": "評論", - "homeEmptyList": "沒有結果" - -} \ No newline at end of file From 9c9230ff8ead77a0a113877b00cf38b8588970b7 Mon Sep 17 00:00:00 2001 From: King Wu Date: Mon, 27 May 2019 23:50:32 +0800 Subject: [PATCH 3/3] Update ReadMe --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d614bc..89896b1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and - Restful api call by using [Dio](https://github.com/flutterchina/dio) - Database debugging (Android Only) by using [flutter_stetho](https://github.com/brianegan/flutter_stetho) - Loading Network Image -- Localization by using Flutter i18n plugin +- Localization by using [gen_lang](https://github.com/KingWu/gen_lang) + and [lang_table](https://github.com/KingWu/lang_table) - Environment Variable & Project Config (Like App Name, Bundle Id) based on different project flavour (Development, Staging & Production) - Build pojo by using json_serializable - Update each list item instead of re-rendering whole list view when data set has changed on a list item @@ -21,8 +22,6 @@ A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and ## Install 1. Follow flutter [official setup guide](https://flutter.io/docs/get-started/install) to set up flutter environment -2. Install Flutter i18n plugin into Android Studio - >Preference > Plugins > Browse repositories > Type ‘Flutter i18n’ > Install > Restart Android Studio ## Run Config 1. Click 'Edit Configuration' @@ -36,15 +35,28 @@ A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and ## Useful Command -Generate json serialize and deserialize functions +### Generate json serialize and deserialize functions -> flutter packages pub run build_runner build --delete-conflicting-outputs +``` +flutter packages pub run build_runner build --delete-conflicting-outputs +``` + +### lang_table +``` +flutter packages pub run lang_table:generate --platform=airTable --input=https://api.airtable.com/v0/appZmh0WMg3y6APAg/example --api-key={YOUR API KEY} --target=Flutter +``` + +### gen_lang +``` +flutter packages pub run gen_lang:generate +``` ## Known Issues - [Unable to launch app on ios simulator with different flavours](https://github.com/flutter/flutter/issues/21335) ## Migration Guide -- If you wanna to use this project as your project' base, please read [migration guide](https://github.com/KingWu/flutter_starter_kit/wiki/Migration-Guide) +- If you wanna to use this project as your project's base, please read + [migration guide](https://github.com/KingWu/flutter_starter_kit/wiki/Migration-Guide) ## Reference @@ -70,6 +82,7 @@ Generate json serialize and deserialize functions - [JSON and serialization](https://flutter.io/docs/development/data-and-backend/json) #### Localization +- [A new approach of localization in Flutter](https://medium.com/@kingwu/a-new-approach-of-localization-in-flutter-e18bfb2b14ab) - [Flutter: internationalization tutorials: Part 3— Android Studio plugin](https://medium.com/@datvt9312/flutter-internationalization-tutorials-part-3-android-studio-plugin-8604e2dc90f0) - [讓 Flutter App 支援多國語系的開發流程](https://medium.com/@zonble/%E8%AE%93-flutter-app-%E6%94%AF%E6%8F%B4%E5%A4%9A%E5%9C%8B%E8%AA%9E%E7%B3%BB%E7%9A%84%E9%96%8B%E7%99%BC%E6%B5%81%E7%A8%8B-ceb31532e2e1)