diff --git a/lib/locale/locales.dart b/lib/locale/locales.dart index 3ee5551d..86050d2c 100644 --- a/lib/locale/locales.dart +++ b/lib/locale/locales.dart @@ -354,6 +354,16 @@ class AppLocalizations { desc: 'Switch to toggle detail / overview', ); } + + String get aboutText { + return Intl.message( + 'wger Workout Manager is free, open source (FLOSS) software released ' + 'under the GNU General Public version 3 or later. ' + 'The code is freely available on github: ', + name: 'aboutText', + desc: 'Text in the about dialog', + ); + } } class AppLocalizationsDelegate extends LocalizationsDelegate { diff --git a/lib/models/workouts/workout_plan.dart b/lib/models/workouts/workout_plan.dart index 10210018..0dea7e66 100644 --- a/lib/models/workouts/workout_plan.dart +++ b/lib/models/workouts/workout_plan.dart @@ -34,10 +34,10 @@ class WorkoutPlan { @JsonKey(required: true, name: 'comment') String description; - @JsonKey(required: false, name: 'days') + @JsonKey(required: false, defaultValue: [], name: 'days') List days = []; - @JsonKey(ignore: true) + @JsonKey(ignore: true, defaultValue: []) List logs = []; WorkoutPlan({ diff --git a/lib/models/workouts/workout_plan.g.dart b/lib/models/workouts/workout_plan.g.dart index b305f864..f443b0af 100644 --- a/lib/models/workouts/workout_plan.g.dart +++ b/lib/models/workouts/workout_plan.g.dart @@ -15,8 +15,10 @@ WorkoutPlan _$WorkoutPlanFromJson(Map json) { : DateTime.parse(json['creation_date'] as String), description: json['comment'] as String, days: (json['days'] as List) - ?.map((e) => e == null ? null : Day.fromJson(e as Map)) - ?.toList(), + ?.map((e) => + e == null ? null : Day.fromJson(e as Map)) + ?.toList() ?? + [], ); } diff --git a/lib/providers/auth.dart b/lib/providers/auth.dart index 84db1a59..7a63b2fa 100644 --- a/lib/providers/auth.dart +++ b/lib/providers/auth.dart @@ -23,12 +23,15 @@ import 'dart:developer'; import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:http/http.dart' as http; +import 'package:package_info/package_info.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:wger/models/http_exception.dart'; class Auth with ChangeNotifier { String token; String serverUrl; + String serverVersion; + PackageInfo applicationVersion; /// flag to indicate that the application has successfully loaded all initial data bool dataInit = false; @@ -54,13 +57,29 @@ class Auth with ChangeNotifier { // return _userId; // } + /// Server application version + Future setServerVersion() async { + var url = '$serverUrl/api/v2/version/'; + final response = await http.get(url); + final responseData = json.decode(response.body); + serverVersion = responseData; + } + + /// (flutter) Application version + Future setApplicationVersion() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + applicationVersion = packageInfo; + } + Future _authenticate(String username, String password, String serverUrl) async { - // The android emulator uses var url = '$serverUrl/api/v2/login/'; //print(username); //print(password); try { + // Get the server version + await setServerVersion(); + final response = await http.post( url, headers: { @@ -129,6 +148,8 @@ class Auth with ChangeNotifier { // _expiryDate = expiryDate; log('autologin successful'); + setApplicationVersion(); + setServerVersion(); notifyListeners(); //_autoLogout(); return true; diff --git a/lib/screens/dashboard.dart b/lib/screens/dashboard.dart index e8cfbf7c..da180f45 100644 --- a/lib/screens/dashboard.dart +++ b/lib/screens/dashboard.dart @@ -47,6 +47,8 @@ class _DashboardScreenState extends State { /// Load initial data from the server Future _loadEntries(BuildContext context) async { if (!Provider.of(context, listen: false).dataInit) { + Provider.of(context, listen: false).setServerVersion(); + // Exercises await Provider.of(context, listen: false).fetchAndSetExercises(); diff --git a/lib/widgets/app_drawer.dart b/lib/widgets/app_drawer.dart index 8711f787..08c208ae 100644 --- a/lib/widgets/app_drawer.dart +++ b/lib/widgets/app_drawer.dart @@ -30,6 +30,8 @@ import 'package:wger/screens/workout_plans_screen.dart'; class AppDrawer extends StatelessWidget { @override Widget build(BuildContext context) { + final authProvider = Provider.of(context, listen: false); + return Drawer( child: Column( children: [ @@ -109,29 +111,33 @@ class AppDrawer extends StatelessWidget { dense: true, icon: Icon(Icons.info), applicationName: 'wger', - applicationVersion: '0.0.1 alpha', - applicationLegalese: '\u{a9} 2020 The wger team', - applicationIcon: Image.asset( - 'assets/images/logo.png', - width: 60, + applicationVersion: '${authProvider.applicationVersion.version} ' + '(server: ${authProvider.serverVersion})', + applicationLegalese: '\u{a9} 2020 - 2021 contributors', + applicationIcon: Padding( + padding: const EdgeInsets.only(top: 10), + child: Image.asset( + 'assets/images/logo.png', + width: 60, + ), ), aboutBoxChildren: [ + SizedBox( + height: 10, + ), RichText( text: TextSpan( style: TextStyle(fontSize: 16, color: Colors.black), children: [ TextSpan( - text: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ' - 'sed diam nonumy eirmod tempor invidunt ut labore et dolore ' - 'magna aliquyam erat, sed diam voluptua. At vero eos et accusam ' - 'et justo duo dolores et ea rebum.\n', + text: AppLocalizations.of(context).aboutText, ), TextSpan( - text: 'https://github.com/wger-project/wger', + text: 'https://github.com/wger-project', style: TextStyle(color: Colors.blue), recognizer: TapGestureRecognizer() ..onTap = () { - launch('https://github.com/wger-project/wger'); + launch('https://github.com/wger-project'); }, ) ], diff --git a/pubspec.lock b/pubspec.lock index 20abe75b..13246a1e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -63,7 +63,7 @@ packages: name: build_daemon url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.6" build_resolvers: dependency: transitive description: @@ -154,7 +154,7 @@ packages: name: code_builder url: "https://pub.dartlang.org" source: hosted - version: "3.5.0" + version: "3.6.0" collection: dependency: transitive description: @@ -412,7 +412,7 @@ packages: name: mockito url: "https://pub.dartlang.org" source: hosted - version: "4.1.3" + version: "4.1.4" nested: dependency: transitive description: @@ -441,6 +441,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.3" + package_info: + dependency: "direct main" + description: + name: package_info + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.3+2" path: dependency: transitive description: @@ -517,7 +524,7 @@ packages: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.3.2+3" + version: "4.3.3" pub_semver: dependency: transitive description: @@ -580,7 +587,7 @@ packages: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+3" + version: "0.0.2+2" shelf: dependency: transitive description: @@ -746,7 +753,7 @@ packages: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" win32: dependency: transitive description: @@ -776,5 +783,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.10.0-110 <2.11.0" + dart: ">=2.10.0 <2.11.0" flutter: ">=1.22.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 30d18e67..f7aac9e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: charts_flutter: ^0.9.0 flutter_typeahead: ^2.0.0 table_calendar: ^2.3.3 + package_info: ^0.4.3+2 dev_dependencies: flutter_test: