Skip to content

Commit

Permalink
✨ Enter base url manually
Browse files Browse the repository at this point in the history
  • Loading branch information
LNA-DEV committed Nov 1, 2024
1 parent 3f3ce37 commit a4e4c8b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MyApp extends StatelessWidget {
),
useMaterial3: true,
),
home: const LoginView(widget: Gallery()),
home: LoginView(widget: const Gallery()),
);
}
}
61 changes: 47 additions & 14 deletions lib/views/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<FormState> _formKey = GlobalKey<FormState>();
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"),
),
],
),
),
);
}
Expand All @@ -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,
),
),
);
}
}

0 comments on commit a4e4c8b

Please sign in to comment.