Skip to content
Snippets Groups Projects
settings.dart 5.84 KiB
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SettingScreen extends StatelessWidget {
  const SettingScreen({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.pink,
        title: Text(
          "Einstellungen",
          style: TextStyle(fontSize: 25, color: Colors.white),
        ),
      ),
      body: Container(
        padding: EdgeInsets.all(8),
        child: ListView(
          children: [
            StandardSettingButton(xOffset: 150, title: "Kennwort", label: "",),
            StandardSettingButton(xOffset: 127, title: "Benutzername", label: ""),
            DropdownSettingButton()
          ],
        ),
      ),
    );
  }
}

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 = "Deggendorf";

  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){
              return ListTile(
                title: Text(currentCity,
                    style: TextStyle(fontSize: 22, color: Color.fromRGBO(
                        1, 1, 1, 0.49411764705882355))
                ),