flappwrite account kit
a flutter wrapper for appwrite’s accounts service, makes it easy to use manage authentication and account features.
under development. not ready for production. help get ready for production.
getting started
this is really very easy to use
- add dependency from git (will only publish to pub if enough people are interested to use and help make it better.)
dependencies:
flappwrite_account_kit:
git: https://github.com/lohanidamodar/flappwrite_account_kit - wrap your materialapp
flappwriteaccountkit
passing a properly initialized appwrite client. example below:class myapp extends statefulwidget {
@override
_myappstate createstate() => _myappstate();
}class _myappstate extends state
<myapp>
{
late client client;
@override
void initstate() {
super.initstate();
//initialize your client
client = client();
client
.setendpoint(‘https://localhost/v1‘)
.setproject(‘60793ca4ce59e’)
.setselfsigned();
}@override
widget build(buildcontext context) {
return flappwriteaccountkit(
client: client,
child: materialapp(
title: ‘flutter demo’,
theme: themedata(
primaryswatch: colors.blue,
),
home: mainscreen(),
),
);
}
} - access
authnotifier
fromcontext
.authnotifier
is an instance ofauthnotifier
that provides all the functions of appwrite’s account service and some easy way to handle authentication. - get
context.authnotifier?.status
gets the authentication status which can be one of theauthstatus.uninitialized
,authstatus.unauthenticated
,authstatus.authenticating
andauthstatus.authenticated
. you can check the status and display the appropriate ui, for exampleclass mainscreen extends statelesswidget {
@override
widget build(buildcontext context) {
final authnotifier = context.authnotifier;widget widget; switch (authnotifier.status) { case authstatus.authenticated: widget = adminpage(); break; case authstatus.unauthenticated: case authstatus.authenticating: widget = loginpage(); break; case authstatus.uninitialized: default: widget = loadingpage(); break; } return widget;
}
} - you must use the functions from the
context.authnotifier
instead default account service from appwrite sdk to create user, create session (login), delete session (logout), so that thecontext.authnotifier?.status
is properly updated and your ui updates accordingly.
Comments are closed.