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

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

Resolve "Clean code"

Closes #13

See merge request !14
parents b5d89b8c 2a9b9efa
No related branches found
No related tags found
1 merge request!14Resolve "Clean code"
Pipeline #2944 passed
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.benoitharrault.memory">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="memory"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
......@@ -21,8 +16,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
......
package org.benoitharrault.memory
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
......@@ -2,5 +2,5 @@ org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
app.versionName=1.0.8
app.versionCode=9
app.versionName=1.0.10
app.versionCode=11
......@@ -5,15 +5,13 @@ int selectedIndex ;
bool selected = true;
int points = 0;
List<TileModel> myPairs = new List<TileModel>();
List<bool> clicked = new List<bool>();
List<TileModel> myPairs = [];
List<bool> clicked = [];
List<bool> getClicked() {
List<bool> yoClicked = new List<bool>();
List<TileModel> myairs = new List<TileModel>();
myairs = getPairs();
for(int i=0;i<myairs.length;i++){
List<bool> yoClicked = [];
List<TileModel> myPairs = getPairs();
for (int i = 0; i < myPairs.length; i++) {
yoClicked[i] = false;
}
......@@ -21,9 +19,7 @@ List<bool> getClicked(){
}
List<TileModel> getPairs() {
List<TileModel> pairs = new List<TileModel>();
List<TileModel> pairs = [];
TileModel tileModel = new TileModel();
//1
......@@ -53,6 +49,7 @@ List<TileModel> getPairs(){
pairs.add(tileModel);
pairs.add(tileModel);
tileModel = new TileModel();
//5
tileModel.setImageAssetPath("assets/panda.png");
tileModel.setIsSelected(false);
......@@ -79,15 +76,12 @@ List<TileModel> getPairs(){
tileModel.setIsSelected(false);
pairs.add(tileModel);
pairs.add(tileModel);
tileModel = new TileModel();
return pairs;
}
List<TileModel> getQuestionPairs() {
List<TileModel> pairs = new List<TileModel>();
List<TileModel> pairs = [];
TileModel tileModel = new TileModel();
//1
......@@ -117,6 +111,7 @@ List<TileModel> getQuestionPairs(){
pairs.add(tileModel);
pairs.add(tileModel);
tileModel = new TileModel();
//5
tileModel.setImageAssetPath("assets/question.png");
tileModel.setIsSelected(false);
......@@ -143,7 +138,6 @@ List<TileModel> getQuestionPairs(){
tileModel.setIsSelected(false);
pairs.add(tileModel);
pairs.add(tileModel);
tileModel = new TileModel();
return pairs;
}
......@@ -7,7 +7,6 @@ import 'package:memory/models/TileModel.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
......@@ -27,26 +26,22 @@ class Home extends StatefulWidget {
}
class _HomeState extends State<Home> {
List<TileModel> gridViewTiles = new List<TileModel>();
List<TileModel> questionPairs = new List<TileModel>();
List<TileModel> gridViewTiles = [];
List<TileModel> questionPairs = [];
@override
void initState() {
// TODO: implement initState
super.initState();
reStart();
}
void reStart() {
void reStart() {
myPairs = getPairs();
myPairs.shuffle();
gridViewTiles = myPairs;
Future.delayed(const Duration(seconds: 5), () {
// Here you can write your code
Future.delayed(const Duration(seconds: 3), () {
setState(() {
print("2 seconds done");
// Here you can write your code for open new view
questionPairs = getQuestionPairs();
gridViewTiles = questionPairs;
selected = false;
......@@ -54,7 +49,6 @@ class _HomeState extends State<Home> {
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
......@@ -67,31 +61,40 @@ class _HomeState extends State<Home> {
SizedBox(
height: 40,
),
points != 800 ? Column(
points != 800
? Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
"$points/800",
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w500),
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
Text(
"Points",
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w300),
fontSize: 14,
fontWeight: FontWeight.w300,
),
),
],
) : Container(),
)
: Container(),
SizedBox(
height: 20,
),
points != 800 ? GridView(
points != 800
? GridView(
shrinkWrap: true,
//physics: ClampingScrollPhysics(),
scrollDirection: Axis.vertical,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
mainAxisSpacing: 0.0, maxCrossAxisExtent: 100.0),
mainAxisSpacing: 0.0,
maxCrossAxisExtent: 100.0,
),
children: List.generate(gridViewTiles.length, (index) {
return Tile(
imagePathUrl: gridViewTiles[index].getImageAssetPath(),
......@@ -99,7 +102,8 @@ class _HomeState extends State<Home> {
parent: this,
);
}),
) : Container(
)
: Container(
child: Column(
children: <Widget>[
GestureDetector(
......@@ -117,16 +121,19 @@ class _HomeState extends State<Home> {
color: Colors.blue,
borderRadius: BorderRadius.circular(24),
),
child: Text("Replay", style: TextStyle(
child: Text(
"Replay",
style: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w500
),),
fontWeight: FontWeight.w500,
),
),
),
),
],
)
)
),
),
],
),
),
......@@ -135,12 +142,10 @@ class _HomeState extends State<Home> {
}
}
class Tile extends StatefulWidget {
String imagePathUrl;
int tileIndex;
_HomeState parent;
final String imagePathUrl;
final int tileIndex;
final _HomeState parent;
Tile({this.imagePathUrl, this.tileIndex, this.parent});
......@@ -162,7 +167,7 @@ class _TileState extends State<Tile> {
if (selectedTile == myPairs[widget.tileIndex].getImageAssetPath()) {
print("add point");
points = points + 100;
print(selectedTile + " thishis" + widget.imagePathUrl);
print(selectedTile + " -> " + widget.imagePathUrl);
TileModel tileModel = new TileModel();
print(widget.tileIndex);
......@@ -179,9 +184,7 @@ class _TileState extends State<Tile> {
selectedTile = "";
});
} else {
print(selectedTile +
" thishis " +
myPairs[widget.tileIndex].getImageAssetPath());
print(selectedTile + " -> " + myPairs[widget.tileIndex].getImageAssetPath());
print("wrong choice");
print(widget.tileIndex);
print(selectedIndex);
......
class TileModel {
String imageAssetPath;
bool isSelected;
......
......@@ -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"
cupertino_icons:
dependency: "direct main"
description:
......@@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
......@@ -74,6 +74,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:
......@@ -87,7 +94,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
sky_engine:
dependency: transitive
description: flutter
......@@ -99,7 +106,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:
......@@ -134,20 +141,13 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.2"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment