switched to local git instance
This commit is contained in:
101
lib/settings.dart
Normal file
101
lib/settings.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class Settings extends StatefulWidget {
|
||||
const Settings({super.key});
|
||||
|
||||
@override
|
||||
State<Settings> createState() => _SettingsState();
|
||||
}
|
||||
|
||||
class _SettingsState extends State<Settings> {
|
||||
late Future<String> initName;
|
||||
late Future<String> initBLand;
|
||||
TextEditingController nameVornameC = TextEditingController();
|
||||
TextEditingController bLandC = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initName = _loadName();
|
||||
initBLand = _loadBLand();
|
||||
}
|
||||
|
||||
Future<String> _loadName() {
|
||||
Future<String> initName = Future.delayed(Duration.zero, () async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final String initName = prefs.getString('nameVorname') ?? '';
|
||||
nameVornameC.text = initName;
|
||||
return initName;
|
||||
});
|
||||
return initName;
|
||||
}
|
||||
|
||||
Future<String> _loadBLand() {
|
||||
Future<String> initBLand = Future.delayed(Duration.zero, () async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
final String initBLand = prefs.getString('bLand') ?? '';
|
||||
bLandC.text = initBLand;
|
||||
return initBLand;
|
||||
});
|
||||
return initBLand;
|
||||
}
|
||||
|
||||
void _saveName() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('nameVorname', nameVornameC.text);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(AppLocalizations.of(context)!.settings)),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(AppLocalizations.of(context)!.changenamestate ,style: const TextStyle(fontSize: 20, ),),
|
||||
FutureBuilder<String>(
|
||||
future: initName, // your Future<String>
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<String> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return TextField(
|
||||
controller: nameVornameC,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context)!.namevorname,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Optionally, return a placeholder widget while waiting
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
},
|
||||
),
|
||||
FutureBuilder<String>(
|
||||
future: initBLand,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return TextField(
|
||||
controller: bLandC,
|
||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.bland),
|
||||
);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.save),
|
||||
onPressed: () {
|
||||
_saveName();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user