apptive_grid_user_management 2.0.2 copy "apptive_grid_user_management: ^2.0.2" to clipboard
apptive_grid_user_management: ^2.0.2 copied to clipboard

Package to add UserManagement through ApptiveGrid to a Flutter App. This provides Login/Register Widgets and options to confirm accounts

example/lib/main.dart

// ignore_for_file: public_member_api_docs

import 'package:apptive_grid_user_management/apptive_grid_user_management.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  final _navigatorKey = GlobalKey<NavigatorState>();

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ApptiveGrid(
      options: const ApptiveGridOptions(
        environment: ApptiveGridEnvironment.alpha,
      ),
      child: Builder(
        builder: (context) {
          return ApptiveGridUserManagement(
            group: 'YOUR_USER_GROUP',
            clientId: 'app',
            redirectScheme: 'resetTest',
            confirmAccountPrompt: (confirmWidget) {
              // Show [confirmWidget] to allow Users to confirm their account
              _navigatorKey.currentState?.push(
                MaterialPageRoute(
                  builder: (_) => Scaffold(
                    appBar: AppBar(
                      title: const Text('Confirm Account'),
                    ),
                    body: SingleChildScrollView(
                      child: confirmWidget,
                    ),
                  ),
                ),
              );
            },
            onAccountConfirmed: (loggedIn) {
              // Account was confirmed
              // go to login screen if [loggedIn] is false
              ScaffoldMessenger.of(_navigatorKey.currentContext!).showSnackBar(
                SnackBar(
                  content: Text('Account Confirmed. LoggedIn: $loggedIn'),
                ),
              );
              if (loggedIn) {
                Navigator.of(context).pushReplacement(
                  MaterialPageRoute(
                    builder: (_) {
                      return const AccountPage();
                    },
                  ),
                );
              } else {
                _navigatorKey.currentState?.pop();
              }
            },
            resetPasswordPrompt: (resetPasswordWidget) {
              // Show [resetPasswordWidget] to allow Users to set a new password
              _navigatorKey.currentState?.push(
                MaterialPageRoute(
                  builder: (_) => Scaffold(
                    appBar: AppBar(
                      title: const Text('Reset Password'),
                    ),
                    body: SingleChildScrollView(
                      child: resetPasswordWidget,
                    ),
                  ),
                ),
              );
            },
            onPasswordReset: (loggedIn) async {
              // User reset their password
              // go to login screen
              debugPrint('Password reset success');
              debugPrint('User is now loggedIn: $loggedIn');
              _navigatorKey.currentState?.pop();
            },
            passwordRequirement: PasswordRequirement.safetyHint,
            child: MaterialApp(
              navigatorKey: _navigatorKey,
              title: 'Apptive Grid User Management Example',
              theme: ThemeData(
                primarySwatch: Colors.blue,
              ),
              home: const LoginRegistrationPage(),
            ),
          );
        },
      ),
    );
  }
}

class LoginRegistrationPage extends StatelessWidget {
  const LoginRegistrationPage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Login/Register'),
      ),
      body: ListView(
        children: [
          Padding(
            padding: const EdgeInsets.all(8),
            child: Card(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: ApptiveGridUserManagementContent(
                  appName: 'ApptiveGridUserManagement Example',
                  onLogin: () {
                    Navigator.of(context).pushReplacement(
                      MaterialPageRoute(
                        builder: (_) {
                          return const AccountPage();
                        },
                      ),
                    );
                  },
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class AccountPage extends StatefulWidget {
  const AccountPage({super.key});

  @override
  State<AccountPage> createState() => _AccountPageState();
}

class _AccountPageState extends State<AccountPage> {
  User? _user;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    ApptiveGrid.getClient(context).getMe().then((user) {
      setState(() {
        _user = user;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Account'),
      ),
      body: Builder(
        builder: (_) {
          if (_user == null) {
            return const Center(
              child: CircularProgressIndicator.adaptive(),
            );
          } else {
            return Column(
              children: [
                Text('Logged in as ${_user!.firstName} ${_user!.lastName}'),
                TextButton(
                  onPressed: () {
                    ApptiveGrid.getClient(context, listen: false)
                        .logout()
                        .then((_) {
                      Navigator.of(context).pushReplacement(
                        MaterialPageRoute(
                          builder: (_) {
                            return const LoginRegistrationPage();
                          },
                        ),
                      );
                    });
                  },
                  child: const Text('Logout'),
                ),
                DeleteAccount.textButton(
                  onAccountDeleted: () {
                    WidgetsBinding.instance.addPostFrameCallback((_) {
                      Navigator.of(context).pushReplacement(
                        MaterialPageRoute(
                          builder: (_) {
                            return const LoginRegistrationPage();
                          },
                        ),
                      );
                    });
                  },
                ),
              ],
            );
          }
        },
      ),
    );
  }
}
1
likes
130
pub points
0%
popularity

Publisher

verified publisherapptivegrid.de

Package to add UserManagement through ApptiveGrid to a Flutter App. This provides Login/Register Widgets and options to confirm accounts

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

apptive_grid_core, flutter, http, intl, password_rule_check, uni_links

More

Packages that depend on apptive_grid_user_management