DietaryGuard/lib/screens/settings.dart

71 lines
1.8 KiB
Dart
Raw Normal View History

2024-08-14 17:26:42 +00:00
import 'package:dietary_guard/controllers/food_data.dart';
2024-08-14 15:43:21 +00:00
import 'package:flutter/material.dart';
2024-08-14 17:26:42 +00:00
import 'package:get/get.dart';
2024-08-14 15:43:21 +00:00
2024-08-14 17:26:42 +00:00
class SettingsScreen extends StatefulWidget {
2024-08-14 15:43:21 +00:00
const SettingsScreen({super.key});
2024-08-14 17:26:42 +00:00
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
final TextEditingController _fdcApiKeyController = TextEditingController();
Future<void> _applySettings() async {
final FoodDataController data = Get.find();
await data.setApiKey(_fdcApiKeyController.text);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('settingsApplied'.tr),
));
}
@override
void initState() {
final FoodDataController data = Get.find();
_fdcApiKeyController.text = data.getApiKey() ?? '';
super.initState();
}
@override
void dispose() {
_fdcApiKeyController.dispose();
super.dispose();
}
2024-08-14 15:43:21 +00:00
@override
Widget build(BuildContext context) {
2024-08-14 17:26:42 +00:00
return Scaffold(
appBar: AppBar(
title: Text('settings'.tr),
),
body: ListView(
children: [
const SizedBox(height: 8),
TextField(
controller: _fdcApiKeyController,
obscureText: true,
decoration: const InputDecoration(
border: OutlineInputBorder(),
label: Text("FDC API Key"),
isDense: true,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton.icon(
icon: const Icon(Icons.save, size: 16),
label: Text('apply'.tr),
onPressed: () => _applySettings(),
),
],
).paddingSymmetric(vertical: 12),
],
).paddingSymmetric(horizontal: 24),
);
2024-08-14 15:43:21 +00:00
}
}