Firebase UI for Flutter
repository·main·Indexed 41 days ago
https://github.com/firebase/firebaseui-flutterA suite of specialized plugins providing ready-made UI components to rapidly integrate Firebase services into Flutter applications. Includes firebase_ui_auth for authentication flows (Email, Phone, OAuth), as well as plugins for Firestore, Realtime Database, and Storage. Features pre-built widgets like SignInScreen and ProfileScreen, and support for multiple languages via the firebase_ui_localizations package.
What's inside Firebase UI for Flutter
- Firebase UI for Flutter is a collection of plugins designed to quickly connect common Flutter UI elements to Firebase APIs. Instead of building complex authentication, database, or storage interfaces from scratch, you can use these specialized plugins to implement standard Firebase features with pre-built UI components.
Overview of Firebase UI Storage
mainFirebase UI Storage provides a collection of Flutter widgets and utilities specifically designed to simplify the integration of user interfaces with Firebase Storage. It offers pre-built components for common storage tasks such as uploading files, displaying progress, rendering images, and listing files in list or grid formats.Explore Firebase UI for Flutter plugins
mainFirebase UI for Flutter provides a collection of specialized plugins to simplify common Firebase integrations. The available plugins include:
Firebase UI Auth
Provides pre-built authentication flows and UI components. Supported authentication methods include:
- Email: Standard email/password authentication.
- Email link: Passwordless authentication via email links.
- Universal Email Sign In: Simplified email-based sign-in.
- Phone: SMS-based phone number authentication.
- OAuth: Social authentication providers (e.g., Google, Facebook).
- Email verification: Flows for verifying user email addresses.
- Navigation & Theming: Customization options for auth flow navigation and visual styles.
Firebase UI Database
Provides UI components and integrations for Firebase database services.
Firebase UI Storage
Provides UI components and integrations for Firebase Storage services.
Use Firebase UI OAuth providers
mainThe
firebase_ui_oauthpackage serves as the base package for various Firebase UI OAuth provider plugins. To implement specific OAuth authentication flows, you must install the specific provider package required for your target service:- Apple Sign In:
firebase_ui_oauth_apple - Google Sign In:
firebase_ui_oauth_google - Facebook Sign In:
firebase_ui_oauth_facebook - Twitter Sign In:
firebase_ui_oauth_twitter
- Apple Sign In:
Customize the loading state of StorageImage
mainThe
StorageImagewidget allows you to define different visual behaviors while the image is being fetched from Firebase Storage using theloadingStateproperty.Available variants via
LoadingStateVariantinclude:solidColor: Displays a solid color placeholder (default).loadingIndicator: Displays a progress indicator (CircularProgressIndicatorfor Material orCupertinoActivityIndicatorfor Cupertino).shimmer: Displays a shimmering animation over a solid color.blurHash: Displays a blurred version of the image using a BlurHash string.
StorageImage( ref: FirebaseStorage.instance.ref('images/dash_and_sparky.png'), fit: BoxFit.cover, loadingState: LoadingStateVariant.solidColor(), // Example variant );How navigation works in Firebase UI
mainFirebase UI uses standard Flutter navigation by default, specifically using
Navigator 1.0(e.g.,Navigator.push(context, route)).- Standard Apps: If your application uses standard Flutter navigation APIs, Firebase UI works out of the box without configuration.
- Custom Routing Apps: If you use a custom routing package or named routes, you must override the default navigation actions using the
actionsproperty on Firebase UI widgets to integrate with your routing strategy.
PaginatedLoadingController states
mainThe
PaginatedLoadingControlleruses a state object to communicate the current status of the data fetch. You can use aswitchexpression onctrl.stateto render different UI components:InitialPageLoading: The very first request for the first page is in progress.PageLoading: A subsequent page is being fetched.PageLoadError: An error occurred during fetching. The error details are available via theerrorproperty.PageLoadComplete: Data has been successfully loaded. The loaded items are available via theitemsproperty.
Advanced configuration with FirestoreQueryBuilder
mainIf you need more control than
FirestoreListViewprovides (for example, using aGridViewinstead of aListView), useFirestoreQueryBuilder.Unlike
FirestoreListView,FirestoreQueryBuilderdoes not provide a built-in list implementation. Instead, itsbuilderreturns aQueryBuilderSnapshotwhich represents the entire state of the query. You are responsible for:- Handling loading states via
snapshot.isFetching. - Handling error states via
snapshot.hasError. - Implementing the UI (e.g.,
GridView.builder). - Manually triggering more data fetches by calling
snapshot.fetchMore()when the user reaches the end of the current list andsnapshot.hasMoreis true.
FirestoreQueryBuilder<Map<String, dynamic>>( query: usersQuery, builder: (context, snapshot, _) { if (snapshot.isFetching) { return const CircularProgressIndicator(); } if (snapshot.hasError) { return Text('Something went wrong! ${snapshot.error}'); } return GridView.builder( itemCount: snapshot.docs.length, itemBuilder: (context, index) { // Manual infinite scroll trigger if (snapshot.hasMore && index + 1 == snapshot.docs.length) { snapshot.fetchMore(); } final user = snapshot.docs[index].data(); return Text(user['name']); }, ); }, );- Handling loading states via
Implement custom scroll views with PaginatedLoadingController
mainIfStorageListViewis too restrictive for your UI needs, you can usePaginatedLoadingControllerto manage the pagination logic yourself while still benefiting from the automated batch loading capabilities.Theme Firebase UI widgets using MaterialApp or CupertinoApp
mainFirebase UI widgets are built on top of Flutter's Material and Cupertino design patterns. They do not have their own independent styling system; instead, they inherit their appearance from the
ThemeData(forMaterialApp) orCupertinoThemeData(forCupertinoApp) provided in your application's root widget.For example, a
SignInScreenusing anEmailAuthProviderwill automatically use standard Material widgets likeTextFormField,TextButton, andOutlinedButton. To change the look of these components, you must override the corresponding theme properties in yourMaterialApp.class FirebaseAuthUIExample extends StatelessWidget { @override Widget build(BuildContext context) { return const MaterialApp( home: SignInScreen( providers: [ EmailAuthProvider(), ], ), ); } }Advanced configuration with FirebaseDatabaseQueryBuilder
mainIf you need more control than
FirebaseDatabaseListViewprovides (for example, if you want to use aGridViewinstead of aListView), useFirebaseDatabaseQueryBuilder.Unlike the list view widget,
FirebaseDatabaseQueryBuilderdoes not provide a UI implementation. Instead, it provides aFirebaseQueryBuilderSnapshotvia itsbuildercallback. This snapshot contains the state of the entire query, including:isFetching: Boolean indicating if data is currently being loaded.hasError: Boolean indicating if an error occurred.error: The error object ifhasErroris true.docs: A list of the documents currently loaded.hasMore: Boolean indicating if there are more items available to fetch.fetchMore(): A method to trigger the loading of the next page of data.
Note: When using a custom implementation like
GridView.builder, you must manually callsnapshot.fetchMore()when the user reaches the end of the current list to enable infinite scrolling.final usersQuery = FirebaseDatabase.instance.ref('users').orderByChild('name'); FirebaseDatabaseQueryBuilder( query: usersQuery, builder: (context, snapshot, _) { if (snapshot.isFetching) { return const CircularProgressIndicator(); } if (snapshot.hasError) { return Text('Something went wrong! ${snapshot.error}'); } return GridView.builder( itemCount: snapshot.docs.length, itemBuilder: (context, index) { // Manually trigger fetchMore when reaching the end of the current batch if (snapshot.hasMore && index + 1 == snapshot.docs.length) { snapshot.fetchMore(); } final user = snapshot.docs[index].value as Map<String, dynamic>; return Text("User name is ${user['name']}"); }, ); }, );Use PaginatedLoadingController for custom scroll views
mainIfStorageGridViewdoes not meet your customization needs, you can implement your own custom scroll view while still leveraging the pagination logic by using thePaginatedLoadingController.