79 lines
2.2 KiB
Dart
79 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'core/api.dart';
|
|
|
|
class SettingsPage extends StatefulWidget {
|
|
const SettingsPage({super.key});
|
|
|
|
@override
|
|
State<SettingsPage> createState() => _SettingsPageState();
|
|
}
|
|
|
|
class _SettingsPageState extends State<SettingsPage> {
|
|
final TextEditingController _urlController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_saveData();
|
|
_urlController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadData();
|
|
}
|
|
|
|
Future<void> _saveData() async {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString('url', _urlController.text);
|
|
}
|
|
|
|
Future<void> _loadData() async {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
setState(() {
|
|
_urlController.text = prefs.getString('url') ?? '';
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Settings'),
|
|
),
|
|
body: ListView(
|
|
padding: const EdgeInsets.all(16.0),
|
|
children: <Widget>[
|
|
Text('LaserProxy URL', style: Theme.of(context).textTheme.titleLarge),
|
|
Text(
|
|
'Set the URL of the LaserProxy instance. Leave it blank to use the default.',
|
|
style: Theme.of(context).textTheme.bodyMedium
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _urlController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'URL',
|
|
hintText: 'https://laserscouter.halfheart.net/',
|
|
border: OutlineInputBorder(),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: Color.fromARGB(255, 19, 81, 179)),
|
|
),
|
|
),
|
|
onChanged: (value) {
|
|
if (value.isEmpty) {
|
|
proxyURL = "https://laserscouter.halfheart.net/";
|
|
}
|
|
else {
|
|
proxyURL = value;
|
|
}
|
|
}
|
|
),
|
|
const Divider(height: 32),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|