build method Null safety

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds a widget that performs email-based authorization.

Implementation

@override
Widget build(BuildContext context) {
  return MaterialApp(
    theme: ThemeData(
      brightness: Brightness.light,
      visualDensity: VisualDensity.standard,
      inputDecorationTheme: const InputDecorationTheme(
        border: OutlineInputBorder(),
      ),
    ),
    initialRoute: initialRoute,
    routes: {
      '/': (context) {
        return SignInScreen(
          actions: [
            ForgotPasswordAction((context, email) {
              Navigator.pushNamed(
                context,
                '/forgot-password',
                arguments: {'email': email},
              );
            }),
            AuthStateChangeAction<SignedIn>((context, state) {
              if (!state.user!.emailVerified) {
                Navigator.pushNamed(context, '/verify-email');
              } else {
                Navigator.pushReplacementNamed(context, '/profile');
              }
            }),
            AuthStateChangeAction<UserCreated>((context, state) {
              if (!state.credential.user!.emailVerified) {
                Navigator.pushNamed(context, '/verify-email');
              } else {
                Navigator.pushReplacementNamed(context, '/profile');
              }
            }),
            AuthStateChangeAction<CredentialLinked>((context, state) {
              if (!state.user.emailVerified) {
                Navigator.pushNamed(context, '/verify-email');
              } else {
                Navigator.pushReplacementNamed(context, '/profile');
              }
            }),
          ],
          styles: const {
            EmailFormStyle(signInButtonVariant: ButtonVariant.filled),
          },
          headerBuilder: headerImage('assets/images/flutterfire_logo.png'),
          sideBuilder: sideImage('assets/images/flutterfire_logo.png'),
          subtitleBuilder: (context, action) {
            return Padding(
              padding: const EdgeInsets.only(bottom: 8),
              child: Text(
                action == AuthAction.signIn
                    ? 'Welcome to Firebase UI! Please sign in to continue.'
                    : 'Welcome to Firebase UI! Please create an account to continue',
              ),
            );
          },
          footerBuilder: (context, action) {
            return Center(
              child: Padding(
                padding: const EdgeInsets.only(top: 16),
                child: Text(
                  action == AuthAction.signIn
                      ? 'By signing in, you agree to our terms and conditions.'
                      : 'By registering, you agree to our terms and conditions.',
                  style: const TextStyle(color: Colors.grey),
                ),
              ),
            );
          },
        );
      },
      '/verify-email': (context) {
        return EmailVerificationScreen(
          headerBuilder: headerIcon(Icons.verified),
          sideBuilder: sideIcon(Icons.verified),
          actions: [
            EmailVerifiedAction(() {
              Navigator.pushReplacementNamed(context, '/profile');
            }),
            AuthCancelledAction((context) {
              FirebaseUIAuth.signOut(context: context);
              Navigator.pushReplacementNamed(context, '/');
            }),
          ],
        );
      },
      '/forgot-password': (context) {
        final arguments = ModalRoute.of(context)?.settings.arguments
            as Map<String, dynamic>?;

        return ForgotPasswordScreen(
          email: arguments?['email'],
          headerMaxExtent: 200,
          headerBuilder: headerIcon(Icons.lock),
          sideBuilder: sideIcon(Icons.lock),
        );
      },
      '/profile': (context) {
        return ProfileScreen(
          actions: [
            SignedOutAction((context) {
              Navigator.pushReplacementNamed(context, '/');
            }),
          ],
        );
      },
    },
    title: 'Firebase Email Authorization Demo',
    debugShowCheckedModeBanner: false,
  );
}