cdb_ui/lib/pages/setup.dart

76 lines
2.1 KiB
Dart
Raw Permalink Normal View History

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