Production-ready Flutter starter with Clean Architecture, Firebase, and BLoC state management. Ships with authentication, push notifications (FCM), and user profile features — English + Arabic (RTL) out of the box.
- Features
- Tech stack
- Architecture
- Prerequisites
- Quick start
- Firebase setup
- Run the app
- Project structure
- Routes
- Authentication
- Push notifications (FCM)
- User profile
- Localization
- Code generation
- Testing
- Security rules
- Troubleshooting
- License
- Email & password (login, register, forgot password)
- Google Sign-In
- Apple Sign-In
- Phone OTP with 60-second resend timer
- Auth-guarded navigation via GoRouter
- User document saved to Firestore on sign-in
- Permission request on first launch (iOS + Android 13+)
- Foreground: custom in-app banner (auto-dismiss 4s)
- Background & terminated: top-level handler + tap navigation
- FCM token stored in Firestore
users/{uid}/fcmToken - Token refresh on
onTokenRefresh - Last 20 notifications cached locally (SharedPreferences)
- Notification history screen
- View and edit display name & bio
- Profile photo upload to Firebase Storage
- Data persisted in Firestore
users/{uid}
- Clean Architecture (domain / data / presentation)
- Dependency injection (GetIt + injectable)
- Immutable models & states (freezed)
- Functional error handling (
Either<Failure, T>via fpdart) - Light / dark theme (ThemeCubit + SharedPreferences)
- Localization: English + Arabic (RTL)
| Category | Packages |
|---|---|
| State | flutter_bloc, bloc_test |
| DI | get_it, injectable |
| Navigation | go_router |
| Firebase | firebase_core, firebase_auth, cloud_firestore, firebase_messaging, firebase_storage, firebase_analytics |
| Auth providers | google_sign_in, sign_in_with_apple |
| Code gen | freezed, json_serializable, build_runner |
| Testing | mocktail, flutter_test |
| Other | fpdart, dio, shared_preferences, image_picker, intl |
Each feature lives under lib/features/<feature>/ with three layers:
lib/features/<feature>/
├── domain/ # entities, repository contracts, use-cases
├── data/ # models, datasources, repository implementations
└── presentation/ # bloc/cubit, pages, widgets
Shared code: lib/core/ (errors, DI, router, theme, constants, utils).
flowchart TB
subgraph presentation [Presentation]
Pages[Pages / Widgets]
Bloc[BLoC / Cubit]
end
subgraph domain [Domain]
UC[Use Cases]
RepoAbs[Repository Contract]
Entity[Entities]
end
subgraph data [Data]
RepoImpl[Repository Impl]
DS[Datasources]
Model[Models]
end
Pages --> Bloc --> UC --> RepoAbs
UC --> Entity
RepoImpl -.implements.-> RepoAbs
RepoImpl --> DS
DS --> Model
| Tool | Version |
|---|---|
| Flutter SDK | ≥ 3.10 |
| Dart SDK | ≥ 3.10 |
| Firebase project | console.firebase.google.com |
| FlutterFire CLI | dart pub global activate flutterfire_cli |
| Xcode | Latest (for iOS) |
| Android Studio | Latest (for Android) |
Optional but recommended:
- A physical device for Phone OTP and Apple Sign-In testing
- Firebase CLI for rules deployment
git clone <your-repo-url>
cd starter
flutter pub getdart pub global activate flutterfire_cli
flutterfire configureThis generates lib/firebase_options.dart with your real API keys and downloads platform config files:
android/app/google-services.jsonios/Runner/GoogleService-Info.plist
dart run build_runner build --delete-conflicting-outputs
flutter gen-l10nflutter runIn Firebase Console → your project:
| Service | Where |
|---|---|
| Authentication | Build → Authentication → Sign-in method |
| Cloud Firestore | Build → Firestore Database → Create database |
| Cloud Storage | Build → Storage → Get started |
| Cloud Messaging | Project Settings → Cloud Messaging |
Enable all providers you plan to use:
| Provider | Console steps |
|---|---|
| Email/Password | Authentication → Sign-in method → Email/Password → Enable |
| Enable Google → add support email | |
| Apple | Enable Apple → follow Apple Developer setup (see below) |
| Phone | Enable Phone → add test numbers for development |
- Firebase Console → Project Settings → Your apps → Android
- Add SHA-1 and SHA-256 fingerprints:
# Debug keystore (default)
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android- Download updated
google-services.jsonand replace inandroid/app/
- Apple Developer → Identifiers → enable Sign in with Apple for your App ID
- Xcode → open
ios/Runner.xcworkspace→ Runner target → Signing & Capabilities → + Capability → Sign in with Apple - Firebase Console → Authentication → Apple → configure Service ID & key
- Test on a real iPhone (Simulator support is limited)
- Firebase Console → Authentication → Phone → Enable
- Add test phone numbers for development (bypasses SMS)
- Use a physical device — emulators often fail SMS delivery
- Ensure SHA fingerprints are registered (Android)
- Apple Developer → create APNs key
- Firebase Console → Project Settings → Cloud Messaging → upload APNs key
- Xcode → Runner → Signing & Capabilities → Push Notifications + Background Modes → Remote notifications
(Background modes are already inios/Runner/Info.plist)
# List devices
flutter devices
# Run on a specific device
flutter run -d <device_id>
# Release build
flutter build apk --release
flutter build ios --release- Splash (
/) — checks auth state - Login (
/login) — if not signed in - Home (
/home) — if authenticated
From Home you can open Profile and Notifications.
lib/
├── main.dart # Firebase init, DI, FCM background handler
├── app.dart # MaterialApp.router, theme, banner host
├── firebase_options.dart # Generated by flutterfire configure
├── core/
│ ├── constants/
│ ├── di/ # GetIt + injectable
│ ├── errors/ # Failure types
│ ├── router/ # GoRouter + auth redirect
│ ├── theme/
│ ├── usecases/
│ └── utils/
├── features/
│ ├── auth/ # Login, register, OTP, social auth
│ ├── notifications/ # FCM service, history, in-app banner
│ ├── profile/ # Edit profile, photo upload
│ └── home/
└── l10n/ # app_en.arb, app_ar.arb
test/
└── features/
├── auth/
├── notifications/
└── profile/
| Path | Screen | Auth required |
|---|---|---|
/ |
Splash | No |
/login |
Login | No |
/register |
Register | No |
/phone-login |
Phone login | No |
/otp |
OTP verification | No |
/forgot-password |
Reset password | No |
/home |
Home | Yes |
/profile |
Profile editor | Yes |
/notifications |
Notification history | Yes |
Route constants: lib/core/router/route_names.dart
- Email —
LoginPage,RegisterPage,ForgotPasswordPage - Google / Apple — social buttons on login screen
- Phone —
PhoneLoginPage→OtpPage(6-digit input, 60s resend)
On successful sign-in, a document is created/merged at:
users/{uid}
├── email
├── displayName
├── photoUrl
├── phoneNumber
├── createdAt
└── fcmToken # updated on login & token refresh
AuthBloc listens to FirebaseAuth.authStateChanges() and drives GoRouter redirects.
| App state | Behavior |
|---|---|
| Foreground | In-app banner via NotificationBannerHost |
| Background | System tray notification; tap opens app + navigates |
| Terminated | getInitialMessage() on cold start |
Firebase Console → Engage → Messaging → Create campaign → Firebase Notification messages.
Custom data (required for routing and history):
| Key | Example | Description |
|---|---|---|
type |
order |
chat, order, promo, or system |
targetRoute |
/home |
GoRouter path to open on tap |
title |
New order |
Fallback title |
body |
Order #123 ready |
Fallback body |
Example payload (HTTP v1 / Cloud Functions):
{
"message": {
"token": "<FCM_DEVICE_TOKEN>",
"notification": {
"title": "New order",
"body": "Order #123 is ready"
},
"data": {
"type": "order",
"targetRoute": "/home",
"title": "New order",
"body": "Order #123 is ready"
}
}
}The last 20 notifications are stored in SharedPreferences and shown on /notifications.
users/{uid}
├── displayName
├── email # read-only in UI
├── bio
├── photoUrl
└── phoneNumber
Uploaded to Firebase Storage:
users/{uid}/avatar.jpg
The download URL is saved to photoUrl in Firestore.
- iOS:
NSPhotoLibraryUsageDescriptioninios/Runner/Info.plist - Android:
READ_MEDIA_IMAGES,POST_NOTIFICATIONSinAndroidManifest.xml
| Locale | File | RTL |
|---|---|---|
| English | lib/l10n/app_en.arb |
No |
| Arabic | lib/l10n/app_ar.arb |
Yes |
Access strings in widgets:
import 'package:starter/core/utils/l10n_extension.dart';
Text(context.l10n.loginTitle);Add a new key to both ARB files, then run:
flutter gen-l10nTest Arabic: change device language to Arabic or add a locale switcher.
Run after changing @freezed, @injectable, or @JsonSerializable classes:
dart run build_runner build --delete-conflicting-outputsWatch mode (during active development):
dart run build_runner watch --delete-conflicting-outputsRegenerate localizations:
flutter gen-l10n# All tests
flutter test
# With coverage
flutter test --coverage
genhtml coverage/lcov.info -o coverage/html # optional HTML report
# Analyzer
flutter analyzeTests use mocktail (not mockito) and bloc_test for BLoC/Cubit sequences.
test/features/
├── auth/ # use-cases, repository, AuthBloc
├── notifications/ # use-cases, NotificationsCubit
└── profile/ # use-cases, ProfileCubit
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /users/{userId}/{allPaths=**} {
allow read: if request.auth != null;
allow write: if request.auth != null && request.auth.uid == userId;
}
}
}Deploy with Firebase CLI:
firebase deploy --only firestore:rules,storageRun flutterfire configure and select your Firebase project.
- Add SHA-1/SHA-256 to Firebase Console
- Re-download
google-services.json - Use the same package name as registered in Firebase
- Enable capability in Xcode
- Configure Apple provider in Firebase Console
- Test on a real device with a valid Apple ID
- Add test numbers in Firebase Console for dev
- Use a physical device
- Check SHA fingerprints (Android)
- Verify Phone auth is enabled
- Upload APNs key to Firebase Console
- Enable Push Notifications capability in Xcode
- Test on a real device (not Simulator for remote pushes)
dart run build_runner build --delete-conflicting-outputs- Enable Firebase Storage in Console
- Deploy Storage security rules
- Check
photoUrlwrite permissions onusers/{uid}
flutter pub get
dart run build_runner build --delete-conflicting-outputs
flutter gen-l10nThis project is provided as a starter template. Add your own license as needed.