From c38e0e4c2a2b77068e07d67631b2119aaf20fdae Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:58:56 +0200 Subject: [PATCH 01/11] Edit code --- assets/environments.dev.json | 2 +- lib/main.dart | 4 ++-- lib/screens/new_citizen_screen.dart | 28 +++++++++++++++++----------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/assets/environments.dev.json b/assets/environments.dev.json index 4d1aad2fc..9ce560b11 100644 --- a/assets/environments.dev.json +++ b/assets/environments.dev.json @@ -1,5 +1,5 @@ { - "SERVER_HOST": "https://srv.giraf.cs.aau.dk/DEV/API", + "SERVER_HOST": "http://localhost:5000/", "DEBUG": true, "USERNAME": "Guardian-dev", "PASSWORD": "password2" diff --git a/lib/main.dart b/lib/main.dart index be5f73998..437fe9b8b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,7 +26,7 @@ void main() { * Use the "environments.local.json" for running against your local web-api * For IOS users: change the SERVER_HOST in the environment.local file to "http://localhost:5000" */ - environment.setFile('assets/environments.dev.json').whenComplete(() { + environment.setFile('assets/environments.local.json').whenComplete(() { _runApp(); }); } @@ -42,7 +42,7 @@ void _runApp() { runApp(MaterialApp( title: 'Weekplanner', theme: ThemeData(fontFamily: 'Quicksand'), - //debugShowCheckedModeBanner: false, + debugShowCheckedModeBanner: false, home: StreamBuilder( initialData: false, stream: di.get().loggedIn.where((bool currentState) => diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index 5515145f9..c193e8719 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -15,11 +15,17 @@ import 'package:weekplanner/widgets/giraf_button_widget.dart'; /// Role names for Weekplanner enum Roles { /// Guardian role - guardian, + guardian, /// Trustee role - trustee, - /// Citizen role - citizen } + trustee, + /// Citizen role + citizen } + +Map roleText = { + Roles.guardian: 'pædagog', + Roles.trustee: 'værge', + Roles.citizen: 'borger', +}; /// Screen for creating a new citizen // ignore: must_be_immutable @@ -120,7 +126,7 @@ class _NewCitizenScreenState extends State { Expanded( child: ListTile( key: const Key('guardianRadioButton'), - title: const Text('Guardian'), + title: const Text('Pædagog'), leading: Radio( value: Roles.guardian, groupValue: _role, @@ -137,7 +143,7 @@ class _NewCitizenScreenState extends State { Expanded( child: ListTile( key: const Key('trusteeRadioButton'), - title: const Text('Trustee'), + title: const Text('Værge'), leading: Radio( value: Roles.trustee, groupValue: _role, @@ -154,7 +160,7 @@ class _NewCitizenScreenState extends State { Expanded( child: ListTile( key: const Key('citizenRadioButton'), - title: const Text('Citizen'), + title: const Text('Borger'), leading: Radio( value: Roles.citizen, groupValue: _role, @@ -280,12 +286,12 @@ class _NewCitizenScreenState extends State { ); }), ), - const Padding( - padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16), + Padding( // edit + padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16), //child: Text('Profil billede af borger (valgfri):'), child: AutoSizeText( - 'Profil billede af borger (valgfri):', - style: TextStyle(fontSize: GirafFont.small), + 'Profil billede af ${roleText[_role]} (valgfri):', + style: const TextStyle(fontSize: GirafFont.small), ), ), From c36aa440482212f4253bad0dce8885b7b18544df Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:50:36 +0200 Subject: [PATCH 02/11] Delete assets/environments.dev.json --- assets/environments.dev.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 assets/environments.dev.json diff --git a/assets/environments.dev.json b/assets/environments.dev.json deleted file mode 100644 index 9ce560b11..000000000 --- a/assets/environments.dev.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "SERVER_HOST": "http://localhost:5000/", - "DEBUG": true, - "USERNAME": "Guardian-dev", - "PASSWORD": "password2" -} From 9dc2b72958558baf8a69f15f24db7961d6df2284 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:51:26 +0200 Subject: [PATCH 03/11] Delete lib/main.dart --- lib/main.dart | 91 --------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 lib/main.dart diff --git a/lib/main.dart b/lib/main.dart deleted file mode 100644 index 437fe9b8b..000000000 --- a/lib/main.dart +++ /dev/null @@ -1,91 +0,0 @@ -import 'package:api_client/api/api.dart'; -import 'package:api_client/models/displayname_model.dart'; -import 'package:api_client/models/enums/role_enum.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:weekplanner/blocs/auth_bloc.dart'; -import 'package:weekplanner/bootstrap.dart'; -import 'package:weekplanner/di.dart'; -import 'package:weekplanner/providers/environment_provider.dart' as environment; -import 'package:weekplanner/routes.dart'; -import 'package:weekplanner/screens/choose_citizen_screen.dart'; -import 'package:weekplanner/screens/login_screen.dart'; -import 'package:weekplanner/screens/weekplan_selector_screen.dart'; -import 'package:weekplanner/widgets/giraf_notify_dialog.dart'; - -final Api _api = di.get(); -final AuthBloc _authBloc = di.get(); - -void main() { - // Register all dependencies for injector - Bootstrap().register(); - WidgetsFlutterBinding.ensureInitialized(); - - /*** - * The weekplanner will by default run towards the dev-enviroment - * Use the "environments.local.json" for running against your local web-api - * For IOS users: change the SERVER_HOST in the environment.local file to "http://localhost:5000" - */ - environment.setFile('assets/environments.local.json').whenComplete(() { - _runApp(); - }); -} - -/// Stores the last state of being logged in -bool lastState = false; - -/// Stores if this is first time, -/// since this fixes a bug with logging in first time -bool firstTimeLogIn = true; - -void _runApp() { - runApp(MaterialApp( - title: 'Weekplanner', - theme: ThemeData(fontFamily: 'Quicksand'), - debugShowCheckedModeBanner: false, - home: StreamBuilder( - initialData: false, - stream: di.get().loggedIn.where((bool currentState) => - lastState != currentState || firstTimeLogIn), - builder: (BuildContext context, AsyncSnapshot snapshot) { - lastState = snapshot.data; - //To make sure we only listen to the stream once we take advantage - // of firstTimeLogin bool value - if(firstTimeLogIn== true){ - _api.connectivity.connectivityStream.listen((dynamic event) { - if(event == false){ - lostConnectionDialog(context); - } - }); - } - firstTimeLogIn = false; - if (snapshot.data) { - // Show screen dependent on logged in role - switch (_authBloc.loggedInUser.role) { - case Role.Citizen: - return WeekplanSelectorScreen( - DisplayNameModel( - displayName: _authBloc.loggedInUser.displayName, - role: describeEnum(_authBloc.loggedInUser.role), - id: _authBloc.loggedInUser.id)); - default: - return ChooseCitizenScreen(); - } - } else { - // Not loggedIn pop context to login screen. - Routes().goHome(context); - return LoginScreen(); - } - }))); -} - -/// Lost connection dialog -void lostConnectionDialog(BuildContext context) { - showDialog
( - context: context, - builder: (BuildContext context) { - return const GirafNotifyDialog( - title: 'Mistet forbindelse', - description: 'Ændringer bliver gemt når du får forbindelse igen'); - }); -} From 040fd574240623fde9e63d3488b489b8b7347beb Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:08:13 +0200 Subject: [PATCH 04/11] Addressing the 'Document and Type' Error --- lib/screens/new_citizen_screen.dart | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index c193e8719..b9ffda5d7 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -21,10 +21,12 @@ enum Roles { /// Citizen role citizen } -Map roleText = { - Roles.guardian: 'pædagog', - Roles.trustee: 'værge', - Roles.citizen: 'borger', +/// This map provides translations for different roles used in the application +/// from English to Danish. +final Map roleText = { + Roles.guardian: 'pædagog', // from Guardian to Pædagog + Roles.trustee: 'værge', // from Trustee to Værge + Roles.citizen: 'borger', // from Citizen to Borger }; /// Screen for creating a new citizen @@ -126,6 +128,8 @@ class _NewCitizenScreenState extends State { Expanded( child: ListTile( key: const Key('guardianRadioButton'), + // The title for the radio button, + // translated from 'Guardian' to 'Pædagog' title: const Text('Pædagog'), leading: Radio( value: Roles.guardian, @@ -143,6 +147,8 @@ class _NewCitizenScreenState extends State { Expanded( child: ListTile( key: const Key('trusteeRadioButton'), + // The title for the radio button, + // translated from 'Trustee' to 'Værge' title: const Text('Værge'), leading: Radio( value: Roles.trustee, @@ -160,6 +166,8 @@ class _NewCitizenScreenState extends State { Expanded( child: ListTile( key: const Key('citizenRadioButton'), + // The title for the radio button, + // translated from 'Citizen' to 'Borger' title: const Text('Borger'), leading: Radio( value: Roles.citizen, @@ -290,6 +298,9 @@ class _NewCitizenScreenState extends State { padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16), //child: Text('Profil billede af borger (valgfri):'), child: AutoSizeText( + // The text for displaying a profile picture based on + // the user's role. It dynamically includes the user's role, + // e.g., 'Pædagog', 'Værge', or 'Borger' 'Profil billede af ${roleText[_role]} (valgfri):', style: const TextStyle(fontSize: GirafFont.small), ), From cfbad31cf6dfd677e74bcb67abde54078eada8e7 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:25:57 +0200 Subject: [PATCH 05/11] Update new_citizen_screen.dart --- lib/screens/new_citizen_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index b9ffda5d7..c7ba902ca 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -23,7 +23,7 @@ enum Roles { /// This map provides translations for different roles used in the application /// from English to Danish. -final Map roleText = { +Map roleText = { Roles.guardian: 'pædagog', // from Guardian to Pædagog Roles.trustee: 'værge', // from Trustee to Værge Roles.citizen: 'borger', // from Citizen to Borger From 1e4b52add7f65cfc60bc10c0228d24bb10883545 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Thu, 26 Oct 2023 22:30:43 +0200 Subject: [PATCH 06/11] Update new_citizen_screen.dart --- lib/screens/new_citizen_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index c7ba902ca..b9ffda5d7 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -23,7 +23,7 @@ enum Roles { /// This map provides translations for different roles used in the application /// from English to Danish. -Map roleText = { +final Map roleText = { Roles.guardian: 'pædagog', // from Guardian to Pædagog Roles.trustee: 'værge', // from Trustee to Værge Roles.citizen: 'borger', // from Citizen to Borger From 9927c7066ab96cfe175bc19686196a0e88c84c14 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:32:50 +0200 Subject: [PATCH 07/11] Update new_citizen_screen.dart --- lib/screens/new_citizen_screen.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index b9ffda5d7..2be30b7ee 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -24,9 +24,9 @@ enum Roles { /// This map provides translations for different roles used in the application /// from English to Danish. final Map roleText = { - Roles.guardian: 'pædagog', // from Guardian to Pædagog - Roles.trustee: 'værge', // from Trustee to Værge - Roles.citizen: 'borger', // from Citizen to Borger + Roles.guardian: 'Pædagog', // from Guardian to Pædagog + Roles.trustee: 'Værge', // from Trustee to Værge + Roles.citizen: 'Borger', // from Citizen to Borger }; /// Screen for creating a new citizen From 1c69f90f6e37e596f5c02259bbee5e68af7d4f1e Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:36:17 +0200 Subject: [PATCH 08/11] Update new_citizen_screen.dart --- lib/screens/new_citizen_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index 2be30b7ee..6aac07ffb 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -23,7 +23,7 @@ enum Roles { /// This map provides translations for different roles used in the application /// from English to Danish. -final Map roleText = { +Map roleText = { Roles.guardian: 'Pædagog', // from Guardian to Pædagog Roles.trustee: 'Værge', // from Trustee to Værge Roles.citizen: 'Borger', // from Citizen to Borger From dfb36e89da32424a5047a6fc71e9c92619b49903 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:48:21 +0200 Subject: [PATCH 09/11] Update new_citizen_screen.dart --- lib/screens/new_citizen_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index 6aac07ffb..69b30bb51 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -23,7 +23,7 @@ enum Roles { /// This map provides translations for different roles used in the application /// from English to Danish. -Map roleText = { +Map roleText = { Roles.guardian: 'Pædagog', // from Guardian to Pædagog Roles.trustee: 'Værge', // from Trustee to Værge Roles.citizen: 'Borger', // from Citizen to Borger From f65b3e187b46102507717d4df57fbca6b84579d5 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:54:10 +0200 Subject: [PATCH 10/11] Update new_citizen_screen.dart --- lib/screens/new_citizen_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/new_citizen_screen.dart b/lib/screens/new_citizen_screen.dart index 69b30bb51..55e794eee 100644 --- a/lib/screens/new_citizen_screen.dart +++ b/lib/screens/new_citizen_screen.dart @@ -23,7 +23,7 @@ enum Roles { /// This map provides translations for different roles used in the application /// from English to Danish. -Map roleText = { +final Map roleText = { Roles.guardian: 'Pædagog', // from Guardian to Pædagog Roles.trustee: 'Værge', // from Trustee to Værge Roles.citizen: 'Borger', // from Citizen to Borger From 1103f5980f8b2be664c00b015118c41a198e21d6 Mon Sep 17 00:00:00 2001 From: Thuyhaile <95319419+Thuyhaile@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:37:28 +0100 Subject: [PATCH 11/11] update main and environments.dev.json --- assets/environments.dev.json | 6 +++ lib/main.dart | 91 ++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 assets/environments.dev.json create mode 100644 lib/main.dart diff --git a/assets/environments.dev.json b/assets/environments.dev.json new file mode 100644 index 000000000..9ce560b11 --- /dev/null +++ b/assets/environments.dev.json @@ -0,0 +1,6 @@ +{ + "SERVER_HOST": "http://localhost:5000/", + "DEBUG": true, + "USERNAME": "Guardian-dev", + "PASSWORD": "password2" +} diff --git a/lib/main.dart b/lib/main.dart new file mode 100644 index 000000000..d7994c0bd --- /dev/null +++ b/lib/main.dart @@ -0,0 +1,91 @@ +import 'package:api_client/api/api.dart'; +import 'package:api_client/models/displayname_model.dart'; +import 'package:api_client/models/enums/role_enum.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:weekplanner/blocs/auth_bloc.dart'; +import 'package:weekplanner/bootstrap.dart'; +import 'package:weekplanner/di.dart'; +import 'package:weekplanner/providers/environment_provider.dart' as environment; +import 'package:weekplanner/routes.dart'; +import 'package:weekplanner/screens/choose_citizen_screen.dart'; +import 'package:weekplanner/screens/login_screen.dart'; +import 'package:weekplanner/screens/weekplan_selector_screen.dart'; +import 'package:weekplanner/widgets/giraf_notify_dialog.dart'; + +final Api _api = di.get(); +final AuthBloc _authBloc = di.get(); + +void main() { + // Register all dependencies for injector + Bootstrap().register(); + WidgetsFlutterBinding.ensureInitialized(); + + /*** + * The weekplanner will by default run towards the dev-enviroment + * Use the "environments.local.json" for running against your local web-api + * For IOS users: change the SERVER_HOST in the environment.local file to "http://localhost:5000" + */ + environment.setFile('assets/environments.local.json').whenComplete(() { + _runApp(); + }); +} + +/// Stores the last state of being logged in +bool lastState = false; + +/// Stores if this is first time, +/// since this fixes a bug with logging in first time +bool firstTimeLogIn = true; + +void _runApp() { + runApp(MaterialApp( + title: 'Weekplanner', + theme: ThemeData(fontFamily: 'Quicksand'), + //debugShowCheckedModeBanner: false, + home: StreamBuilder( + initialData: false, + stream: di.get().loggedIn.where((bool currentState) => + lastState != currentState || firstTimeLogIn), + builder: (BuildContext context, AsyncSnapshot snapshot) { + lastState = snapshot.data; + //To make sure we only listen to the stream once we take advantage + // of firstTimeLogin bool value + if(firstTimeLogIn== true){ + _api.connectivity.connectivityStream.listen((dynamic event) { + if(event == false){ + lostConnectionDialog(context); + } + }); + } + firstTimeLogIn = false; + if (snapshot.data) { + // Show screen dependent on logged in role + switch (_authBloc.loggedInUser.role) { + case Role.Citizen: + return WeekplanSelectorScreen( + DisplayNameModel( + displayName: _authBloc.loggedInUser.displayName, + role: describeEnum(_authBloc.loggedInUser.role), + id: _authBloc.loggedInUser.id)); + default: + return ChooseCitizenScreen(); + } + } else { + // Not loggedIn pop context to login screen. + Routes().goHome(context); + return LoginScreen(); + } + }))); +} + +/// Lost connection dialog +void lostConnectionDialog(BuildContext context) { + showDialog
( + context: context, + builder: (BuildContext context) { + return const GirafNotifyDialog( + title: 'Mistet forbindelse', + description: 'Ændringer bliver gemt når du får forbindelse igen'); + }); +}