Skip to content
Snippets Groups Projects
Commit fe490012 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Clean code, remove deprecations

parent fb352ab3
No related branches found
No related tags found
1 merge request!60Resolve "Clean code"
Pipeline #2903 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.1.24 app.versionName=0.1.25
app.versionCode=48 app.versionCode=49
...@@ -26,24 +26,27 @@ class MyApp extends StatelessWidget { ...@@ -26,24 +26,27 @@ class MyApp extends StatelessWidget {
), ),
home: Home(), home: Home(),
onGenerateRoute: (settings) { onGenerateRoute: (settings) {
final args = settings.arguments as Map<String, dynamic>;
switch (settings.name) { switch (settings.name) {
case '/game-pick-word': { case '/game-pick-word':
{
return MaterialPageRoute( return MaterialPageRoute(
builder: (context) => GamePickWordPage(), builder: (context) => GamePickWordPage(),
); );
} }
break; break;
case '/game-pick-image': { case '/game-pick-image':
{
return MaterialPageRoute( return MaterialPageRoute(
builder: (context) => GamePickImagePage(), builder: (context) => GamePickImagePage(),
); );
} }
break; break;
default: { print("Unknown menu entry"); } default:
{
print("Unknown menu entry");
}
break; break;
} }
......
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
class Data extends ChangeNotifier { class Data extends ChangeNotifier {
// Language // Language
String _lang = ''; String _lang = '';
// randomization // randomization
Map _word = null; Map _word;
List _otherWords = []; List _otherWords = [];
List _images = []; List _images = [];
final int _recentWordsCount = 20; final int _recentWordsCount = 20;
......
...@@ -5,8 +5,8 @@ import '../provider/data.dart'; ...@@ -5,8 +5,8 @@ import '../provider/data.dart';
import '../utils/random_pick_data.dart'; import '../utils/random_pick_data.dart';
class GamePickImagePage extends StatelessWidget { class GamePickImagePage extends StatelessWidget {
int _countWords = 4; final int _countWords = 4;
int _countImages = 1; final int _countImages = 1;
Future<void> startGame(Data myProvider, String lang) async { Future<void> startGame(Data myProvider, String lang) async {
await resetGame(myProvider); await resetGame(myProvider);
...@@ -44,11 +44,9 @@ class GamePickImagePage extends StatelessWidget { ...@@ -44,11 +44,9 @@ class GamePickImagePage extends StatelessWidget {
} }
attempts++; attempts++;
if ( if ((words != null) &&
(words != null) && (words.length == _countWords) (words.length == _countWords) &&
&& !myProvider.isRecentlyPicked(word['key'])) {
!myProvider.isRecentlyPicked(word['key'])
) {
myProvider.updateWord = word; myProvider.updateWord = word;
myProvider.updateImages = words; myProvider.updateImages = words;
} }
...@@ -130,18 +128,14 @@ class GamePickImagePage extends StatelessWidget { ...@@ -130,18 +128,14 @@ class GamePickImagePage extends StatelessWidget {
double imageSize = 130; double imageSize = 130;
String imageAsset = 'assets/placeholder.png'; String imageAsset = 'assets/placeholder.png';
if ( if ((word['images'] != null) &&
(word['images'] != null) (word['images'].length != 0) &&
&& (word['images'][0] != null)) {
(word['images'].length != 0)
&&
(word['images'][0] != null)
) {
imageAsset = 'assets/images/' + word['images'][0]; imageAsset = 'assets/images/' + word['images'][0];
} }
return Container( return Container(
child: FlatButton( child: TextButton(
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
...@@ -155,10 +149,12 @@ class GamePickImagePage extends StatelessWidget { ...@@ -155,10 +149,12 @@ class GamePickImagePage extends StatelessWidget {
image: AssetImage(imageAsset), image: AssetImage(imageAsset),
width: imageSize, width: imageSize,
height: imageSize, height: imageSize,
fit: BoxFit.fill fit: BoxFit.fill,
), ),
), ),
onPressed: () { checkWord(myProvider, word); }, onPressed: () {
checkWord(myProvider, word);
},
), ),
); );
} }
...@@ -217,8 +213,10 @@ class GamePickImagePage extends StatelessWidget { ...@@ -217,8 +213,10 @@ class GamePickImagePage extends StatelessWidget {
width: 6, width: 6,
), ),
), ),
child: RaisedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
word != null ? word[myProvider.lang] : '', word != null ? word[myProvider.lang] : '',
style: TextStyle( style: TextStyle(
...@@ -227,6 +225,7 @@ class GamePickImagePage extends StatelessWidget { ...@@ -227,6 +225,7 @@ class GamePickImagePage extends StatelessWidget {
color: Colors.white, color: Colors.white,
), ),
), ),
onPressed: null,
), ),
), ),
], ],
...@@ -239,9 +238,12 @@ class GamePickImagePage extends StatelessWidget { ...@@ -239,9 +238,12 @@ class GamePickImagePage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Container( Container(
child: RaisedButton( child: ElevatedButton(
color: Colors.teal, style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35), padding: EdgeInsets.all(35),
),
child: Text( child: Text(
"🇫🇷", "🇫🇷",
style: TextStyle( style: TextStyle(
...@@ -254,9 +256,12 @@ class GamePickImagePage extends StatelessWidget { ...@@ -254,9 +256,12 @@ class GamePickImagePage extends StatelessWidget {
), ),
SizedBox(height: 15), SizedBox(height: 15),
Container( Container(
child: RaisedButton( child: ElevatedButton(
color: Colors.teal, style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35), padding: EdgeInsets.all(35),
),
child: Text( child: Text(
"🇬🇧", "🇬🇧",
style: TextStyle( style: TextStyle(
...@@ -294,9 +299,9 @@ class GamePickImagePage extends StatelessWidget { ...@@ -294,9 +299,9 @@ class GamePickImagePage extends StatelessWidget {
children: <Widget>[ children: <Widget>[
_buildTextItemBlock(_myProvider), _buildTextItemBlock(_myProvider),
SizedBox(height: 2), SizedBox(height: 2),
((_myProvider.word == null) || (_myProvider.word['key'] == '')) ? ((_myProvider.word == null) || (_myProvider.word['key'] == ''))
_buildStartGameBlock(_myProvider) : ? _buildStartGameBlock(_myProvider)
_buildScoreContainer(_myProvider), : _buildScoreContainer(_myProvider),
SizedBox(height: 2), SizedBox(height: 2),
_buildImageItemsBlock(_myProvider), _buildImageItemsBlock(_myProvider),
], ],
...@@ -313,9 +318,9 @@ class GamePickImagePage extends StatelessWidget { ...@@ -313,9 +318,9 @@ class GamePickImagePage extends StatelessWidget {
height: (MediaQuery.of(context).size.height), height: (MediaQuery.of(context).size.height),
width: (MediaQuery.of(context).size.width), width: (MediaQuery.of(context).size.width),
child: pageContent, child: pageContent,
) ),
) ),
) ),
); );
} }
} }
...@@ -5,8 +5,8 @@ import '../provider/data.dart'; ...@@ -5,8 +5,8 @@ import '../provider/data.dart';
import '../utils/random_pick_data.dart'; import '../utils/random_pick_data.dart';
class GamePickWordPage extends StatelessWidget { class GamePickWordPage extends StatelessWidget {
int _countWords = 4; final int _countWords = 4;
int _countImages = 4; final int _countImages = 4;
Future<void> startGame(Data myProvider, String lang) async { Future<void> startGame(Data myProvider, String lang) async {
await resetGame(myProvider); await resetGame(myProvider);
...@@ -46,13 +46,9 @@ class GamePickWordPage extends StatelessWidget { ...@@ -46,13 +46,9 @@ class GamePickWordPage extends StatelessWidget {
} }
attempts++; attempts++;
if ( if (((words != null) && (words.length == _countWords)) &&
((words != null) && (words.length == _countWords)) ((images != null) && (images.length == _countImages)) &&
&& !myProvider.isRecentlyPicked(word['key'])) {
((images != null) && (images.length == _countImages))
&&
!myProvider.isRecentlyPicked(word['key'])
) {
myProvider.updateWord = word; myProvider.updateWord = word;
myProvider.updateOtherWords = words.skip(1).toList(); myProvider.updateOtherWords = words.skip(1).toList();
myProvider.updateImages = images; myProvider.updateImages = images;
...@@ -152,8 +148,7 @@ class GamePickWordPage extends StatelessWidget { ...@@ -152,8 +148,7 @@ class GamePickWordPage extends StatelessWidget {
image: AssetImage(imageAsset), image: AssetImage(imageAsset),
width: imageSize, width: imageSize,
height: imageSize, height: imageSize,
fit: BoxFit.fill fit: BoxFit.fill),
),
); );
} }
...@@ -197,8 +192,10 @@ class GamePickWordPage extends StatelessWidget { ...@@ -197,8 +192,10 @@ class GamePickWordPage extends StatelessWidget {
width: 6, width: 6,
), ),
), ),
child: FlatButton( child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
),
child: Text( child: Text(
word != null ? word[myProvider.lang] : '', word != null ? word[myProvider.lang] : '',
style: TextStyle( style: TextStyle(
...@@ -207,7 +204,9 @@ class GamePickWordPage extends StatelessWidget { ...@@ -207,7 +204,9 @@ class GamePickWordPage extends StatelessWidget {
color: Colors.white, color: Colors.white,
), ),
), ),
onPressed: () { checkWord(myProvider, word); }, onPressed: () {
checkWord(myProvider, word);
},
), ),
); );
} }
...@@ -262,9 +261,12 @@ class GamePickWordPage extends StatelessWidget { ...@@ -262,9 +261,12 @@ class GamePickWordPage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Container( Container(
child: RaisedButton( child: ElevatedButton(
color: Colors.teal, style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35), padding: EdgeInsets.all(35),
),
child: Text( child: Text(
"🇫🇷", "🇫🇷",
style: TextStyle( style: TextStyle(
...@@ -277,9 +279,12 @@ class GamePickWordPage extends StatelessWidget { ...@@ -277,9 +279,12 @@ class GamePickWordPage extends StatelessWidget {
), ),
SizedBox(height: 15), SizedBox(height: 15),
Container( Container(
child: RaisedButton( child: ElevatedButton(
color: Colors.teal, style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35), padding: EdgeInsets.all(35),
),
child: Text( child: Text(
"🇬🇧", "🇬🇧",
style: TextStyle( style: TextStyle(
...@@ -317,9 +322,9 @@ class GamePickWordPage extends StatelessWidget { ...@@ -317,9 +322,9 @@ class GamePickWordPage extends StatelessWidget {
children: <Widget>[ children: <Widget>[
_buildImageItemsBlock(_myProvider.images), _buildImageItemsBlock(_myProvider.images),
SizedBox(height: 2), SizedBox(height: 2),
((_myProvider.word == null) || (_myProvider.word['key'] == '')) ? ((_myProvider.word == null) || (_myProvider.word['key'] == ''))
_buildStartGameBlock(_myProvider) : ? _buildStartGameBlock(_myProvider)
_buildScoreContainer(_myProvider), : _buildScoreContainer(_myProvider),
SizedBox(height: 2), SizedBox(height: 2),
_buildTextItemsBlock(_myProvider), _buildTextItemsBlock(_myProvider),
], ],
...@@ -336,9 +341,9 @@ class GamePickWordPage extends StatelessWidget { ...@@ -336,9 +341,9 @@ class GamePickWordPage extends StatelessWidget {
height: (MediaQuery.of(context).size.height), height: (MediaQuery.of(context).size.height),
width: (MediaQuery.of(context).size.width), width: (MediaQuery.of(context).size.width),
child: pageContent, child: pageContent,
) ),
) ),
) ),
); );
} }
} }
...@@ -34,14 +34,17 @@ class Home extends StatelessWidget { ...@@ -34,14 +34,17 @@ class Home extends StatelessWidget {
width: 8, width: 8,
), ),
), ),
child: FlatButton( child: TextButton(
color: color, style: TextButton.styleFrom(
padding: EdgeInsets.all(15), padding: EdgeInsets.all(15),
primary: color,
backgroundColor: color,
),
child: Image( child: Image(
image: AssetImage(imageAsset), image: AssetImage(imageAsset),
width: imageSize, width: imageSize,
height: imageSize, height: imageSize,
fit: BoxFit.fill fit: BoxFit.fill,
), ),
onPressed: () { onPressed: () {
resetGame(_myProvider); resetGame(_myProvider);
...@@ -54,7 +57,6 @@ class Home extends StatelessWidget { ...@@ -54,7 +57,6 @@ class Home extends StatelessWidget {
); );
} }
return Scaffold( return Scaffold(
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
body: Center( body: Center(
......
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'random_pick_word.dart'; import 'random_pick_word.dart';
import 'random_pick_image.dart'; import 'random_pick_image.dart';
...@@ -11,11 +9,12 @@ class RandomPickData { ...@@ -11,11 +9,12 @@ class RandomPickData {
List _words; List _words;
init(String lang, int wordsCount, int imagesPerWordCount) async { init(String lang, int wordsCount, int imagesPerWordCount) async {
_words = new List(wordsCount); _words = List.filled(wordsCount, []);
await getWordsAndImages(lang, wordsCount, imagesPerWordCount); await getWordsAndImages(lang, wordsCount, imagesPerWordCount);
} }
Future<void> getWordsAndImages(String lang, int wordsCount, int imagesPerWordCount) async { Future<void> getWordsAndImages(
String lang, int wordsCount, int imagesPerWordCount) async {
RandomPickWord randomPickWord; RandomPickWord randomPickWord;
RandomPickImage randomPickImage; RandomPickImage randomPickImage;
......
...@@ -8,7 +8,7 @@ class RandomPickImage { ...@@ -8,7 +8,7 @@ class RandomPickImage {
List _images; List _images;
init(String word, int count) async { init(String word, int count) async {
_images = new List(count); _images = List.filled(count, []);
await imageFromLocalFile(word, count); await imageFromLocalFile(word, count);
} }
......
...@@ -8,7 +8,7 @@ class RandomPickWord { ...@@ -8,7 +8,7 @@ class RandomPickWord {
List _words; List _words;
init(String lang, int count) async { init(String lang, int count) async {
_words = new List(count); _words = List.filled(count, []);
await wordFromLocalFile(lang, count); await wordFromLocalFile(lang, count);
} }
...@@ -29,7 +29,7 @@ class RandomPickWord { ...@@ -29,7 +29,7 @@ class RandomPickWord {
_words = []; _words = [];
} else { } else {
// Remove empty words // Remove empty words
wordList.removeWhere((value) => ((value.containsKey(lang) == false) || (value[lang] == ''))); wordList.removeWhere((w) => ((w.containsKey(lang) == false) || (w[lang] == '')));
// Randomize words list // Randomize words list
wordList.shuffle(); wordList.shuffle();
......
...@@ -42,14 +42,14 @@ packages: ...@@ -42,14 +42,14 @@ packages:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" version: "1.16.0"
fake_async: fake_async:
dependency: transitive dependency: transitive
description: description:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -87,7 +87,7 @@ packages: ...@@ -87,7 +87,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
...@@ -108,7 +108,7 @@ packages: ...@@ -108,7 +108,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
provider: provider:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -127,7 +127,7 @@ packages: ...@@ -127,7 +127,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
...@@ -162,7 +162,7 @@ packages: ...@@ -162,7 +162,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.9"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
...@@ -176,7 +176,7 @@ packages: ...@@ -176,7 +176,7 @@ packages:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
sdks: sdks:
dart: ">=2.14.0 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.16.0" flutter: ">=1.16.0"
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wordguessing/main.dart';
void main() {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment