From 9b1d867826acbe7eb8a08d199c6470580cf41732 Mon Sep 17 00:00:00 2001 From: Bossanyi Tibor Date: Thu, 9 Jul 2020 14:08:14 +0200 Subject: [PATCH] bug fix 1.0 (android logo, old device, firstname, exercise save) --- android/app/src/main/AndroidManifest.xml | 6 +- lib/main.dart | 17 +++++- lib/model/auth.dart | 1 + lib/model/customer.dart | 8 +-- lib/util/session.dart | 25 +++++++- lib/view/account.dart | 2 +- lib/view/customer_modify_page.dart | 2 +- lib/view/exercise_new_page.dart | 6 +- lib/viewmodel/customer_view_model.dart | 4 +- pubspec.lock | 72 +++++++++++++++++++++++- pubspec.yaml | 6 ++ 11 files changed, 132 insertions(+), 17 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 709929d..066fc3f 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -7,8 +7,8 @@ FlutterApplication and put your custom class here. --> + android:label="WorkoutTest" + android:icon="@mipmap/launcher_icon"> - + \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index b28d024..af7ff4e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -51,7 +51,7 @@ class AitrainerApp extends StatelessWidget { localizationsDelegates: [ // ... app-specific localization delegate[s] here AppLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, + GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: [ @@ -59,6 +59,21 @@ class AitrainerApp extends StatelessWidget { const Locale('hu', "HU"), // Hungarian // ... other locales the app supports ], + localeResolutionCallback: (Locale locale, Iterable supportedLocales) { + //myLocale = deviceLocale ; + // here you make your app language similar to device language , + // but you should check whether the localization is supported by your app + Locale realSupportedLocale = Locale('en', "US"); + supportedLocales.forEach((supportedLocale) { + if ( supportedLocale.countryCode == locale.countryCode ) { + realSupportedLocale = supportedLocale; + } + }); + if ( realSupportedLocale.countryCode != locale.countryCode ) { + print ("Locale " + locale.countryCode + " not supported on this device :("); + } + return realSupportedLocale; + }, routes: { 'home': (context) => AitrainerHome(), 'loading': (context) => LoadingScreenMain(), diff --git a/lib/model/auth.dart b/lib/model/auth.dart index 14e1c31..fb920f1 100644 --- a/lib/model/auth.dart +++ b/lib/model/auth.dart @@ -43,6 +43,7 @@ class Auth { Customer userLoggedIn; bool firstLoad = true; List _exerciseTypes; + List deviceLanguages; factory Auth() { return _singleton; diff --git a/lib/model/customer.dart b/lib/model/customer.dart index 8dad01f..6063fb9 100644 --- a/lib/model/customer.dart +++ b/lib/model/customer.dart @@ -1,7 +1,7 @@ class Customer { String name; String email; - String firstName; + String firstname; String sex; int age; String active; @@ -18,7 +18,7 @@ class Customer { Customer({this.customerId, this.name, - this.firstName, + this.firstname, this.email, this.sex, this.age, @@ -36,7 +36,7 @@ class Customer { Customer.fromJson(Map json) { this.customerId = json['customerId']; this.name = json['name']; - this.firstName = json['firstname']; + this.firstname = json['firstname']; this.email = json['email']; this.sex = json['sex']; this.age = json['age']; @@ -52,7 +52,7 @@ class Customer { Map toJson() => { "name": name, - "firstName": firstName, + "firstname": firstname, "email": email, "age": age, "sex": sex, diff --git a/lib/util/session.dart b/lib/util/session.dart index 391ab8f..14583a3 100644 --- a/lib/util/session.dart +++ b/lib/util/session.dart @@ -2,7 +2,8 @@ import 'package:aitrainer_app/localization/app_language.dart'; import 'package:aitrainer_app/service/api.dart'; import 'package:aitrainer_app/service/customer_service.dart'; import 'package:aitrainer_app/service/exercisetype_service.dart'; -import 'package:aitrainer_app/viewmodel/exercise_type_changing_view_model.dart'; +import 'package:devicelocale/devicelocale.dart'; +import 'package:flutter/services.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:aitrainer_app/model/auth.dart'; @@ -19,11 +20,33 @@ class Session { if ( _auth.firstLoad ) { _fetchToken(_sharedPreferences, callback); + initDeviceLocale(); appLanguage.fetchLocale(); } } + Future initDeviceLocale() async { + List languages; + String currentLocale; + + // Platform messages may fail, so we use a try/catch PlatformException. + try { + languages = await Devicelocale.preferredLanguages; + Auth().deviceLanguages = languages; + print("device langs " + languages.toString()); + + } on PlatformException { + print("Error obtaining preferred languages"); + } + try { + currentLocale = await Devicelocale.currentLocale; + print("Device currentlocale " + currentLocale); + } on PlatformException { + print("Error obtaining current locale"); + } + } + /* Auth flow of the user, see auth.dart */ diff --git a/lib/view/account.dart b/lib/view/account.dart index 8af21fe..4f7aba5 100644 --- a/lib/view/account.dart +++ b/lib/view/account.dart @@ -77,7 +77,7 @@ class _AccountPagePageState extends State { children: [ Text(_loggedIn ? Auth().userLoggedIn.email + " " + Auth().userLoggedIn.name + " " + - Auth().userLoggedIn.firstName : "", + Auth().userLoggedIn.firstname : "", style: TextStyle(color: Colors.blue)), Icon(Icons.arrow_forward_ios), ]), diff --git a/lib/view/customer_modify_page.dart b/lib/view/customer_modify_page.dart index 48bf05d..05fe88a 100644 --- a/lib/view/customer_modify_page.dart +++ b/lib/view/customer_modify_page.dart @@ -163,7 +163,7 @@ class _CustomerModifyPageState extends State { labelText: AppLocalizations.of(context).translate('First Name'), ), keyboardType: TextInputType.emailAddress, - initialValue: customerChangeModel.customer.customer.firstName, + initialValue: customerChangeModel.customer.customer.firstname, onFieldSubmitted: (input) => customerChangeModel.customer.setFirstName(input) ) ) diff --git a/lib/view/exercise_new_page.dart b/lib/view/exercise_new_page.dart index b72aeb5..dd6c7c4 100644 --- a/lib/view/exercise_new_page.dart +++ b/lib/view/exercise_new_page.dart @@ -30,7 +30,7 @@ class _ExerciseNewPageState extends State { model.exerciseViewModel.createNew(); customerName = model != null && model.customer != null ? model.customer.name + " " + - model.customer.firstName + model.customer.firstname : "Please select a customer"; exerciseName = model != null && @@ -157,7 +157,7 @@ class _ExerciseNewPageState extends State { inputFormatters: [ WhitelistingTextInputFormatter(RegExp(r"[\d.]")) ], - onFieldSubmitted: (input) => { + onChanged: (input) => { print ("UnitQuantity value $input"), model.exerciseViewModel.setUnitQuantity( double.parse(input)) @@ -193,7 +193,7 @@ class _ExerciseNewPageState extends State { inputFormatters: [ WhitelistingTextInputFormatter(RegExp(r"[\d.]")) ], - onFieldSubmitted: (input) => + onChanged: (input) => { print ("Quantity value $input"), model.exerciseViewModel.setQuantity( diff --git a/lib/viewmodel/customer_view_model.dart b/lib/viewmodel/customer_view_model.dart index 5d55df1..1ecd113 100644 --- a/lib/viewmodel/customer_view_model.dart +++ b/lib/viewmodel/customer_view_model.dart @@ -11,7 +11,7 @@ class CustomerViewModel { } String get firstName { - return this.customer.firstName; + return this.customer.firstname; } String get sex { @@ -26,7 +26,7 @@ class CustomerViewModel { this.customer.name = name; } setFirstName(String firstName) { - this.customer.firstName = firstName; + this.customer.firstname = firstName; } setPassword( String password ) { diff --git a/pubspec.lock b/pubspec.lock index c609b3c..60ef7bc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.13" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.0" async: dependency: transitive description: @@ -36,6 +50,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.12" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.5" cupertino_icons: dependency: "direct main" description: @@ -50,6 +78,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" + devicelocale: + dependency: "direct main" + description: + name: devicelocale + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.1" fake_async: dependency: transitive description: @@ -69,6 +104,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.8" + flutter_launcher_icons: + dependency: "direct dev" + description: + name: flutter_launcher_icons + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.5" flutter_localizations: dependency: "direct main" description: flutter @@ -93,6 +135,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.1.4" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.14" intl: dependency: "direct dev" description: @@ -128,6 +177,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.4" provider: dependency: "direct dev" description: @@ -203,6 +259,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.0" + yaml: + dependency: transitive + description: + name: yaml + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" sdks: dart: ">=2.7.0 <3.0.0" - flutter: ">=1.0.0 <2.0.0" + flutter: ">=1.12.13+hotfix.6 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 428c575..de00cca 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,6 +27,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.3 + devicelocale: ^0.3.1 flutter_localizations: sdk: flutter @@ -42,6 +43,11 @@ dev_dependencies: datetime_picker_formfield: ^1.0.0 shared_preferences: ^0.4.1 + flutter_launcher_icons: "^0.7.3" + +flutter_icons: + android: "launcher_icon" + image_path: "asset/icon/icon.png" # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec