docs(firebase_login): add firebase login example app
Description
Add a Flutter app example demonstrating how to handle Firebase authentication using Riverpod.
- sign up, and sign in with email and password
- sign in with google
- error handling, display error message
- navigation based on the user's authentication state
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
-
[ ] I have updated the
CHANGELOG.mdof the relevant packages. Changelog files must be edited under the form:## Unreleased fix/major/minor - Description of your change. (thanks to @yourGithubId) -
[ ] If this contains new features or behavior changes, I have updated the documentation to match those changes.
Summary by CodeRabbit
-
New Features
- Added Firebase authentication with email/password and Google Sign-In
- Implemented user sign-up, sign-in, and sign-out functionality
- Created home screen displaying user information
- Introduced README with setup instructions and screenshots
-
Documentation
- Added project configuration files, metadata, and
.gitignore
- Added project configuration files, metadata, and
-
Testing
- Implemented widget tests for authentication flows
- Added test utilities for mocking authentication repository
-
Development Tools
- Configured Riverpod for state management
- Set up analysis options and linting configurations
- Added build and development dependency configurations
- Introduced dependency overrides for local development
Walkthrough
This pull request introduces a comprehensive Firebase login example application using Flutter and Riverpod. The project establishes a complete authentication flow with sign-up, sign-in, and home pages, integrating Firebase authentication with Google Sign-In. It includes detailed error handling and state management using Freezed and Riverpod. The project is configured with metadata, linting rules, dependency management, and extensive .gitignore settings. Additionally, it provides documentation, generated code for providers, and a suite of widget tests covering authentication flows and UI components.
Changes
| File | Change Summary |
|---|---|
examples/firebase_login/.gitignore |
Added comprehensive ignore patterns for Flutter, Firebase, and development environments. |
examples/firebase_login/.metadata |
Created project metadata file with Flutter configuration details and migration tracking. |
examples/firebase_login/README.md |
Added documentation with app features, screenshots, and setup instructions. |
examples/firebase_login/analysis_options.yaml |
Configured linting and analysis options including Riverpod lint plugin and error ignores. |
examples/firebase_login/lib/auth/auth_repository.dart |
Implemented authentication repository with Firebase and Google Sign-In methods, error handling, and Riverpod providers. |
examples/firebase_login/lib/auth/auth_repository.g.dart |
Generated Riverpod provider code for authentication repository and related services. |
examples/firebase_login/lib/auth/user.dart |
Introduced immutable User model class with authentication state helpers using Freezed. |
examples/firebase_login/lib/auth/user.freezed.dart |
Generated immutable User class implementation using Freezed. |
examples/firebase_login/lib/home/home.dart |
Created home page widget displaying user info and logout button with sign-out functionality. |
examples/firebase_login/lib/main.dart |
Created main application entry point initializing Firebase and managing auth state with Riverpod. |
examples/firebase_login/lib/main.g.dart |
Generated Riverpod provider code for user authentication stream. |
examples/firebase_login/lib/sign_in/sign_in.dart |
Developed sign-in page with email/password and Google authentication, state management, and error handling. |
examples/firebase_login/lib/sign_in/sign_in.freezed.dart |
Implemented sign-in state management using Freezed with states: initial, loading, success, failure. |
examples/firebase_login/lib/sign_up/sign_up.dart |
Implemented sign-up page with email registration, state management, and error handling. |
examples/firebase_login/lib/sign_up/sign_up.freezed.dart |
Defined sign-up state management using Freezed with states: initial, loading, success, failure. |
examples/firebase_login/pubspec.yaml |
Defined project dependencies, environment constraints, and dev dependencies. |
examples/firebase_login/pubspec_overrides.yaml |
Added dependency overrides for local Riverpod package development. |
examples/firebase_login/test/app_test.dart |
Introduced widget tests for the App component verifying auth-based navigation. |
examples/firebase_login/test/home_test.dart |
Added widget test for HomePage verifying sign-out interaction triggers signOut method. |
examples/firebase_login/test/pump_app.dart |
Created mock authentication repository and widget tester extension for injecting mocks. |
examples/firebase_login/test/sign_in_test.dart |
Established widget tests for SignInPage verifying sign-in method calls on user interaction. |
examples/firebase_login/test/sign_up_test.dart |
Validated sign-up functionality with widget test verifying sign-up method call on form submission. |
Poem
π° A Rabbit's Authentication Tale π
With Firebase and Riverpod's might,
Login flows now shine so bright!
Sign in, sign up, with Google's grace,
Security dances at a playful pace!
~ CodeRabbit's Authentication Poet π
[!TIP]
β‘π¬ Agentic Chat (Pro Plan, General Availability)
- We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
π Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 1bca38150b671991b4fdc73aeb635aae842ea275 and 583ae7fe0e59b7d61e41b7521222c594608918cc.
π Files selected for processing (1)
examples/firebase_login/lib/auth/user.dart(1 hunks)
π§ Files skipped from review as they are similar to previous changes (1)
- examples/firebase_login/lib/auth/user.dart
β° Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Redirect rules - river-pod
- GitHub Check: Header rules - river-pod
- GitHub Check: Pages changed - river-pod
- GitHub Check: riverpod_lint (master, packages/riverpod_lint)
- GitHub Check: changelog
- GitHub Check: check_generation
- GitHub Check: build (stable, packages/flutter_riverpod/example)
- GitHub Check: build (stable, examples/pub)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
πͺ§ Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
I don't like the proposed folder architecture. Please don't use kind-based folders such as models/ providers/ repositories.
Instead use feature-based folders like home/login_page/settings/ ...
Thanks for this!
I gave a very quick look at the current state, and suggested broad changes. I'll look move closely at the details once we agree on the basics :)
Note: It'd be useful to update the README with:
- instructions on how folks can run the example (so using setting up their firebase.json & co)
- screenshots of the example in various scenarios, to allow folks to easily see what the example can do
Thanks for the quick review and feedback, Remi.
I'll make the changes as suggested, and I'll make sure to verify the architecture with you before I start moving things around, so weβre on the same page. I'll add instructions to the README as well.
Cool :)
If you have any doubt, feel free to ask questions!
@rrousselGit I have considered your suggestions and come up with this structure, what do you think about it?
lib/
βββ auth/
β βββ auth_repository.dart
β βββ user.dart
βββ app/
β βββ app_state.dart // e.g., app state provider (auth state can be renamed)
β βββ app.dart // MaterialApp widget, route initialization
βββ sign_in/
β βββ sign_in_page.dart
β βββ sign_in_state.dart // Providers related to sign-in
βββ sign_up/
β βββ sign_up_page.dart
β βββ sign_up_state.dart // Providers related to sign-up
βββ home/
β βββ home_page.dart
βββ main.dart
βββ provider_observer.dart
Also, I noticed your comment regarding app_provider_observer.dart is not useful in this context. It can help debug during the development process.
If you feel it doesn't add enough value here, I'm happy to remove it! I just thought it might be beneficial to keep it for the debugging phase and as a teaching point for others reviewing the example.
@rrousselGit I have considered your suggestions and come up with this structure, what do you think about it?
Must better!
Also, I noticed your comment regarding
app_provider_observer.dartis not useful in this context. It can help debug during the development process.If you feel it doesn't add enough value here, I'm happy to remove it! I just thought it might be beneficial to keep it for the debugging phase and as a teaching point for others reviewing the example.
I think it's better to remove it.
IMO, less is more. The more noise we add, the harder it is for people to find what they are looking for.
In that sense, I'd even consider removing the snackbar logic.
Demonstrating how to do those things is valuable. But it should likely be a separate example instead.
One example = one goal.
This one is about Firebase auth.
We can have another example for demonstrating logging (including Crashlytics interaction).
And another one for how to deal with loading/error pages ; be it snackbars or "Oopsy" screens.
If this example contains something, it should be closely related to Firebase Auth.
Actually about the folder structure, I'd still change a few things.
What I'd personally do is:
lib/
βββ sign_in.dart // Both the view + provider
βββ sign_up.dart // Both the view + provider again
βββ home.dart // View + whatever home-state there is
βββ main.dart // Including whatever was from the proposed "app" folder"
For UI, I usually go with "one file per route".
It's good to keep the provider and its view in the same file. No need to separate them