From 6fae83674b5136ba74d6d316c15018eaf241ad67 Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Sun, 30 Jul 2023 19:26:56 -0600 Subject: [PATCH] Added internet permission and better message from api call --- android/app/src/main/AndroidManifest.xml | 4 +++- lib/features/account/login.dart | 17 ++++++++++++----- lib/features/account/signup.dart | 16 ++++++++++++---- .../settings/screens/settings_screen.dart | 6 +++--- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 1f536ef..4fe2cdf 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,8 @@ - + + diff --git a/lib/features/account/login.dart b/lib/features/account/login.dart index bc834b2..35d475b 100644 --- a/lib/features/account/login.dart +++ b/lib/features/account/login.dart @@ -217,14 +217,21 @@ class _LoginState extends ConsumerState { 'password': passwordController.text, }); - final bool success = data?['success'] ?? false; + String message = 'Login unsuccessful'; + bool success = data?['success'] == 'false'; + if (data != null) { + if (data['message'] != null) { + message = data['message']; + } else if (success) { + message = 'Logged in!'; + } + } + // final bool success = data?['success'] ?? false; + printAmber(data); showSnack( ref: ref, - text: data?['message'] ?? success - ? 'Login successful' - : 'Login unsuccessful', + text: message, type: !success ? SnackType.error : SnackType.success); - printAmber(data); } catch (err, st) { printRed('Error in login: $err\n$st'); } diff --git a/lib/features/account/signup.dart b/lib/features/account/signup.dart index b7075fa..5024d51 100644 --- a/lib/features/account/signup.dart +++ b/lib/features/account/signup.dart @@ -89,7 +89,8 @@ class _SignupState extends ConsumerState { } return null; }, - text: 'Email: (optional)', + text: 'Email:', + subtext: '(optional)', index: 2), generateTextField( controller: passwordController, @@ -169,6 +170,7 @@ class _SignupState extends ConsumerState { Widget generateTextField({ required String text, + String? subtext, String? label, required int index, required TextEditingController controller, @@ -182,9 +184,15 @@ class _SignupState extends ConsumerState { children: [ Padding( padding: const EdgeInsets.all(8.0), - child: Text( - text, - style: TextStyle(fontSize: size.width < 350 ? 16 : 20), + child: Column( + children: [ + Text( + text, + style: TextStyle(fontSize: size.width < 350 ? 16 : 20), + ), + if (subtext != null) + Text(subtext, style: const TextStyle(fontSize: 12)), + ], ), ), const Spacer(), diff --git a/lib/features/settings/screens/settings_screen.dart b/lib/features/settings/screens/settings_screen.dart index 4a1ff5d..f88dbb1 100644 --- a/lib/features/settings/screens/settings_screen.dart +++ b/lib/features/settings/screens/settings_screen.dart @@ -21,9 +21,9 @@ class _SettingsScreenState extends ConsumerState { children: [ const Text('Settings'), const SizedBox(height: 20), - Text(user!.name), - Text("Username: ${user.username ?? 'N/A'}"), - Text("Email: ${user.email ?? 'N/A'}"), + Text(user?.name ?? 'N/A'), + Text("Username: ${user?.username ?? 'N/A'}"), + Text("Email: ${user?.email ?? 'N/A'}"), Text("Family Code: ${family?.code ?? 'N/A'}"), const Spacer(), UiButton(