From 17d9a8ad3abfc70de1f70731da9713cd78987dc1 Mon Sep 17 00:00:00 2001
From: Anager <fridrich1900@gmail.com>
Date: Mon, 4 Apr 2022 20:03:31 +0200
Subject: [PATCH] settings architecture

---
 .../settings/dropdownbutton.dart              |  92 +++++++++
 .../settings/settings.dart                    | 184 +-----------------
 .../settings/standardsettingbutton.dart       |  91 +++++++++
 3 files changed, 187 insertions(+), 180 deletions(-)
 create mode 100644 lib/bottom_navigation_bar_buttons/settings/dropdownbutton.dart
 create mode 100644 lib/bottom_navigation_bar_buttons/settings/standardsettingbutton.dart

diff --git a/lib/bottom_navigation_bar_buttons/settings/dropdownbutton.dart b/lib/bottom_navigation_bar_buttons/settings/dropdownbutton.dart
new file mode 100644
index 0000000..88e967c
--- /dev/null
+++ b/lib/bottom_navigation_bar_buttons/settings/dropdownbutton.dart
@@ -0,0 +1,92 @@
+import 'package:flutter/material.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+
+
+class DropdownSettingButton extends StatefulWidget {
+  const DropdownSettingButton({Key? key}) : super(key: key);
+
+  @override
+  State<DropdownSettingButton> createState() => _DropdownSettingButtonState();
+}
+
+class _DropdownSettingButtonState extends State<DropdownSettingButton> {
+  bool _expanded = false;
+  String currentCity = "Die aktuelle Stadt ändern";
+
+  String getCurrentCity(){
+    getCurrentCityFromSharedPreferences();
+    return currentCity;
+  }
+
+  getCurrentCityFromSharedPreferences() async {
+    SharedPreferences prefs = await SharedPreferences.getInstance();
+    String val = prefs.getString('currentCity') ?? "Not Selected";
+    currentCity = val;
+  }
+
+  setCurrentCityInSharedPreferences(String newCity) async{
+    SharedPreferences prefs = await SharedPreferences.getInstance();
+    prefs.setString('currentCity', newCity);
+  }
+
+
+  @override
+  Widget build(BuildContext context) {
+    return ExpansionPanelList(
+      animationDuration: Duration(microseconds: 2000),
+      children:[
+        ExpansionPanel(
+            canTapOnHeader: true,
+            isExpanded: _expanded,
+            headerBuilder: (context, isExpanded){
+              String city = getCurrentCity();
+              return ListTile(
+                title: Text(city,
+                    style: TextStyle(fontSize: 20, color: Color.fromRGBO(
+                        1, 1, 1, 0.5))
+                ),
+              );
+            },
+            body: Column(
+              children: <Widget> [
+                TextButton(
+                    onPressed: (){
+                      setCurrentCityInSharedPreferences("Deggendorf");
+                      _expanded = false;
+                      getCurrentCityFromSharedPreferences();
+                      setState(() {
+                      });
+                    },
+                    child: Text(
+                      "Deggendorf",
+                      style: TextStyle(fontSize: 20, color: Color.fromRGBO(
+                          1, 1, 1, 0.5)),
+                    )
+                ),
+                TextButton(
+                    onPressed: (){
+                      setCurrentCityInSharedPreferences("Plattling");
+                      _expanded = false;
+                      getCurrentCityFromSharedPreferences();
+                      setState(() {
+                      });
+                    },
+                    child: Text(
+                      "Plattling",
+                      style: TextStyle(fontSize: 20, color: Color.fromRGBO(
+                          1, 1, 1, 0.5)),
+                    )
+                ),
+              ],
+            )
+        )
+      ],
+      expansionCallback: (panelIndex, isExpanded){
+        _expanded = !_expanded;
+        setState(() {
+
+        });
+      },
+    );
+  }
+}
\ No newline at end of file
diff --git a/lib/bottom_navigation_bar_buttons/settings/settings.dart b/lib/bottom_navigation_bar_buttons/settings/settings.dart
index 6fc32e8..ec998f5 100644
--- a/lib/bottom_navigation_bar_buttons/settings/settings.dart
+++ b/lib/bottom_navigation_bar_buttons/settings/settings.dart
@@ -1,7 +1,10 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
-import 'package:shared_preferences/shared_preferences.dart';
+
+import 'package:deggendorf_app/bottom_navigation_bar_buttons/settings/dropdownbutton.dart';
+import 'package:deggendorf_app/bottom_navigation_bar_buttons/settings/standardsettingbutton.dart';
+
 
 class SettingScreen extends StatelessWidget {
   const SettingScreen({Key? key}) : super(key: key);
@@ -30,182 +33,3 @@ class SettingScreen extends StatelessWidget {
     );
   }
 }
