66 lines
2.5 KiB
Dart
66 lines
2.5 KiB
Dart
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:calorimeter/utils/app_drawer.dart';
|
|
import 'package:calorimeter/utils/settings_bloc.dart';
|
|
import 'package:settings_ui/settings_ui.dart';
|
|
|
|
class SettingsWidget extends StatefulWidget {
|
|
const SettingsWidget({super.key});
|
|
|
|
@override
|
|
State<SettingsWidget> createState() => _SettingsWidgetState();
|
|
}
|
|
|
|
class _SettingsWidgetState extends State<SettingsWidget> {
|
|
var kcalPerDayCtrl = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: BlocBuilder<SettingsDataBloc, SettingsState>(
|
|
builder: (context, state) {
|
|
return SettingsList(sections: [
|
|
SettingsSection(
|
|
title: const Text('Deine persönlichen Einstellungen'),
|
|
tiles: [
|
|
SettingsTile.navigation(
|
|
leading: const Icon(Icons.food_bank),
|
|
title: const Text('Kalorienlimit pro Tag'),
|
|
value: Text(state.kcalLimit.toString()),
|
|
onPressed: (context) async {
|
|
await showDialog(
|
|
builder: (ctx) {
|
|
return AlertDialog(
|
|
title: const Text("Kalorienlimit pro Tag"),
|
|
content: TextField(controller: kcalPerDayCtrl),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
double setting;
|
|
try {
|
|
setting =
|
|
double.parse(kcalPerDayCtrl.text);
|
|
} catch (e) {
|
|
setting = 2000.0;
|
|
}
|
|
context.read<SettingsDataBloc>().add(
|
|
DailyKcalLimitUpdated(kcal: setting));
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: const Text('Ok'))
|
|
],
|
|
);
|
|
},
|
|
context: context);
|
|
}),
|
|
],
|
|
),
|
|
]);
|
|
}),
|
|
drawer: const AppDrawer(),
|
|
appBar: AppBar(title: const Text('Einstellungen')),
|
|
);
|
|
}
|
|
}
|