From ba559326a1b6830401bf2a32aed28bc624df3dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Fri, 1 Jul 2022 16:51:41 +0200 Subject: [PATCH] Clean some code, fix deprecations --- android/app/build.gradle | 2 +- android/gradle.properties | 4 +- lib/provider/data.dart | 4 +- lib/screens/game.dart | 2 +- lib/screens/home.dart | 27 +++++----- lib/utils/random_pick.dart | 6 ++- lib/widgets/dialog_fetch_error.dart | 4 +- lib/widgets/dialog_gameover.dart | 4 +- lib/widgets/letters.dart | 17 ++++--- lib/widgets/my_app_bar.dart | 5 -- pubspec.lock | 79 ++++++++++++++++++----------- pubspec.yaml | 2 +- test/widget_test.dart | 10 ---- 13 files changed, 88 insertions(+), 78 deletions(-) delete mode 100644 test/widget_test.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 2f9bebd..fdffea3 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -39,7 +39,7 @@ if (keystorePropertiesFile.exists()) { } android { - compileSdkVersion 29 + compileSdkVersion 31 lintOptions { disable 'InvalidPackage' diff --git a/android/gradle.properties b/android/gradle.properties index 730a8e7..2f77d26 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -2,5 +2,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true android.enableR8=true -app.versionName=1.2.2 -app.versionCode=13 +app.versionName=1.2.3 +app.versionCode=14 diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 0570e49..b224e4e 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -36,8 +36,8 @@ class Data extends ChangeNotifier { void _getPrefs() async { await _sharedPrefs.init(); _gameModeValue = _sharedPrefs.gameMode ?? - onlineGameMode.keys - .firstWhere((k) => onlineGameMode[k].contains(_sharedPrefs.level), orElse: () => false); + onlineGameMode.keys.firstWhere((k) => onlineGameMode[k].contains(_sharedPrefs.level), + orElse: () => false); _levelValue = onlineGameMode[_gameModeValue].contains(_sharedPrefs.level) ? _sharedPrefs.level : onlineGameMode[_gameModeValue].first; diff --git a/lib/screens/game.dart b/lib/screens/game.dart index 9ba71b7..2c039c4 100644 --- a/lib/screens/game.dart +++ b/lib/screens/game.dart @@ -49,7 +49,7 @@ class Game extends StatelessWidget { title: Text('Indice'), content: Text(_myProvider.clue), actions: <Widget>[ - FlatButton( + TextButton( child: Text('Revenir au jeu'), onPressed: () => Navigator.of(context).pop(), ) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 75e73b2..6142e9e 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -12,7 +12,6 @@ class Home extends StatelessWidget { @override Widget build(BuildContext context) { - Orientation orientation = MediaQuery.of(context).orientation; Data _myProvider = Provider.of<Data>(context); void _errorWord(context) { @@ -23,7 +22,7 @@ class Home extends StatelessWidget { content: Text('Erreur inattendue à la récupération d\'un mot aléatoire.\n' 'Installer une nouvelle version de l\'application pourrait corriger cette anomalie.'), actions: <Widget>[ - FlatButton( + TextButton( child: Text('Fermer'), onPressed: () => Navigator.of(context).pop(), ) @@ -64,7 +63,6 @@ class Home extends StatelessWidget { ), ), ), - Column( children: [ Row( @@ -73,7 +71,8 @@ class Home extends StatelessWidget { Text('Mode en ligne'), Switch( value: _myProvider.gameModeValue, - onChanged: (bool value) => _myProvider.updateGameMode = value, + onChanged: (bool value) => + _myProvider.updateGameMode = value, activeTrackColor: Color(board), activeColor: Colors.greenAccent[400], ), @@ -84,7 +83,8 @@ class Home extends StatelessWidget { children: [ Text('Niveau'), DropdownButton<String>( - value: _myProvider.levelValue ?? onlineGameMode[_myProvider.gameModeValue].first, + value: _myProvider.levelValue ?? + onlineGameMode[_myProvider.gameModeValue].first, items: onlineGameMode[_myProvider.gameModeValue] .map<DropdownMenuItem<String>>((String value) { return DropdownMenuItem<String>( @@ -92,21 +92,20 @@ class Home extends StatelessWidget { child: Text(value), ); }).toList(), - onChanged: (String value) => _myProvider.updateLevel = value, + onChanged: (String value) => + _myProvider.updateLevel = value, ), ], ), ], ), - - RaisedButton.icon( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0))), - color: Color(board), - textColor: Colors.white, - padding: EdgeInsets.all(10.0), + ElevatedButton.icon( + style: ElevatedButton.styleFrom( + onPrimary: Colors.white, + primary: Color(board), + padding: EdgeInsets.all(10.0), + ), onPressed: () async { - Scaffold.of(context).removeCurrentSnackBar(); _myProvider.resetGame(); _myProvider.searching = true; bool control = true; diff --git a/lib/utils/random_pick.dart b/lib/utils/random_pick.dart index 49c1a13..fce8cd4 100644 --- a/lib/utils/random_pick.dart +++ b/lib/utils/random_pick.dart @@ -23,11 +23,13 @@ class RandomPick { await wordFromLocal(); break; case 'Avancé': - _url = 'https://www.palabrasaleatorias.com/mots-aleatoires.php?fs=1&fs2=0&Submit=Nouveau+mot'; + _url = + 'https://www.palabrasaleatorias.com/mots-aleatoires.php?fs=1&fs2=0&Submit=Nouveau+mot'; await wordFromWeb(_url); break; case 'Junior': - _url = 'https://www.palabrasaleatorias.com/mots-aleatoires.php?fs=1&fs2=1&Submit=Nouveau+mot'; + _url = + 'https://www.palabrasaleatorias.com/mots-aleatoires.php?fs=1&fs2=1&Submit=Nouveau+mot'; await wordFromWeb(_url); break; case 'Expert': diff --git a/lib/widgets/dialog_fetch_error.dart b/lib/widgets/dialog_fetch_error.dart index fad5665..c355b28 100644 --- a/lib/widgets/dialog_fetch_error.dart +++ b/lib/widgets/dialog_fetch_error.dart @@ -16,11 +16,11 @@ class DialogFetchError extends StatelessWidget { 'La connexion internet est peut-être inaccessible.\n' 'Changer vers un mode de jeu hors-ligne ?'), actions: [ - FlatButton( + TextButton( child: const Text('REVENIR'), onPressed: () => Navigator.pop(context, false), ), - FlatButton( + TextButton( child: const Text('ACCEPTER'), onPressed: () => Navigator.pop(context, true), ), diff --git a/lib/widgets/dialog_gameover.dart b/lib/widgets/dialog_gameover.dart index 9925dee..e18de8d 100644 --- a/lib/widgets/dialog_gameover.dart +++ b/lib/widgets/dialog_gameover.dart @@ -38,13 +38,13 @@ class DialogGameOver extends StatelessWidget { ), ), actions: [ - FlatButton( + TextButton( child: const Text('QUITTER'), onPressed: () { Navigator.pushNamed(context, Home.id); }, ), - FlatButton( + TextButton( child: const Text('REJOUER'), onPressed: () async { _myProvider.resetSuccessAndErrors(); diff --git a/lib/widgets/letters.dart b/lib/widgets/letters.dart index 850dcf2..d3f45db 100644 --- a/lib/widgets/letters.dart +++ b/lib/widgets/letters.dart @@ -23,10 +23,12 @@ class LetterButtons extends StatelessWidget { keys.add( Padding( padding: const EdgeInsets.all(2.0), - child: RaisedButton( - disabledColor: Colors.grey, - disabledTextColor: Colors.white, - splashColor: Color(accent), + child: ElevatedButton( + style: ElevatedButton.styleFrom( + primary: Colors.grey, + onPrimary: Colors.white, + shadowColor: Color(accent), + ), onPressed: _myProvider.usedLetters.contains(key) ? null : () async { @@ -61,13 +63,13 @@ class LetterButtons extends StatelessWidget { key, textAlign: TextAlign.center, ), - color: Colors.grey[200], ), ), ); }); return Container( - alignment: orientation == Orientation.portrait ? Alignment.bottomCenter : Alignment.center, + alignment: + orientation == Orientation.portrait ? Alignment.bottomCenter : Alignment.center, color: Color(darkGreen), padding: EdgeInsets.all(10.0), margin: EdgeInsets.only(top: orientation == Orientation.portrait ? 0.0 : paddingTop), @@ -75,7 +77,8 @@ class LetterButtons extends StatelessWidget { padding: EdgeInsets.zero, shrinkWrap: true, crossAxisCount: orientation == Orientation.portrait ? 9 : 3, - childAspectRatio: orientation == Orientation.portrait ? 1 / 1 : (itemWidth / itemHeight), + childAspectRatio: + orientation == Orientation.portrait ? 1 / 1 : (itemWidth / itemHeight), children: keys, ), ); diff --git a/lib/widgets/my_app_bar.dart b/lib/widgets/my_app_bar.dart index 95ac8ec..7408094 100644 --- a/lib/widgets/my_app_bar.dart +++ b/lib/widgets/my_app_bar.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show SystemNavigator; -import 'package:provider/provider.dart'; -import '../provider/data.dart'; import '../screens/scores.dart'; class MyAppBar extends StatelessWidget implements PreferredSizeWidget { @@ -14,8 +12,6 @@ class MyAppBar extends StatelessWidget implements PreferredSizeWidget { @override Widget build(BuildContext context) { - Data _myProvider = Provider.of<Data>(context); - return AppBar( title: Text('Hangman'), automaticallyImplyLeading: false, @@ -27,7 +23,6 @@ class MyAppBar extends StatelessWidget implements PreferredSizeWidget { SystemNavigator.pop(); break; case 'Scores': - Scaffold.of(context).removeCurrentSnackBar(); Navigator.pushNamed(context, Scores.id); break; } diff --git a/pubspec.lock b/pubspec.lock index 89271c7..51ae67c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,7 +21,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" charcode: dependency: transitive description: @@ -42,7 +42,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" csslib: dependency: transitive description: @@ -63,21 +63,21 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" ffi: dependency: transitive description: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "2.0.1" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.1" + version: "6.1.2" flutter: dependency: "direct main" description: flutter @@ -120,14 +120,14 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.3" + version: "0.6.4" list_french_words: dependency: "direct main" description: name: list_french_words url: "https://pub.dartlang.org" source: hosted - version: "0.1.0+1" + version: "0.1.0+2" matcher: dependency: transitive description: @@ -135,6 +135,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.4" meta: dependency: transitive description: @@ -155,56 +162,56 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+2" + version: "2.1.7" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.4" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.5" + version: "2.1.0" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.11.0" + version: "1.11.1" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.1.2" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "4.2.1" + version: "4.2.4" provider: dependency: "direct main" description: @@ -218,42 +225,56 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.12+4" + version: "2.0.15" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.12" + shared_preferences_ios: + dependency: transitive + description: + name: shared_preferences_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.2+4" + version: "2.1.1" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+11" + version: "2.0.4" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.0" shared_preferences_web: dependency: transitive description: name: shared_preferences_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.2+7" + version: "2.0.4" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.2+3" + version: "2.1.1" sky_engine: dependency: transitive description: flutter @@ -265,7 +286,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -300,35 +321,35 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.4.9" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.2" win32: dependency: transitive description: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.7.0" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "0.2.0+1" sdks: - dart: ">=2.13.0 <3.0.0" - flutter: ">=1.20.0" + dart: ">=2.17.0 <3.0.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 00d79eb..9f1493d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ dependencies: flutter: sdk: flutter provider: ^4.3.2+3 - shared_preferences: ^0.5.12+4 + shared_preferences: ^2.0.6 html: ^0.14.0+4 http: ^0.12.2 diacritic: ^0.1.1 diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 6dc53c3..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:hangman/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - await tester.pumpWidget(Hangman()); - }); -} -- GitLab