diff --git a/android/gradle.properties b/android/gradle.properties index 3e5bc11bf6886fca5fe136b2f4b5243b5fbdf633..d2167bacd126ac63d1d644795209d624ba2f1a4e 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.1.25 -app.versionCode=49 +app.versionName=0.1.26 +app.versionCode=50 diff --git a/lib/main.dart b/lib/main.dart index 60bfe3fde33d7b02d6ecb7fd73e4960bbb662b7b..8f745e27e7b60c2faec44aac9e5a6a0bf4b96bbf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -33,7 +33,6 @@ class MyApp extends StatelessWidget { builder: (context) => GamePickWordPage(), ); } - break; case '/game-pick-image': { @@ -41,7 +40,6 @@ class MyApp extends StatelessWidget { builder: (context) => GamePickImagePage(), ); } - break; default: { diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 42c833cc1efc2942071da4ed8404d8d72a018f5d..841c3a6d26316d7ecc35bfafc7e7b74a6270e8c3 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -5,7 +5,7 @@ class Data extends ChangeNotifier { String _lang = ''; // randomization - Map _word; + Map _word = {}; List _otherWords = []; List _images = []; final int _recentWordsCount = 20; @@ -27,7 +27,7 @@ class Data extends ChangeNotifier { set updateWord(Map value) { _word = value; - if (value != null && value['key'] != '') { + if (value.containsKey('key') && value['key'] != '') { _recentWords.insert(0, value['key']); _recentWords = _recentWords.take(_recentWordsCount).toList(); } @@ -53,7 +53,7 @@ class Data extends ChangeNotifier { } void resetGame() { - _word = null; + _word = {}; _otherWords = []; _images = []; _questionsCount = 0; diff --git a/lib/screens/game_pick_image.dart b/lib/screens/game_pick_image.dart index bf549de71bb307cbc251bf828601485eb49e5907..c7d7d3de823fa7c0cb5465eadc001892789cff6c 100644 --- a/lib/screens/game_pick_image.dart +++ b/lib/screens/game_pick_image.dart @@ -19,8 +19,8 @@ class GamePickImagePage extends StatelessWidget { myProvider.updateQuestionsCount = 0; myProvider.updateGoodAnswers = 0; myProvider.updateWrongAnswers = 0; - myProvider.updateWord = null; - myProvider.updateImages = null; + myProvider.updateWord = {}; + myProvider.updateImages = []; } Future<void> nextWord(Data myProvider) async { @@ -29,24 +29,22 @@ class GamePickImagePage extends StatelessWidget { } Future<void> pickData(Data myProvider) async { - List words; + List words = []; RandomPickData randomPickData; - Map word; + Map word = {}; int attempts = 0; do { randomPickData = RandomPickData(); await randomPickData.init(myProvider.lang, _countWords, _countImages); - if (randomPickData.words != null) { + if (randomPickData.words.isNotEmpty) { words = randomPickData.words; word = words.take(1).toList()[0]; } attempts++; - if ((words != null) && - (words.length == _countWords) && - !myProvider.isRecentlyPicked(word['key'])) { + if ((words.length == _countWords) && !myProvider.isRecentlyPicked(word['key'])) { myProvider.updateWord = word; myProvider.updateImages = words; } @@ -140,7 +138,7 @@ class GamePickImagePage extends StatelessWidget { decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), border: Border.all( - color: Colors.blue[200], + color: Colors.blue.shade200, width: 8, ), ), @@ -162,7 +160,7 @@ class GamePickImagePage extends StatelessWidget { Column _buildImageItemsBlock(Data myProvider) { List words = myProvider.images; - if ((words == null) || (words.length != _countWords)) { + if (words.length != _countWords) { return Column(); } @@ -195,7 +193,7 @@ class GamePickImagePage extends StatelessWidget { Column _buildTextItemBlock(Data myProvider) { Map word = myProvider.word; - if (word == null) { + if (word.isEmpty) { return Column(); } @@ -218,7 +216,7 @@ class GamePickImagePage extends StatelessWidget { padding: EdgeInsets.all(15), ), child: Text( - word != null ? word[myProvider.lang] : '', + word.containsKey(myProvider.lang) ? word[myProvider.lang] : '', style: TextStyle( fontSize: 30, fontWeight: FontWeight.w600, @@ -299,7 +297,7 @@ class GamePickImagePage extends StatelessWidget { children: <Widget>[ _buildTextItemBlock(_myProvider), SizedBox(height: 2), - ((_myProvider.word == null) || (_myProvider.word['key'] == '')) + ((!_myProvider.word.containsKey('key')) || (_myProvider.word['key'] == '')) ? _buildStartGameBlock(_myProvider) : _buildScoreContainer(_myProvider), SizedBox(height: 2), diff --git a/lib/screens/game_pick_word.dart b/lib/screens/game_pick_word.dart index 9b1aa6259d8f37e0ed7632af1d366896b6040536..df675f8331e9706c4a36f122a20a93ff12154e64 100644 --- a/lib/screens/game_pick_word.dart +++ b/lib/screens/game_pick_word.dart @@ -19,8 +19,8 @@ class GamePickWordPage extends StatelessWidget { myProvider.updateQuestionsCount = 0; myProvider.updateGoodAnswers = 0; myProvider.updateWrongAnswers = 0; - myProvider.updateWord = null; - myProvider.updateImages = null; + myProvider.updateWord = {}; + myProvider.updateImages = []; } Future<void> nextWord(Data myProvider) async { @@ -29,25 +29,25 @@ class GamePickWordPage extends StatelessWidget { } Future<void> pickData(Data myProvider) async { - List words; - List images; + List words = []; + List images = []; RandomPickData randomPickData; - Map word; + Map word = {}; int attempts = 0; do { randomPickData = RandomPickData(); await randomPickData.init(myProvider.lang, _countWords, _countImages); - if (randomPickData.words != null) { + if (randomPickData.words.isNotEmpty) { words = randomPickData.words; word = words.take(1).toList()[0]; images = word['images']; } attempts++; - if (((words != null) && (words.length == _countWords)) && - ((images != null) && (images.length == _countImages)) && + if ((words.length == _countWords) && + (images.length == _countImages) && !myProvider.isRecentlyPicked(word['key'])) { myProvider.updateWord = word; myProvider.updateOtherWords = words.skip(1).toList(); @@ -131,7 +131,7 @@ class GamePickWordPage extends StatelessWidget { double imageSize = 130; String imageAsset = 'assets/placeholder.png'; - if (image != null) { + if (image != '') { imageAsset = 'assets/images/' + image; } @@ -140,7 +140,7 @@ class GamePickWordPage extends StatelessWidget { decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), border: Border.all( - color: Colors.blue[200], + color: Colors.blue.shade200, width: 8, ), ), @@ -153,7 +153,7 @@ class GamePickWordPage extends StatelessWidget { } Column _buildImageItemsBlock(List images) { - if ((images == null) || (images.length != _countImages)) { + if (images.length != _countImages) { return Column(); } @@ -197,7 +197,7 @@ class GamePickWordPage extends StatelessWidget { padding: EdgeInsets.all(15), ), child: Text( - word != null ? word[myProvider.lang] : '', + word.containsKey(myProvider.lang) ? word[myProvider.lang] : '', style: TextStyle( fontSize: 20, fontWeight: FontWeight.w600, @@ -215,7 +215,7 @@ class GamePickWordPage extends StatelessWidget { Map word = myProvider.word; List otherWords = myProvider.otherWords; - if ((word == null) || (otherWords.length != (_countWords - 1))) { + if ((word.isEmpty) || (otherWords.length != (_countWords - 1))) { return Column(); } @@ -322,7 +322,7 @@ class GamePickWordPage extends StatelessWidget { children: <Widget>[ _buildImageItemsBlock(_myProvider.images), SizedBox(height: 2), - ((_myProvider.word == null) || (_myProvider.word['key'] == '')) + ((!_myProvider.word.containsKey('key')) || (_myProvider.word['key'] == '')) ? _buildStartGameBlock(_myProvider) : _buildScoreContainer(_myProvider), SizedBox(height: 2), diff --git a/lib/screens/home.dart b/lib/screens/home.dart index bfe6a848191f701365f304403b383d3ff24d573d..76cc8ad720856c94cbfbdf24d87fafbb72750dc9 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -11,9 +11,9 @@ class Home extends StatelessWidget { myProvider.updateQuestionsCount = 0; myProvider.updateGoodAnswers = 0; myProvider.updateWrongAnswers = 0; - myProvider.updateWord = null; - myProvider.updateOtherWords = null; - myProvider.updateImages = null; + myProvider.updateWord = {}; + myProvider.updateOtherWords = []; + myProvider.updateImages = []; } @override diff --git a/lib/utils/random_pick_data.dart b/lib/utils/random_pick_data.dart index 9a21081ee47ff486f9276f10fd0824ad91efafbf..3875f18c330db66bdfb27a702644c40be77973df 100644 --- a/lib/utils/random_pick_data.dart +++ b/lib/utils/random_pick_data.dart @@ -6,7 +6,7 @@ import 'random_pick_image.dart'; class RandomPickData { RandomPickData(); - List _words; + List _words = []; init(String lang, int wordsCount, int imagesPerWordCount) async { _words = List.filled(wordsCount, []); @@ -18,12 +18,12 @@ class RandomPickData { RandomPickWord randomPickWord; RandomPickImage randomPickImage; - List pickedWords; + List pickedWords = []; randomPickWord = RandomPickWord(); await randomPickWord.init(lang, wordsCount); - if (randomPickWord.words != null) { + if (randomPickWord.words.isNotEmpty) { pickedWords = randomPickWord.words; for (var i = 0; i < pickedWords.length; i++) { @@ -31,7 +31,7 @@ class RandomPickData { randomPickImage = RandomPickImage(); await randomPickImage.init(word['key'], imagesPerWordCount); - if (randomPickImage.images != null) { + if (randomPickImage.images.isNotEmpty) { pickedWords[i]['images'] = randomPickImage.images; } } diff --git a/lib/utils/random_pick_image.dart b/lib/utils/random_pick_image.dart index a726960814c96ff57bbee12b0c3584d85fd64202..cc156d1613ec75344916d71da46bc34c1180dfa4 100644 --- a/lib/utils/random_pick_image.dart +++ b/lib/utils/random_pick_image.dart @@ -5,7 +5,7 @@ import 'package:flutter/services.dart'; class RandomPickImage { RandomPickImage(); - List _images; + List _images = []; init(String word, int count) async { _images = List.filled(count, []); @@ -14,7 +14,8 @@ class RandomPickImage { Future<void> imageFromLocalFile(String word, int count) async { // Get all images for this word - List imageList; + List imageList = []; + try { String jsonString = await rootBundle.loadString('assets/assets_images.json'); final jsonResponse = await json.decode(jsonString); @@ -24,7 +25,7 @@ class RandomPickImage { } // Check we have enough images - if ((imageList == null) || (imageList.length < count)) { + if (imageList.length < count) { print('Not enough images in list for word "' + word + '".'); _images = []; } else { diff --git a/lib/utils/random_pick_word.dart b/lib/utils/random_pick_word.dart index eb4cfbc288184ba47eb0616516699566b4148ad6..4300e7e0232165f30b72d1480c255d9637091003 100644 --- a/lib/utils/random_pick_word.dart +++ b/lib/utils/random_pick_word.dart @@ -5,7 +5,7 @@ import 'package:flutter/services.dart'; class RandomPickWord { RandomPickWord(); - List _words; + List _words = []; init(String lang, int count) async { _words = List.filled(count, []); @@ -14,7 +14,8 @@ class RandomPickWord { Future<void> wordFromLocalFile(String lang, int count) async { // Get global words list - List wordList; + List wordList = []; + try { String jsonString = await rootBundle.loadString('assets/files/words.json'); final jsonResponse = await json.decode(jsonString); diff --git a/pubspec.lock b/pubspec.lock index 15e556479d9b9f1e6ac008fad7a2887fa424312c..5a0caee6c6f7b196767c20eb8d64e15f8fca7559 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -73,7 +73,7 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" matcher: dependency: transitive description: @@ -115,7 +115,7 @@ packages: name: provider url: "https://pub.dartlang.org" source: hosted - version: "6.0.2" + version: "6.0.3" sky_engine: dependency: transitive description: flutter @@ -169,7 +169,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6d45b4d20a35ce7da9cef83286da1c97a98819f5..ebed783389dcb7a4ae0df9ed10dce93a8e928f33 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.16.1 <3.0.0" dependencies: flutter: