import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'core/api.dart'; import 'login.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), ElevatedButton( onPressed: () { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: const Text('Reset All Data'), content: const Text('Are you sure you want to reset all data?'), actions: [ ElevatedButton( onPressed: () async { SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.clear(); Navigator.pop(context); Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => const LoginPage(), ), ); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.red, textStyle: const TextStyle(color: Colors.white), ), child: const Text('Yes'), ), ElevatedButton( onPressed: () { Navigator.pop(context); }, child: const Text('No'), ), ] ); } ); }, child: const Text('Reset All Data'), ), ], ), ); } }