94 lines
No EOL
3 KiB
Dart
94 lines
No EOL
3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'remote_settings.dart';
|
|
|
|
class RemoteSettingsPage extends StatefulWidget {
|
|
const RemoteSettingsPage({super.key});
|
|
@override
|
|
State<RemoteSettingsPage> createState() => _RemoteSettingsPageState();
|
|
}
|
|
|
|
class _RemoteSettingsPageState extends State<RemoteSettingsPage> {
|
|
final _form = GlobalKey<FormState>();
|
|
bool _enabled = RemoteSettings.defaultEnabled;
|
|
final _baseUrl = TextEditingController(text: RemoteSettings.defaultBaseUrl);
|
|
final _indexPath = TextEditingController(text: RemoteSettings.defaultIndexPath);
|
|
final _email = TextEditingController();
|
|
final _password = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_load();
|
|
}
|
|
|
|
Future<void> _load() async {
|
|
final s = await RemoteSettings.load();
|
|
setState(() {
|
|
_enabled = s.enabled;
|
|
_baseUrl.text = s.baseUrl;
|
|
_indexPath.text = s.indexPath;
|
|
_email.text = s.email;
|
|
_password.text = s.password;
|
|
});
|
|
}
|
|
|
|
Future<void> _save() async {
|
|
if (!_form.currentState!.validate()) return;
|
|
final s = RemoteSettings(
|
|
enabled: _enabled,
|
|
baseUrl: _baseUrl.text.trim(),
|
|
indexPath: _indexPath.text.trim(),
|
|
email: _email.text.trim(),
|
|
password: _password.text,
|
|
);
|
|
await s.save();
|
|
if (!mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Impostazioni remote salvate')));
|
|
Navigator.of(context).maybePop();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Remote Settings')),
|
|
body: Form(
|
|
key: _form,
|
|
child: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
SwitchListTile(
|
|
title: const Text('Abilita sync remoto'),
|
|
value: _enabled,
|
|
onChanged: (v) => setState(() => _enabled = v),
|
|
),
|
|
TextFormField(
|
|
controller: _baseUrl,
|
|
decoration: const InputDecoration(labelText: 'Base URL (es. https://server.tld)'),
|
|
validator: (v) => (v==null || v.isEmpty) ? 'Obbligatorio' : null,
|
|
),
|
|
TextFormField(
|
|
controller: _indexPath,
|
|
decoration: const InputDecoration(labelText: 'Index path (es. photos/)'),
|
|
validator: (v) => (v==null || v.isEmpty) ? 'Obbligatorio' : null,
|
|
),
|
|
TextFormField(
|
|
controller: _email,
|
|
decoration: const InputDecoration(labelText: 'User/Email'),
|
|
),
|
|
TextFormField(
|
|
controller: _password,
|
|
obscureText: true,
|
|
decoration: const InputDecoration(labelText: 'Password'),
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedButton.icon(
|
|
onPressed: _save,
|
|
icon: const Icon(Icons.save),
|
|
label: const Text('Salva'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |