From 2a9b9efad0851ee6b8daacf8da265a27a94e1e3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Wed, 29 Jun 2022 16:12:59 +0200
Subject: [PATCH] Clean some code

---
 android/app/src/main/AndroidManifest.xml      |  11 +-
 .../org/benoitharrault/memory/MainActivity.kt |  12 --
 android/gradle.properties                     |   4 +-
 lib/data/data.dart                            |  32 ++--
 lib/main.dart                                 | 151 +++++++++---------
 lib/models/TileModel.dart                     |  13 +-
 pubspec.lock                                  |  30 ++--
 7 files changed, 115 insertions(+), 138 deletions(-)
 delete mode 100644 android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt

diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 3b7f203..2ca7b69 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,16 +1,11 @@
 <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" />
diff --git a/android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt b/android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt
deleted file mode 100644
index 840a08c..0000000
--- a/android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-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);
-    }
-}
diff --git a/android/gradle.properties b/android/gradle.properties
index cd725b5..6a4dd06 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -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
diff --git a/lib/data/data.dart b/lib/data/data.dart
index 3726f4f..dbdf036 100644
--- a/lib/data/data.dart
+++ b/lib/data/data.dart
@@ -1,29 +1,25 @@
 import 'package:memory/models/TileModel.dart';
 
 String selectedTile = "";
-int selectedIndex ;
+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> getClicked() {
+  List<bool> yoClicked = [];
+  List<TileModel> myPairs = getPairs();
+  for (int i = 0; i < myPairs.length; i++) {
     yoClicked[i] = false;
   }
 
   return yoClicked;
 }
 
-List<TileModel>  getPairs(){
-
-  List<TileModel> pairs = new List<TileModel>();
-
+List<TileModel> getPairs() {
+  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> getQuestionPairs() {
+  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;
 }
diff --git a/lib/main.dart b/lib/main.dart
index 257cd15..eb33f1f 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -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,66 +61,79 @@ class _HomeState extends State<Home> {
               SizedBox(
                 height: 40,
               ),
-              points != 800 ? Column(
-                crossAxisAlignment: CrossAxisAlignment.center,
-                children: <Widget>[
-                  Text(
-                    "$points/800",
-                    style: TextStyle(
-                        fontSize: 20, fontWeight: FontWeight.w500),
-                  ),
-                  Text(
-                    "Points",
-                    textAlign: TextAlign.start,
-                    style: TextStyle(
-                        fontSize: 14, fontWeight: FontWeight.w300),
-                  ),
-                ],
-              ) : Container(),
+              points != 800
+                  ? Column(
+                      crossAxisAlignment: CrossAxisAlignment.center,
+                      children: <Widget>[
+                        Text(
+                          "$points/800",
+                          style: TextStyle(
+                            fontSize: 20,
+                            fontWeight: FontWeight.w500,
+                          ),
+                        ),
+                        Text(
+                          "Points",
+                          textAlign: TextAlign.start,
+                          style: TextStyle(
+                            fontSize: 14,
+                            fontWeight: FontWeight.w300,
+                          ),
+                        ),
+                      ],
+                    )
+                  : Container(),
               SizedBox(
                 height: 20,
               ),
-              points != 800 ? GridView(
-                shrinkWrap: true,
-                //physics: ClampingScrollPhysics(),
-                scrollDirection: Axis.vertical,
-                gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
-                    mainAxisSpacing: 0.0, maxCrossAxisExtent: 100.0),
-                children: List.generate(gridViewTiles.length, (index) {
-                  return Tile(
-                    imagePathUrl: gridViewTiles[index].getImageAssetPath(),
-                    tileIndex: index,
-                    parent: this,
-                  );
-                }),
-              ) : Container(
-                child: Column(
-                  children: <Widget>[
-                    GestureDetector(
-                      onTap: (){
-                        setState(() {
-                          points = 0;
-                          reStart();
-                        });
-                      },
-                      child: Container(
-                        height: 50,
-                        width: 200,
-                        alignment: Alignment.center,
-                        decoration: BoxDecoration(
-                          color: Colors.blue,
-                          borderRadius: BorderRadius.circular(24),
-                        ),
-                        child: Text("Replay", style: TextStyle(
-                            color: Colors.white,
-                            fontSize: 17,
-                            fontWeight: FontWeight.w500
-                        ),),
+              points != 800
+                  ? GridView(
+                      shrinkWrap: true,
+                      //physics: ClampingScrollPhysics(),
+                      scrollDirection: Axis.vertical,
+                      gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
+                        mainAxisSpacing: 0.0,
+                        maxCrossAxisExtent: 100.0,
+                      ),
+                      children: List.generate(gridViewTiles.length, (index) {
+                        return Tile(
+                          imagePathUrl: gridViewTiles[index].getImageAssetPath(),
+                          tileIndex: index,
+                          parent: this,
+                        );
+                      }),
+                    )
+                  : Container(
+                      child: Column(
+                        children: <Widget>[
+                          GestureDetector(
+                            onTap: () {
+                              setState(() {
+                                points = 0;
+                                reStart();
+                              });
+                            },
+                            child: Container(
+                              height: 50,
+                              width: 200,
+                              alignment: Alignment.center,
+                              decoration: BoxDecoration(
+                                color: Colors.blue,
+                                borderRadius: BorderRadius.circular(24),
+                              ),
+                              child: Text(
+                                "Replay",
+                                style: TextStyle(
+                                  color: Colors.white,
+                                  fontSize: 17,
+                                  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);
diff --git a/lib/models/TileModel.dart b/lib/models/TileModel.dart
index 94fc7d3..4cf7435 100644
--- a/lib/models/TileModel.dart
+++ b/lib/models/TileModel.dart
@@ -1,23 +1,22 @@
-class TileModel{
-
+class TileModel {
   String imageAssetPath;
   bool isSelected;
 
   TileModel({this.imageAssetPath, this.isSelected});
 
-  void setImageAssetPath(String getImageAssetPath){
+  void setImageAssetPath(String getImageAssetPath) {
     imageAssetPath = getImageAssetPath;
   }
 
-  String getImageAssetPath(){
+  String getImageAssetPath() {
     return imageAssetPath;
   }
 
-  void setIsSelected(bool getIsSelected){
+  void setIsSelected(bool getIsSelected) {
     isSelected = getIsSelected;
   }
 
-  bool getIsSelected(){
+  bool getIsSelected() {
     return isSelected;
   }
-}
\ No newline at end of file
+}
diff --git a/pubspec.lock b/pubspec.lock
index 736fe5a..aece043 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"
   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"
-- 
GitLab