-
-class DropdownSettingButton extends StatefulWidget {
-  const DropdownSettingButton({Key? key}) : super(key: key);
-
-  @override
-  State<DropdownSettingButton> createState() => _DropdownSettingButtonState();
-}
-
-class _DropdownSettingButtonState extends State<DropdownSettingButton> {
-  bool _expanded = false;
-  String currentCity = "Die aktuelle Stadt";
-
-  String getCurrentCity(){
-    getCurrentCityFromSharedPreferences();
-    return currentCity;
-  }
-
-  getCurrentCityFromSharedPreferences() async {
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    String val = prefs.getString('currentCity') ?? "Not Selected";
-    currentCity = val;
-  }
-
-  setCurrentCityInSharedPreferences(String newCity) async{
-    SharedPreferences prefs = await SharedPreferences.getInstance();
-    prefs.setString('currentCity', newCity);
-  }
-
-
-  @override
-  Widget build(BuildContext context) {
-    return ExpansionPanelList(
-      animationDuration: Duration(microseconds: 2000),
-      children:[
-        ExpansionPanel(
-            canTapOnHeader: true,
-            isExpanded: _expanded,
-            headerBuilder: (context, isExpanded){
-              String city = getCurrentCity();
-              return ListTile(
-                title: Text(city,
-                    style: TextStyle(fontSize: 20, color: Color.fromRGBO(
-                        1, 1, 1, 0.5))
-                ),
-              );
-            },
-            body: Column(
-              children: <Widget> [
-                TextButton(
-                    onPressed: (){
-                      setCurrentCityInSharedPreferences("Deggendorf");
-                      _expanded = false;
-                      getCurrentCityFromSharedPreferences();
-                      setState(() {
-                      });
-                    },
-                    child: Text(
-                      "Deggendorf",
-                      style: TextStyle(fontSize: 20, color: Color.fromRGBO(
-                        1, 1, 1, 0.5)),
-                    )
-                ),
-                TextButton(
-                    onPressed: (){
-                      setCurrentCityInSharedPreferences("Plattling");
-                      _expanded = false;
-                      getCurrentCityFromSharedPreferences();
-                      setState(() {
-                      });
-                    },
-                    child: Text(
-                      "Plattling",
-                      style: TextStyle(fontSize: 20, color: Color.fromRGBO(
-                        1, 1, 1, 0.5)),
-                    )
-                ),
-              ],
-            )
-        )
-      ],
-      expansionCallback: (panelIndex, isExpanded){
-        _expanded = !_expanded;
-        setState(() {
-
-        });
-      },
-    );
-  }
-}
-
-
-class StandardSettingButton extends StatefulWidget {
-  const StandardSettingButton({Key? key,
-    required this.xOffset,
-    required this.title,
-    required this.label
-  }) : super(key: key);
-
-  final double xOffset;
-  final String title;
-  final String label;
-
-  @override
-  State<StandardSettingButton> createState() => _StandardSettingButtonState();
-}
-
-class _StandardSettingButtonState extends State<StandardSettingButton> {
-
-  bool isPassword(){
-    if (widget.title == "Kennwort"){
-      return true;
-    }
-    return false;
-  }
-
-  @override
-  Widget build(BuildContext context) {
-    return TextButton(
-        onPressed: (){
-          showDialog(
-            context: context,
-            builder: (context) => AlertDialog(
-              title: Text(
-                "Wollen Sie ${widget.title} ändern?",
-                style: TextStyle(
-                    fontSize: 16
-                ),
-              ),
-              content: TextField(
-                obscureText: isPassword() ,
-                decoration: InputDecoration(
-                    hintText: "geben Sie ${widget.title} ein"
-                ),
-              ),
-              actions: [
-                TextButton(
-                    onPressed: (){Navigator.pop(context);},
-                    child: Text("ändern")
-                ),
-                TextButton(
-                    onPressed: (){
-                      Navigator.pop(context);
-                    },
-                    child: Text("abbrechen")
-                )
-              ],
-            ),
-          );
-        },
-        child: Row(
-          children: <Widget>[
-            Column(
-              crossAxisAlignment: CrossAxisAlignment.start,
-              children: [
-                Text(
-                  widget.title,
-                  style: TextStyle(fontSize: 25, color: Color.fromRGBO(
-                      1, 1, 1, 0.5)),
-                ),
-                Text(
-                  "drücken um das ${widget.title} zu ändern",
-                  style: TextStyle(fontSize: 10, color: Color.fromRGBO(
-                      1, 1, 1, 0.37)),
-                )
-              ],
-            ),
-            SizedBox(
-              width: widget.xOffset,
-            ),
-            Icon(
-              Icons.keyboard_arrow_right_rounded,
-              color: Color.fromRGBO(1, 1, 1, 0.5),
-              size: 40,
-            )
-          ],
-        )
-    );
-  }
-}
diff --git a/lib/bottom_navigation_bar_buttons/settings/standardsettingbutton.dart b/lib/bottom_navigation_bar_buttons/settings/standardsettingbutton.dart
new file mode 100644
index 0000000..42e7af7
--- /dev/null
+++ b/lib/bottom_navigation_bar_buttons/settings/standardsettingbutton.dart
@@ -0,0 +1,91 @@
+import 'package:flutter/material.dart';
+
+
+class StandardSettingButton extends StatefulWidget {
+  const StandardSettingButton({Key? key,
+    required this.xOffset,
+    required this.title,
+    required this.label
+  }) : super(key: key);
+
+  final double xOffset;
+  final String title;
+  final String label;
+
+  @override
+  State<StandardSettingButton> createState() => _StandardSettingButtonState();
+}
+
+class _StandardSettingButtonState extends State<StandardSettingButton> {
+
+  bool isPassword(){
+    if (widget.title == "Kennwort"){
+      return true;
+    }
+    return false;
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return TextButton(
+        onPressed: (){
+          showDialog(
+            context: context,
+            builder: (context) => AlertDialog(
+              title: Text(
+                "Wollen Sie ${widget.title} ändern?",
+                style: TextStyle(
+                    fontSize: 16
+                ),
+              ),
+              content: TextField(
+                obscureText: isPassword() ,
+                decoration: InputDecoration(
+                    hintText: "geben Sie ${widget.title} ein"
+                ),
+              ),
+              actions: [
+                TextButton(
+                    onPressed: (){Navigator.pop(context);},
+                    child: Text("ändern")
+                ),
+                TextButton(
+                    onPressed: (){
+                      Navigator.pop(context);
+                    },
+                    child: Text("abbrechen")
+                )
+              ],
+            ),
+          );
+        },
+        child: Row(
+          children: <Widget>[
+            Column(
+              crossAxisAlignment: CrossAxisAlignment.start,
+              children: [
+                Text(
+                  widget.title,
+                  style: TextStyle(fontSize: 25, color: Color.fromRGBO(
+                      1, 1, 1, 0.5)),
+                ),
+                Text(
+                  "drücken um das ${widget.title} zu ändern",
+                  style: TextStyle(fontSize: 10, color: Color.fromRGBO(
+                      1, 1, 1, 0.37)),
+                )
+              ],
+            ),
+            SizedBox(
+              width: widget.xOffset,
+            ),
+            Icon(
+              Icons.keyboard_arrow_right_rounded,
+              color: Color.fromRGBO(1, 1, 1, 0.5),
+              size: 40,
+            )
+          ],
+        )
+    );
+  }
+}
\ No newline at end of file
-- 
GitLab