diff --git a/lib/main.dart b/lib/main.dart index f728fe7..2d85049 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -42,7 +42,7 @@ class MyApp extends StatelessWidget { ), useMaterial3: true, ), - home: const LoginView(widget: Gallery()), + home: LoginView(widget: const Gallery()), ); } } diff --git a/lib/views/login.dart b/lib/views/login.dart index 4661a64..2e8c11e 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -5,31 +5,50 @@ import 'package:open_media_server_app/globals/globals.dart'; import 'package:open_media_server_app/helpers/preferences.dart'; class LoginView extends StatelessWidget { - const LoginView({super.key, required this.widget}); + LoginView({super.key, required this.widget}); final Widget widget; + final GlobalKey _formKey = GlobalKey(); + final domainController = TextEditingController(); + @override Widget build(BuildContext context) { - Preferences.prefs!.setString("BaseUrl", ""); - return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).scaffoldBackgroundColor, surfaceTintColor: Colors.transparent, title: Text(Globals.Title), ), - body: FutureBuilder( - future: authenticate(context), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center(child: CircularProgressIndicator()); - } else if (snapshot.hasError) { - return Center(child: Text('Error: ${snapshot.error}')); - } - - return widget; - }, + body: Form( + key: _formKey, + child: Column( + children: [ + TextFormField( + controller: domainController, + decoration: const InputDecoration( + hintText: 'Domain', + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return 'Please enter some text'; + } + return null; + }, + ), + ElevatedButton( + onPressed: () async { + if (_formKey.currentState!.validate()) { + Preferences.prefs! + .setString("BaseUrl", domainController.text); + + authenticate(context); + } + }, + child: const Text("Submit"), + ), + ], + ), ), ); } @@ -41,5 +60,19 @@ class LoginView extends StatelessWidget { LoginManager loginManager = LoginManager(info); var token = await loginManager.login(info, context); + + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (context) => Scaffold( + appBar: AppBar( + backgroundColor: Theme.of(context).scaffoldBackgroundColor, + surfaceTintColor: Colors.transparent, + title: Text(Globals.Title), + ), + body: widget, + ), + ), + ); } }