71 lines
1.8 KiB
Dart
71 lines
1.8 KiB
Dart
import 'package:dietary_guard/controllers/food_data.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
|
const SettingsScreen({super.key});
|
|
|
|
@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();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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),
|
|
);
|
|
}
|
|
}
|