From 4ad5c408c45e011024c1d56387bd724dbd8093fc Mon Sep 17 00:00:00 2001 From: doman Date: Sat, 29 Jul 2023 18:42:29 +0200 Subject: [PATCH] NOTIFICATION RUN --- lib/client.dart | 2 +- lib/login_screen.dart | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/client.dart b/lib/client.dart index 7b5476f..b055b14 100644 --- a/lib/client.dart +++ b/lib/client.dart @@ -72,7 +72,7 @@ class ApiClient { return jsonDecode(response.body); } - void login(String username, String password) async { + Future login(String username, String password) async { final headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json', diff --git a/lib/login_screen.dart b/lib/login_screen.dart index fa07eb1..4a2e838 100644 --- a/lib/login_screen.dart +++ b/lib/login_screen.dart @@ -21,13 +21,42 @@ class _LoginScreen extends State { super.dispose(); } + void showError(String message) + { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(message, textAlign: TextAlign.center), + backgroundColor: Theme.of(context).colorScheme.error, + ), + ); + } + + void showText(String text) + { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(text, textAlign: TextAlign.center), + backgroundColor: Theme.of(context).colorScheme.primary, + ), + ); + } + + void popMeDady() { + Navigator.pop(context); + } + // login client when button pressed void _login() async { - widget.apiClient.login( - usernameController.text, - passwordController.text, - ); - Navigator.pop(context); + try { + await widget.apiClient.login( + usernameController.text, + passwordController.text, + ); + showText("Logged in"); + popMeDady(); + } on Exception catch (e) { + showError(e.toString()); + } } @override @@ -35,7 +64,7 @@ class _LoginScreen extends State { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: const Text("ANALUJ"), + title: const Text("FOODER login"), ), body: Center( child: Container(