Browse Source

added person images

Eray Sönmez 11 months ago
parent
commit
3b7615e4a1

+ 2 - 0
android/app/build.gradle

@@ -43,6 +43,7 @@ android {
43 43
         targetSdkVersion 29
44 44
         versionCode flutterVersionCode.toInteger()
45 45
         versionName flutterVersionName
46
+        multiDexEnabled true
46 47
     }
47 48
 
48 49
     buildTypes {
@@ -60,4 +61,5 @@ flutter {
60 61
 
61 62
 dependencies {
62 63
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64
+    compile 'com.android.support:multidex:1.0.1'
63 65
 }

+ 1 - 1
android/gradle.properties

@@ -1,4 +1,4 @@
1 1
 org.gradle.jvmargs=-Xmx1536M
2 2
 android.useAndroidX=true
3 3
 android.enableJetifier=true
4
-android.enableR8=true
4
+android.enableR8=true

+ 3 - 1
android/gradle/wrapper/gradle-wrapper.properties

@@ -3,4 +3,6 @@ distributionBase=GRADLE_USER_HOME
3 3
 distributionPath=wrapper/dists
4 4
 zipStoreBase=GRADLE_USER_HOME
5 5
 zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
6
+# distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
7
+# distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
8
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

BIN
assets/images/default-avatar.png


BIN
assets/images/drake.jpg


+ 4 - 2
lib/models/person.dart

@@ -5,8 +5,9 @@ class Person {
5 5
   String lastname;
6 6
   int age;
7 7
   String gender;
8
+  String image;
8 9
 
9
-  Person(this.firstname, this.lastname, this.age, this.gender);
10
+  Person(this.firstname, this.lastname, this.age, this.gender, this.image);
10 11
 
11 12
   String toJson() {
12 13
     Map<String, dynamic> map = Map<String, dynamic>();
@@ -14,12 +15,13 @@ class Person {
14 15
     map['lastname'] = this.lastname;
15 16
     map['age'] = this.age;
16 17
     map['gender'] = this.gender;
18
+    map['image'] = this.image;
17 19
 
18 20
     return jsonEncode(map);
19 21
   }
20 22
 
21 23
   static Person fromJson(String json) {
22 24
     Map<String, dynamic> map = jsonDecode(json);
23
-    return Person(map['firstname'], map['lastname'], map['age'], map['gender']);
25
+    return Person(map['firstname'], map['lastname'], map['age'], map['gender'], map['image']);
24 26
   }
25 27
 }

+ 1 - 1
lib/personhinzufuegen.dart

@@ -11,7 +11,7 @@ class PersonHinzufuegen extends StatefulWidget {
11 11
 class PersonHinzufuegenState extends State<PersonHinzufuegen> {
12 12
   @override
13 13
   Widget build(BuildContext context) {
14
-    Person p = Person('', '', 0, '');
14
+    Person p = Person('', '', 0, '', '');
15 15
 
16 16
     return Scaffold(
17 17
         body: SafeArea(

+ 9 - 4
lib/startseite.dart

@@ -15,7 +15,7 @@ class _StartSeiteState extends State<StartSeite> {
15 15
   List<Person> generatedPersons = List<Person>();
16 16
 
17 17
   Future<String> fetchPerson() async {
18
-    final person = await http.get('https://randomname.de/?format=json&count=1');
18
+    final person = await http.get('https://randomname.de/?format=json&count=1&images=1');
19 19
     dynamic json = "";
20 20
     if (person != null) {
21 21
       if (person.statusCode == 200) {
@@ -72,10 +72,15 @@ class _StartSeiteState extends State<StartSeite> {
72 72
                     itemCount: generatedPersons.length,
73 73
                     itemBuilder: (BuildContext context, int index) {
74 74
                       String vorname = generatedPersons[index].firstname;
75
-                      return ListTile(title: Text(vorname), onTap: () => Navigator.pushNamed(context, PersonDetailsRoute, arguments: generatedPersons[index]));
75
+                      print(generatedPersons[index].toJson());
76
+                      return ListTile(
77
+                          leading: Network.isAvailable() ? Image.network(generatedPersons[index].image ?? '') : Image.asset("assets/images/default-avatar.png"),
78
+                          title: Text(vorname),
79
+                          onTap: () => Navigator.pushNamed(context, PersonDetailsRoute, arguments: generatedPersons[index]));
76 80
                     },
77 81
                   )),
78 82
             ),
83
+            Center(child: Container(child: Image.asset("assets/images/drake.jpg"))),
79 84
             Center(
80 85
                 child: RaisedButton(
81 86
                     color: Colors.black,
@@ -91,7 +96,7 @@ class _StartSeiteState extends State<StartSeite> {
91 96
                             await fetchPerson().then((value) async {
92 97
                               if (value.isNotEmpty) {
93 98
                                 var json = jsonDecode(value)[0];
94
-                                Person p = Person(json['firstname'], json['lastname'], json['age'], json['gender']);
99
+                                Person p = Person(json['firstname'], json['lastname'], json['age'], json['gender'], json['image']);
95 100
                                 SharedPreferences prefs = await _prefs;
96 101
                                 firstname = json['firstname'];
97 102
 
@@ -165,7 +170,7 @@ class _StartSeiteState extends State<StartSeite> {
165 170
             Center(
166 171
               child: RaisedButton(
167 172
                   onPressed: () async {
168
-                    bool result = await Navigator.pushNamed(context, PersonHinzufuegenRoute);
173
+                    bool result = await Navigator.pushNamed(context, PersonHinzufuegenRoute) ?? false;
169 174
                     if (result) {
170 175
                       setState(() {
171 176
                         printPreferences();

+ 2 - 4
lib/utils/network.dart

@@ -8,8 +8,6 @@ class Network {
8 8
     return _isAvailable;
9 9
   }
10 10
 
11
-  static StreamSubscription<ConnectivityResult> _streamSubscription;
12
-
13 11
   static Future<bool> isNetworkAvailable() async {
14 12
     var connectivityResult = await Connectivity().checkConnectivity();
15 13
     bool result = false;
@@ -24,14 +22,14 @@ class Network {
24 22
   static void init() async {
25 23
     await isNetworkAvailable();
26 24
 
27
-    Network._streamSubscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) async {
25
+    Connectivity().onConnectivityChanged.listen((ConnectivityResult result) async {
28 26
       print("Network changed!");
29 27
       return await isNetworkAvailable();
30 28
     });
31 29
   }
32 30
 
33 31
   static void registerSubscription(Function callback) {
34
-    StreamSubscription<ConnectivityResult> streamSubscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) async {
32
+    Connectivity().onConnectivityChanged.listen((ConnectivityResult result) async {
35 33
       print("Network changed!");
36 34
       callback();
37 35
     });

+ 2 - 0
pubspec.yaml

@@ -45,6 +45,8 @@ flutter:
45 45
   # the material Icons class.
46 46
   uses-material-design: true
47 47
 
48
+  assets:
49
+    - assets/images/
48 50
   # To add assets to your application, add an assets section, like this:
49 51
   # assets:
50 52
   #   - images/a_dot_burr.jpeg