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

Merge branch '57-clean-code' into 'master'

Resolve "Clean code"

Closes #57

See merge request !60
parents fb352ab3 fe490012
Branches
Tags Release_0.1.25_49
1 merge request!60Resolve "Clean code"
Pipeline #2906 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.1.24
app.versionCode=48
app.versionName=0.1.25
app.versionCode=49
......@@ -26,24 +26,27 @@ class MyApp extends StatelessWidget {
),
home: Home(),
onGenerateRoute: (settings) {
final args = settings.arguments as Map<String, dynamic>;
switch (settings.name) {
case '/game-pick-word': {
case '/game-pick-word':
{
return MaterialPageRoute(
builder: (context) => GamePickWordPage(),
);
}
break;
case '/game-pick-image': {
case '/game-pick-image':
{
return MaterialPageRoute(
builder: (context) => GamePickImagePage(),
);
}
break;
default: { print("Unknown menu entry"); }
default:
{
print("Unknown menu entry");
}
break;
}
......
import 'package:flutter/foundation.dart';
class Data extends ChangeNotifier {
// Language
String _lang = '';
// randomization
Map _word = null;
Map _word;
List _otherWords = [];
List _images = [];
final int _recentWordsCount = 20;
......
......@@ -5,8 +5,8 @@ import '../provider/data.dart';
import '../utils/random_pick_data.dart';
class GamePickImagePage extends StatelessWidget {
int _countWords = 4;
int _countImages = 1;
final int _countWords = 4;
final int _countImages = 1;
Future<void> startGame(Data myProvider, String lang) async {
await resetGame(myProvider);
......@@ -44,11 +44,9 @@ class GamePickImagePage extends StatelessWidget {
}
attempts++;
if (
(words != null) && (words.length == _countWords)
&&
!myProvider.isRecentlyPicked(word['key'])
) {
if ((words != null) &&
(words.length == _countWords) &&
!myProvider.isRecentlyPicked(word['key'])) {
myProvider.updateWord = word;
myProvider.updateImages = words;
}
......@@ -130,18 +128,14 @@ class GamePickImagePage extends StatelessWidget {
double imageSize = 130;
String imageAsset = 'assets/placeholder.png';
if (
(word['images'] != null)
&&
(word['images'].length != 0)
&&
(word['images'][0] != null)
) {
if ((word['images'] != null) &&
(word['images'].length != 0) &&
(word['images'][0] != null)) {
imageAsset = 'assets/images/' + word['images'][0];
}
return Container(
child: FlatButton(
child: TextButton(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
......@@ -155,10 +149,12 @@ class GamePickImagePage extends StatelessWidget {
image: AssetImage(imageAsset),
width: 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 {
width: 6,
),
),
child: RaisedButton(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.all(15),
),
child: Text(
word != null ? word[myProvider.lang] : '',
style: TextStyle(
......@@ -227,6 +225,7 @@ class GamePickImagePage extends StatelessWidget {
color: Colors.white,
),
),
onPressed: null,
),
),
],
......@@ -239,9 +238,12 @@ class GamePickImagePage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: RaisedButton(
color: Colors.teal,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35),
),
child: Text(
"🇫🇷",
style: TextStyle(
......@@ -254,9 +256,12 @@ class GamePickImagePage extends StatelessWidget {
),
SizedBox(height: 15),
Container(
child: RaisedButton(
color: Colors.teal,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35),
),
child: Text(
"🇬🇧",
style: TextStyle(
......@@ -294,9 +299,9 @@ class GamePickImagePage extends StatelessWidget {
children: <Widget>[
_buildTextItemBlock(_myProvider),
SizedBox(height: 2),
((_myProvider.word == null) || (_myProvider.word['key'] == '')) ?
_buildStartGameBlock(_myProvider) :
_buildScoreContainer(_myProvider),
((_myProvider.word == null) || (_myProvider.word['key'] == ''))
? _buildStartGameBlock(_myProvider)
: _buildScoreContainer(_myProvider),
SizedBox(height: 2),
_buildImageItemsBlock(_myProvider),
],
......@@ -313,9 +318,9 @@ class GamePickImagePage extends StatelessWidget {
height: (MediaQuery.of(context).size.height),
width: (MediaQuery.of(context).size.width),
child: pageContent,
)
)
)
),
),
),
);
}
}
......@@ -5,8 +5,8 @@ import '../provider/data.dart';
import '../utils/random_pick_data.dart';
class GamePickWordPage extends StatelessWidget {
int _countWords = 4;
int _countImages = 4;
final int _countWords = 4;
final int _countImages = 4;
Future<void> startGame(Data myProvider, String lang) async {
await resetGame(myProvider);
......@@ -46,13 +46,9 @@ class GamePickWordPage extends StatelessWidget {
}
attempts++;
if (
((words != null) && (words.length == _countWords))
&&
((images != null) && (images.length == _countImages))
&&
!myProvider.isRecentlyPicked(word['key'])
) {
if (((words != null) && (words.length == _countWords)) &&
((images != null) && (images.length == _countImages)) &&
!myProvider.isRecentlyPicked(word['key'])) {
myProvider.updateWord = word;
myProvider.updateOtherWords = words.skip(1).toList();
myProvider.updateImages = images;
......@@ -152,8 +148,7 @@ class GamePickWordPage extends StatelessWidget {
image: AssetImage(imageAsset),
width: imageSize,
height: imageSize,
fit: BoxFit.fill
),
fit: BoxFit.fill),
);
}
......@@ -197,8 +192,10 @@ class GamePickWordPage extends StatelessWidget {
width: 6,
),
),
child: FlatButton(
child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(15),
),
child: Text(
word != null ? word[myProvider.lang] : '',
style: TextStyle(
......@@ -207,7 +204,9 @@ class GamePickWordPage extends StatelessWidget {
color: Colors.white,
),
),
onPressed: () { checkWord(myProvider, word); },
onPressed: () {
checkWord(myProvider, word);
},
),
);
}
......@@ -262,9 +261,12 @@ class GamePickWordPage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: RaisedButton(
color: Colors.teal,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35),
),
child: Text(
"🇫🇷",
style: TextStyle(
......@@ -277,9 +279,12 @@ class GamePickWordPage extends StatelessWidget {
),
SizedBox(height: 15),
Container(
child: RaisedButton(
color: Colors.teal,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.teal,
primary: Colors.teal,
padding: EdgeInsets.all(35),
),
child: Text(
"🇬🇧",
style: TextStyle(
......@@ -317,9 +322,9 @@ class GamePickWordPage extends StatelessWidget {
children: <Widget>[
_buildImageItemsBlock(_myProvider.images),
SizedBox(height: 2),
((_myProvider.word == null) || (_myProvider.word['key'] == '')) ?
_buildStartGameBlock(_myProvider) :
_buildScoreContainer(_myProvider),
((_myProvider.word == null) || (_myProvider.word['key'] == ''))
? _buildStartGameBlock(_myProvider)
: _buildScoreContainer(_myProvider),
SizedBox(height: 2),
_buildTextItemsBlock(_myProvider),
],
......@@ -336,9 +341,9 @@ class GamePickWordPage extends StatelessWidget {
height: (MediaQuery.of(context).size.height),
width: (MediaQuery.of(context).size.width),
child: pageContent,
)
)
)
),
),
),
);
}
}
......@@ -34,14 +34,17 @@ class Home extends StatelessWidget {
width: 8,
),
),
child: FlatButton(
color: color,
child: TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(15),
primary: color,
backgroundColor: color,
),
child: Image(
image: AssetImage(imageAsset),
width: imageSize,
height: imageSize,
fit: BoxFit.fill
fit: BoxFit.fill,
),
onPressed: () {
resetGame(_myProvider);
......@@ -54,7 +57,6 @@ class Home extends StatelessWidget {
);
}
return Scaffold(
backgroundColor: Colors.blue,
body: Center(
......
import 'dart:async';
import 'dart:convert';
import 'package:flutter/services.dart';
import 'random_pick_word.dart';
import 'random_pick_image.dart';
......@@ -11,11 +9,12 @@ class RandomPickData {
List _words;
init(String lang, int wordsCount, int imagesPerWordCount) async {
_words = new List(wordsCount);
_words = List.filled(wordsCount, []);
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;
RandomPickImage randomPickImage;
......
......@@ -8,7 +8,7 @@ class RandomPickImage {
List _images;
init(String word, int count) async {
_images = new List(count);
_images = List.filled(count, []);
await imageFromLocalFile(word, count);
}
......
......@@ -8,7 +8,7 @@ class RandomPickWord {
List _words;
init(String lang, int count) async {
_words = new List(count);
_words = List.filled(count, []);
await wordFromLocalFile(lang, count);
}
......@@ -29,7 +29,7 @@ class RandomPickWord {
_words = [];
} else {
// Remove empty words
wordList.removeWhere((value) => ((value.containsKey(lang) == false) || (value[lang] == '')));
wordList.removeWhere((w) => ((w.containsKey(lang) == false) || (w[lang] == '')));
// Randomize words list
wordList.shuffle();
......
......@@ -42,14 +42,14 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
......@@ -87,7 +87,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
......@@ -108,7 +108,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
provider:
dependency: "direct main"
description:
......@@ -127,7 +127,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:
......@@ -162,7 +162,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
typed_data:
dependency: transitive
description:
......@@ -176,7 +176,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.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