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 createState() => _SettingsPageState(); } class _SettingsPageState extends State { final TextEditingController _urlController = TextEditingController(); @override void dispose() { _saveData(); _urlController.dispose(); super.dispose(); } @override void initState() { super.initState(); _loadData(); } Future _saveData() async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString('url', _urlController.text); } Future _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: [ 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://laserproxy.halfheart.net/', border: OutlineInputBorder(), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Color.fromARGB(255, 19, 81, 179)), ), ), onChanged: (value) { if (value.isEmpty) { proxyURL = "https://laserproxy.halfheart.net/"; } else { proxyURL = value; } } ), const Divider(height: 32), ], ), ); } }