Skip to content
Snippets Groups Projects
Commit a486be5e authored by Anager's avatar Anager
Browse files

added shared preferences

parent dea9d537
No related branches found
No related tags found
1 merge request!2Home page chaitanya
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(
......@@ -40,12 +42,15 @@ class _DropdownSettingButtonState extends State<DropdownSettingButton> {
bool _expanded = false;
String currentCity = "Deggendorf";
void setCurrentCity(bool isDeg){
if (isDeg){
currentCity = "Deggendorf";
}else{
currentCity = "Plattling";
}
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);
}
......@@ -55,44 +60,46 @@ class _DropdownSettingButtonState extends State<DropdownSettingButton> {
animationDuration: Duration(microseconds: 2000),
children:[
ExpansionPanel(
canTapOnHeader: true,
isExpanded: _expanded,
headerBuilder: (context, isExpanded){
return ListTile(
title: Text("Aktuelle Stadt: ${currentCity}",
style: TextStyle(fontSize: 22, color: Color.fromRGBO(
1, 1, 1, 0.49411764705882355))
),
);
},
body: Column(
children: <Widget> [
TextButton(
onPressed: (){
setCurrentCity(true);
_expanded = false;
setState(() {
});
},
child: Text(
"Deggendorf", style: TextStyle(fontSize: 20, color: Color.fromRGBO(
1, 1, 1, 0.49411764705882355)),
)
),
TextButton(
onPressed: (){
setCurrentCity(false);
_expanded = false;
setState(() {
});
},
child: Text(
"Plattling", style: TextStyle(fontSize: 20, color: Color.fromRGBO(
1, 1, 1, 0.49411764705882355)),
)
),
],
)
canTapOnHeader: true,
isExpanded: _expanded,
headerBuilder: (context, isExpanded){
return ListTile(
title: Text(currentCity,
style: TextStyle(fontSize: 22, color: Color.fromRGBO(
1, 1, 1, 0.49411764705882355))
),
);
},
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.49411764705882355)),
)
),
TextButton(
onPressed: (){
setCurrentCityInSharedPreferences("Plattling");
_expanded = false;
getCurrentCityFromSharedPreferences();
setState(() {
});
},
child: Text(
"Plattling", style: TextStyle(fontSize: 20, color: Color.fromRGBO(
1, 1, 1, 0.49411764705882355)),
)
),
],
)
)
],
expansionCallback: (panelIndex, isExpanded){
......
......@@ -269,7 +269,7 @@ packages:
source: hosted
version: "5.0.0"
shared_preferences:
dependency: transitive
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
......
......@@ -37,6 +37,7 @@ dependencies:
cupertino_icons: ^1.0.4
http: ^0.13.4
flutter_settings_screens: ^0.2.2+1
shared_preferences: ^2.0.13
dev_dependencies:
flutter_test:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment