import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/main.dart'; import 'package:flutter/material.dart'; class SetupPage extends StatefulWidget { const SetupPage({super.key}); @override State createState() => _SetupPageState(); } class _SetupPageState extends State { final TextEditingController _urlController = TextEditingController(); final TextEditingController _tokenController = TextEditingController(); Future _saveSettings() async { String instanceUrl = _urlController.text.trim(); String token = _tokenController.text.trim(); if (instanceUrl.isEmpty || token.isEmpty) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Please fill in all fields')), ); return; } API().save(instanceUrl, token); // Indicate that the setup is complete ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Setup Complete!')), ); await API().prefetch(); // Navigate or close the setup screen Navigator.pushReplacement( context, MaterialPageRoute( builder: (context) => const MyHomePage(), )); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Setup Page'), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ TextField( controller: _urlController, decoration: const InputDecoration(labelText: 'Instance URL'), keyboardType: TextInputType.url, ), const SizedBox(height: 16.0), TextField( controller: _tokenController, decoration: const InputDecoration(labelText: 'Token'), obscureText: true, ), const SizedBox(height: 32.0), ElevatedButton( onPressed: _saveSettings, child: const Text('Complete Setup'), ), ], ), ), ); } }