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