easy_engine 0.0.6  easy_engine: ^0.0.6 copied to clipboard
easy_engine: ^0.0.6 copied to clipboard
The counter part of the easy_engine project.
Easy Extensions #
The easy_engine package is the counter part of the easy-engine built as the firebase cloud functions to support various essential features that cannot be done from font-end applications like enabling and disabling user account, sending push notifications, and more.
Terms #
- easy-engin(with a hyphen) is the cloud function project. Meanwhile,- easy_engine(with an underscore) is the Flutter package that supports access to the cloud functions of the- easy-engine.
Why the cloud functions? #
- Refer Why cloud functions? at the easy-enginecloud function project.
ClaimAdmin #
- 
This function is optional. You can set a user as an admin without this function. You can simply open the Firebase console -> Firestore -> look for user document -> set admin field to trueto make a user as an admin.
- 
The EngineService.instance.claimAdminfunction allows the logged-in user to set himself as an admin. If an admin already exists, it will give an error(Exception) with the codealready-existand the messageAdmin already exists.
- 
Essentially, it marks the adminfield of the logged-in user astrueif no other user has this field set totrue.
- 
regionis the region of your cloud functions. It is recommended to have the same region as your firestore.
ElevatedButton(
  onPressed: () async {
    try {
      await engine.claimAdmin(region: region);
      onSuccess();
    } on FirebaseFunctionsException catch (e) {
      onFailure('${e.code}/${e.message}');
    } catch (e) {
      onFailure(e.toString());
    }
  },
  child: const Text('Claim Admin'),
)
ClaimAdminButton #
- Use the ClaimAdminButtonwidget for simplicity, or copy its code to customize it yourself.
ClaimAdminButton(region: 'asia-northeast3'),
Delete Account #
- 
This fucntion provides a better user experience to users and easy to develop the recent-loginlogic to developers.
- 
This function is optional. You can develop the recent-loginprocedure in your app without installing this function.
- 
As stated in the official document of Apple developer's page, it is mandatory to provide a way of deleting their own account to users. 
- 
The code below only provides the account deletion only. It is up to the app how to delete all the user related data and sign out. - If the cloud function is called again when the user account is deleted, it will throw an error of internal.
 
- If the cloud function is called again when the user account is deleted, it will throw an error of 
ElevatedButton(
  onPressed: () async {
    try {
      final re = await engine.deleteAccount();
      print(re);
    } on FirebaseFunctionsException catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content:
              Text('Error: ${e.code}/${e.message}'),
        ),
      );
    } catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Error: $e'), // e.code: internal, e.message: INTERNAL
        ),
      );
    }
  },
  child: const Text('Delete Account'),
),
Push notifications #
- The easy-enginecloud function project supports push notifications. But thiseasy_egineof easy_packages does not support these functions because theeasy_messagingpackage is already supporting the push notification ofeasy-engine.