Ideas to handle Multi User Application with Flutter

Kururu
2 min readDec 23, 2022

sometimes you may find yourself work on application which has multiple users, for example if you want to make one healthcare app for both patient and doctor. imagine if a user has two accounts one as doctor and another as patient. if he use one device . how can you handle this situation?

bellow few of the techniques that i came out with and i believe can help handle this situation.

Save user Token and Type on SharedPreferences:

use sharedPreferences package to save some metadata like user_id , token or use_type . these metadata will help in some logic in your app.

in your business logic classes you can get the shared preferences object and access to all saved data.

Restrict Access to certain Pages:

you can do this by many ways , fortunately , get package came with something called router guard or middle-ware you can access to specific pages depending on some logic for example allow specific user type to access the page

sample code :

class AuthGuard extends GetMiddleware {
// Get the auth service
final authService = Get.find<AuthService>();

// The default is 0 but you can update it to any number. Please ensure you match the priority based
// on the number of guards you have.
@override
int? get priority => 1;

@override
RouteSettings? redirect(String? route) {
// Navigate to login if client is not authenticated other wise continue
if (authService.isAuthenticated) return RouteSettings(name: AppLinks.LOGIN);
return RouteSettings(name: AppLinks.DASHBOARD);
}
}

see the full code in this article:

also you can build some logic in initState to decide if go to build or redirect user to somewhere:)

 void initState() {
super.initState();

SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
//here is your logic
if(currentUserType=="Doctor"){

Navigator.pop(context);

}





});
}

Handle Firebase Notifications:

basically, you can send Firebase notifications to users either by topic or device ids. if user log as patient and having deviceId and topic then decide to logout and log use doctor you have to make sure that he unsubscribe to all topics and remove his device id from backend database . by this you can insure use will not receive notifications on app after logged out. still he can receive notifications on his email or SMS .

that’s all ideas i remember , please list in the comment bellow any idea that can help on build multi user applications ❤️

thanks for reading ❤️

Sign up to discover human stories that deepen your understanding of the world.

Kururu
Kururu

Written by Kururu

Android | Flutter | Data Analytics

No responses yet

Write a response