139 lines
4.0 KiB
Dart
Raw Permalink Normal View History

2025-01-09 21:44:43 +01:00
import 'package:covas_mobile/classes/MyDrawer.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
import 'dart:io';
import '../classes/MyDrawer.dart';
import '../classes/alert.dart';
import '../classes/eventAdded.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: EditSettings(),
);
}
}
class EditSettings extends StatefulWidget {
const EditSettings({super.key});
@override
_EditProfileState createState() => _EditProfileState();
}
class _EditProfileState extends State<EditSettings>
with ShowAlertDialog, ShowEventDialog {
TextEditingController inputUserName = TextEditingController();
2025-01-09 22:13:20 +01:00
int? kilometer;
Future<void> getParameter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
2025-01-09 23:27:22 +01:00
setState(() {
var kilometer = prefs.getDouble("kilometer")?.toInt() ?? null;
});
}
2025-01-09 22:13:20 +01:00
2025-01-09 23:27:22 +01:00
Future<void> setParameter() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
2025-01-09 22:13:20 +01:00
if (kilometer != null) {
2025-01-09 23:27:22 +01:00
prefs.setDouble("kilometer", kilometer?.toDouble() ?? 50);
showAlertDialog(context, "Update", "Mise à jour des paramètres");
2025-01-09 22:13:20 +01:00
}
}
2025-01-09 21:44:43 +01:00
@override
void initState() {
super.initState();
2025-01-09 22:13:20 +01:00
getParameter();
2025-01-09 21:44:43 +01:00
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
2025-01-09 21:48:24 +01:00
title: Text("Settings"),
2025-01-09 21:44:43 +01:00
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
drawer: MyDrawer(),
body: Form(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
2025-01-09 22:13:20 +01:00
left: 15.0,
right: 15.0,
top: 15.0,
bottom: 0.0,
),
child: DropdownButtonFormField<int>(
2025-01-09 21:44:43 +01:00
decoration: InputDecoration(
2025-01-09 22:13:20 +01:00
border: OutlineInputBorder(),
labelText: 'Define kilometer',
),
value:
kilometer, // Set the initial selected value here, or leave as `null` if unselected.
items: [
DropdownMenuItem(
value: 5,
child: Text('5km'),
),
DropdownMenuItem(
value: 25,
child: Text('25km'),
),
DropdownMenuItem(
value: 50,
child: Text('50km'),
),
DropdownMenuItem(
value: 75,
child: Text('75km'),
),
DropdownMenuItem(
value: 100,
child: Text('100km'),
),
],
onChanged: (int? newValue) {
// Handle selection
kilometer = newValue;
},
2025-01-09 21:44:43 +01:00
),
),
SizedBox(
height: 30,
),
Container(
height: 50,
width: 250,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(20)),
child: TextButton(
2025-01-09 21:48:24 +01:00
onPressed: () {},
2025-01-09 21:44:43 +01:00
child: Text(
2025-01-09 21:48:24 +01:00
'Mettre à jour les paramètres',
2025-01-09 21:44:43 +01:00
style: TextStyle(color: Colors.white, fontSize: 25),
),
),
)
],
),
),
));
}
}