authentication_provider

Creator: coderz1093

Last updated:

0 purchases

authentication_provider Image
authentication_provider Images

Languages

Categories

Add to Cart

Description:

authentication provider

Authentication Provider #
This Widget is modeled after the provider package but specifically for the authentication workflow.
Example #
class _MyAppState extends State<MyApp> {
AuthenticationController controller;

@override
void initState() {
super.initState();
controller = AuthenticationController<User>(context);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: AuthenticationProvider<User>(
controller: controller,
builder: (context) {
var state = AuthenticationProvider.of<User>(context).state;
if (state is AuthState.Loading) {
return Scaffold(
appBar: AppBar(
title: const Text('Loading'),
),
body: Center(
child: CircularProgressIndicator(),
),
);
} else if (state is AuthState.Unauthenticated) {
return Scaffold(
appBar: AppBar(
title: const Text('Unauthenticated'),
),
body: Center(
child: Column(children: [
Text('Woops, you are not authenticated.'),
FlatButton(
child: Text('Sign In'),
onPressed: () => controller.authenticate(user: User()),
)
]),
),
);
} else if (state is AuthState.Authenticated<User>) {
return Scaffold(
appBar: AppBar(
title: const Text('Authenticated'),
),
body: Center(
child: Column(children: [
Text(
'Congratulations, you (${state.user.name}) are authenticated.'),
FlatButton(
child: Text('Log Out'),
onPressed: () => controller.deauthenticate(),
)
]),
),
);
}
Future.delayed(Duration(seconds: 1), () {
controller.initialize();
});
return Scaffold(
appBar: AppBar(
title: const Text('Uninitialized'),
),
body: Center(
child: Text(''),
),
);
}));
}
}

class User {
String name = 'Nathaniel';
}
copied to clipboard
Usage #
For most users the only classes of concern are AuthenticationState and AuthenticationProvider.
AuthenticationProvider should be placed at the top of the widget tree in order to redraw the widget tree if a user is de-authenticated. You will need to pass an AuthenticationController to the provider, which has many optional parameters.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.