reis-mobile 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/.claude-plugin/marketplace.json +24 -0
  2. package/.claude-plugin/plugin.json +12 -0
  3. package/CHANGELOG.md +103 -0
  4. package/LICENSE +21 -0
  5. package/README.md +631 -0
  6. package/THIRD_PARTY_NOTICES.md +105 -0
  7. package/agents/flutter-architect.md +92 -0
  8. package/agents/flutter-performance-engineer.md +103 -0
  9. package/agents/flutter-test-engineer.md +100 -0
  10. package/agents/lead-mobile.md +107 -0
  11. package/agents/mobile-code-reviewer.md +66 -0
  12. package/agents/mobile-staff-engineer.md +85 -0
  13. package/agents/plugin-native-expert.md +97 -0
  14. package/bin/reis-mobile.mjs +256 -0
  15. package/commands/debate.md +135 -0
  16. package/commands/doctor.md +23 -0
  17. package/commands/reis-mobile.md +50 -0
  18. package/commands/review.md +53 -0
  19. package/core/config/language.mjs +83 -0
  20. package/core/context/context-engine.mjs +113 -0
  21. package/core/detection/project-probe.mjs +104 -0
  22. package/core/detection/stack-detector.mjs +204 -0
  23. package/core/diagnostics/doctor.mjs +181 -0
  24. package/core/install/claude-plugin.mjs +76 -0
  25. package/core/paths.mjs +4 -0
  26. package/core/registry/frontmatter.mjs +81 -0
  27. package/core/registry/registry.mjs +140 -0
  28. package/core/router/intent-detector.mjs +75 -0
  29. package/core/router/intents.mjs +91 -0
  30. package/core/router/router.mjs +83 -0
  31. package/core/security/redact.mjs +24 -0
  32. package/package.json +35 -0
  33. package/skills/architecture-feature-first/SKILL.md +116 -0
  34. package/skills/bloc/SKILL.md +354 -0
  35. package/skills/code-review/SKILL.md +89 -0
  36. package/skills/dart-3-updates/SKILL.md +223 -0
  37. package/skills/dart-add-unit-test/SKILL.md +126 -0
  38. package/skills/dart-collect-coverage/SKILL.md +145 -0
  39. package/skills/dart-fix-runtime-errors/SKILL.md +170 -0
  40. package/skills/dart-generate-test-mocks/SKILL.md +159 -0
  41. package/skills/dart-migrate-to-checks-package/SKILL.md +532 -0
  42. package/skills/dart-resolve-package-conflicts/SKILL.md +120 -0
  43. package/skills/dart-run-static-analysis/SKILL.md +108 -0
  44. package/skills/dart-use-pattern-matching/SKILL.md +240 -0
  45. package/skills/dart-use-pattern-matching/examples/json_patterns.dart +85 -0
  46. package/skills/detect-mobile-stack/SKILL.md +33 -0
  47. package/skills/effective-dart/SKILL.md +187 -0
  48. package/skills/firebase-ai/SKILL.md +93 -0
  49. package/skills/firebase-analytics/SKILL.md +129 -0
  50. package/skills/firebase-app-check/SKILL.md +124 -0
  51. package/skills/firebase-auth/SKILL.md +224 -0
  52. package/skills/firebase-cloud-firestore/SKILL.md +165 -0
  53. package/skills/firebase-cloud-functions/SKILL.md +148 -0
  54. package/skills/firebase-crashlytics/SKILL.md +182 -0
  55. package/skills/firebase-data-connect/SKILL.md +80 -0
  56. package/skills/firebase-database/SKILL.md +224 -0
  57. package/skills/firebase-in-app-messaging/SKILL.md +111 -0
  58. package/skills/firebase-messaging/SKILL.md +201 -0
  59. package/skills/firebase-remote-config/SKILL.md +131 -0
  60. package/skills/firebase-storage/SKILL.md +158 -0
  61. package/skills/flutter-add-integration-test/SKILL.md +167 -0
  62. package/skills/flutter-add-widget-preview/SKILL.md +149 -0
  63. package/skills/flutter-add-widget-test/SKILL.md +158 -0
  64. package/skills/flutter-adding-home-screen-widgets/SKILL.md +205 -0
  65. package/skills/flutter-animating-apps/SKILL.md +185 -0
  66. package/skills/flutter-app-architecture/SKILL.md +80 -0
  67. package/skills/flutter-apply-architecture-best-practices/SKILL.md +166 -0
  68. package/skills/flutter-build-responsive-layout/SKILL.md +143 -0
  69. package/skills/flutter-building-forms/SKILL.md +125 -0
  70. package/skills/flutter-building-layouts/SKILL.md +131 -0
  71. package/skills/flutter-building-plugins/SKILL.md +209 -0
  72. package/skills/flutter-caching-data/SKILL.md +171 -0
  73. package/skills/flutter-change-notifier/SKILL.md +138 -0
  74. package/skills/flutter-embedding-native-views/SKILL.md +200 -0
  75. package/skills/flutter-errors/SKILL.md +126 -0
  76. package/skills/flutter-fix-layout-issues/SKILL.md +134 -0
  77. package/skills/flutter-handling-concurrency/SKILL.md +182 -0
  78. package/skills/flutter-implement-json-serialization/SKILL.md +157 -0
  79. package/skills/flutter-improving-accessibility/SKILL.md +113 -0
  80. package/skills/flutter-interoperating-with-native-apis/SKILL.md +130 -0
  81. package/skills/flutter-login-usecase/SKILL.md +38 -0
  82. package/skills/flutter-managing-state/SKILL.md +206 -0
  83. package/skills/flutter-project-audit/SKILL.md +66 -0
  84. package/skills/flutter-reducing-app-size/SKILL.md +103 -0
  85. package/skills/flutter-secure-token-store/SKILL.md +35 -0
  86. package/skills/flutter-setting-up-on-macos/SKILL.md +78 -0
  87. package/skills/flutter-setup-declarative-routing/SKILL.md +259 -0
  88. package/skills/flutter-setup-localization/SKILL.md +214 -0
  89. package/skills/flutter-theming-apps/SKILL.md +163 -0
  90. package/skills/flutter-use-http-package/SKILL.md +178 -0
  91. package/skills/flutter-widget-review/SKILL.md +54 -0
  92. package/skills/flutter-working-with-databases/SKILL.md +203 -0
  93. package/skills/flutterfire-configure/SKILL.md +143 -0
  94. package/skills/mobile-security-audit/SKILL.md +101 -0
  95. package/skills/mockito/SKILL.md +149 -0
  96. package/skills/mocktail/SKILL.md +122 -0
  97. package/skills/patrol-e2e-testing/SKILL.md +224 -0
  98. package/skills/provider/SKILL.md +139 -0
  99. package/skills/riverpod/SKILL.md +246 -0
  100. package/skills/testing/SKILL.md +50 -0
  101. package/stacks/android/stack.json +8 -0
  102. package/stacks/flutter/stack.json +8 -0
  103. package/stacks/ios/stack.json +8 -0
  104. package/stacks/kotlin-multiplatform/stack.json +8 -0
  105. package/stacks/react-native/stack.json +8 -0
@@ -0,0 +1,224 @@
1
+ ---
2
+ name: firebase-auth
3
+ description: Integrates Firebase Authentication into Flutter apps. Use when setting up auth, managing auth state, implementing email/password or social sign-in, handling auth errors, managing users, or applying security best practices.
4
+ routing: manual
5
+ stacks: [flutter]
6
+ source: https://github.com/evanca/flutter-ai-rules
7
+ license: MIT
8
+ ---
9
+
10
+ # Firebase Authentication Skill
11
+
12
+ This skill defines how to correctly use Firebase Authentication in Flutter applications.
13
+
14
+ ## When to Use
15
+
16
+ Use this skill when:
17
+
18
+ * Setting up Firebase Authentication in a Flutter project.
19
+ * Listening to authentication state changes.
20
+ * Implementing email/password or social sign-in.
21
+ * Managing user profiles, account linking, or MFA.
22
+ * Handling authentication errors.
23
+ * Applying security best practices for auth flows.
24
+
25
+ ---
26
+
27
+ ## 1. Setup and Configuration
28
+
29
+ ```
30
+ flutter pub add firebase_auth
31
+ ```
32
+
33
+ ```dart
34
+ import 'package:firebase_auth/firebase_auth.dart';
35
+ ```
36
+
37
+ - Enable desired authentication providers in the **Firebase console** before using them.
38
+ - Initialize Firebase before using any Firebase Authentication features.
39
+
40
+ **Local emulator for testing:**
41
+
42
+ ```dart
43
+ Future<void> main() async {
44
+ WidgetsFlutterBinding.ensureInitialized();
45
+ await Firebase.initializeApp();
46
+ await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
47
+ // ...
48
+ }
49
+ ```
50
+
51
+ ---
52
+
53
+ ## 2. Authentication State Management
54
+
55
+ Use the appropriate stream based on what you need to observe:
56
+
57
+ | Stream | Fires when |
58
+ |---|---|
59
+ | `authStateChanges()` | User signs in or out |
60
+ | `idTokenChanges()` | ID token changes (including custom claims) |
61
+ | `userChanges()` | User data changes (e.g., profile updates) |
62
+
63
+ ```dart
64
+ FirebaseAuth.instance
65
+ .authStateChanges()
66
+ .listen((User? user) {
67
+ if (user == null) {
68
+ print('User is currently signed out!');
69
+ } else {
70
+ print('User is signed in!');
71
+ }
72
+ });
73
+ ```
74
+
75
+ - Listen to these streams **immediately** when the app starts to handle the initial auth state.
76
+ - Custom claims are only available after sign-in, re-authentication, token expiration, or manual token refresh.
77
+
78
+ ---
79
+
80
+ ## 3. Email and Password Authentication
81
+
82
+ **Create a new account:**
83
+
84
+ ```dart
85
+ try {
86
+ final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
87
+ email: emailAddress,
88
+ password: password,
89
+ );
90
+ } on FirebaseAuthException catch (e) {
91
+ if (e.code == 'weak-password') {
92
+ print('The password provided is too weak.');
93
+ } else if (e.code == 'email-already-in-use') {
94
+ print('The account already exists for that email.');
95
+ }
96
+ } catch (e) {
97
+ print(e);
98
+ }
99
+ ```
100
+
101
+ **Sign in:**
102
+
103
+ ```dart
104
+ try {
105
+ final credential = await FirebaseAuth.instance.signInWithEmailAndPassword(
106
+ email: emailAddress,
107
+ password: password,
108
+ );
109
+ } on FirebaseAuthException catch (e) {
110
+ if (e.code == 'user-not-found') {
111
+ print('No user found for that email.');
112
+ } else if (e.code == 'wrong-password') {
113
+ print('Wrong password provided for that user.');
114
+ }
115
+ }
116
+ ```
117
+
118
+ - Verify the user's email address after account creation.
119
+ - Firebase rate-limits new email/password sign-ups from the same IP to protect against abuse.
120
+ - On iOS/macOS, authentication state persists between app re-installs via the system keychain.
121
+
122
+ ---
123
+
124
+ ## 4. Social Authentication
125
+
126
+ **Google Sign-In (native platforms):**
127
+
128
+ ```dart
129
+ Future<UserCredential> signInWithGoogle() async {
130
+ final GoogleSignInAccount? googleUser = await GoogleSignIn.instance.authenticate();
131
+ final GoogleSignInAuthentication googleAuth = googleUser.authentication;
132
+ final credential = GoogleAuthProvider.credential(idToken: googleAuth.idToken);
133
+ return await FirebaseAuth.instance.signInWithCredential(credential);
134
+ }
135
+ ```
136
+
137
+ **Google Sign-In (web):**
138
+
139
+ ```dart
140
+ Future<UserCredential> signInWithGoogle() async {
141
+ GoogleAuthProvider googleProvider = GoogleAuthProvider();
142
+ googleProvider.addScope('https://www.googleapis.com/auth/contacts.readonly');
143
+ googleProvider.setCustomParameters({'login_hint': 'user@example.com'});
144
+ return await FirebaseAuth.instance.signInWithPopup(googleProvider);
145
+ }
146
+ ```
147
+
148
+ - Configure platform-specific settings for each provider (e.g., SHA1 key for Google Sign-In on Android).
149
+ - If a user signs in with a social provider after registering with the same email manually, Firebase's trusted provider concept will automatically change their authentication provider.
150
+
151
+ ---
152
+
153
+ ## 5. Error Handling
154
+
155
+ - Always use `try-catch` with `FirebaseAuthException`.
156
+ - Check `e.code` to identify specific error types.
157
+ - Handle `account-exists-with-different-credential` by fetching sign-in methods for the email and guiding users through the correct flow.
158
+ - Handle `too-many-requests` with retry logic or user feedback.
159
+ - Handle `operation-not-allowed` by ensuring the provider is enabled in the Firebase console.
160
+
161
+ ---
162
+
163
+ ## 6. User Management
164
+
165
+ ```dart
166
+ // Update profile
167
+ await FirebaseAuth.instance.currentUser?.updateProfile(
168
+ displayName: "Jane Q. User",
169
+ photoURL: "https://example.com/jane-q-user/profile.jpg",
170
+ );
171
+
172
+ // Update email (sends verification to new address first)
173
+ await user?.verifyBeforeUpdateEmail("newemail@example.com");
174
+ ```
175
+
176
+ - Use `verifyBeforeUpdateEmail()` — **not** `updateEmail()` — to change a user's email. The email only updates after the user verifies it.
177
+ - Store only essential info in the auth profile; use a database for additional user data.
178
+ - Use `linkWithCredential()` to connect multiple auth providers to a single account.
179
+ - Verify the user's identity before linking new credentials.
180
+ - Use `fetchSignInMethodsForEmail()` when handling account linking.
181
+
182
+ ---
183
+
184
+ ## 7. Security Best Practices
185
+
186
+ - Never store sensitive authentication credentials in client-side code.
187
+ - Monitor auth state changes for proper session management.
188
+ - Validate user input before submitting authentication requests to prevent injection attacks.
189
+ - Call `FirebaseAuth.instance.signOut()` when users exit the app.
190
+ - For sensitive operations, re-authenticate users with `reauthenticateWithCredential()`.
191
+ - Enforce strong password policies for email/password auth.
192
+ - In Realtime Database and Cloud Storage Security Rules, use the `auth` variable to get the signed-in user's UID for access control.
193
+ - Use multi-factor authentication for sensitive applications.
194
+
195
+ ---
196
+
197
+ ## 8. Multi-Factor Authentication
198
+
199
+ > **Security warning:** Avoid SMS-based MFA. SMS is insecure and easy to compromise or spoof.
200
+
201
+ > **Platform limitation:** Windows does not support MFA. MFA with multiple tenants is not supported on Flutter.
202
+
203
+ - Enable at least one MFA-compatible provider before implementing MFA.
204
+
205
+ ---
206
+
207
+ ## 9. Email Link Authentication
208
+
209
+ > **Important:** Firebase Dynamic Links is deprecated for email link authentication. Firebase Hosting is now used to send sign-in links.
210
+
211
+ - Set `handleCodeInApp: true` in `ActionCodeSettings` — sign-in must always be completed in the app.
212
+ - Store the user's email locally (e.g., `SharedPreferences`) when sending the sign-in link.
213
+ - **Never** pass the user's email in redirect URL parameters — this enables session injection attacks.
214
+ - Use HTTPS URLs in production to prevent link interception.
215
+ - Configure the app to detect incoming links and parse the underlying deep link for sign-in completion.
216
+
217
+ ---
218
+
219
+ ## References
220
+
221
+ - [Firebase Authentication Flutter documentation](https://firebase.google.com/docs/auth/flutter/start)
222
+ - [Email/password authentication](https://firebase.google.com/docs/auth/flutter/password-auth)
223
+ - [Federated identity & social sign-in](https://firebase.google.com/docs/auth/flutter/federated-auth)
224
+ - [Multi-factor authentication](https://firebase.google.com/docs/auth/flutter/multi-factor)
@@ -0,0 +1,165 @@
1
+ ---
2
+ name: firebase-cloud-firestore
3
+ description: Integrates Cloud Firestore into Flutter apps. Use when setting up Firestore, designing document/collection structure, reading and writing data, working with real-time listeners, designing for scale, or applying security rules.
4
+ routing: manual
5
+ stacks: [flutter]
6
+ source: https://github.com/evanca/flutter-ai-rules
7
+ license: MIT
8
+ ---
9
+
10
+ # Firebase Cloud Firestore Skill
11
+
12
+ This skill defines how to correctly use Cloud Firestore in Flutter applications.
13
+
14
+ ## When to Use
15
+
16
+ Use this skill when:
17
+
18
+ * Setting up and configuring Cloud Firestore in a Flutter project.
19
+ * Designing document and collection structure.
20
+ * Performing read, write, or real-time listener operations.
21
+ * Optimizing for scale and avoiding hotspots.
22
+ * Applying Firestore security rules.
23
+
24
+ ---
25
+
26
+ ## 1. Database Selection
27
+
28
+ Choose **Cloud Firestore** when your app needs:
29
+ - Rich, hierarchical data models with subcollections.
30
+ - Complex queries: chaining filters, combining filtering and sorting on a property.
31
+ - Transactions that atomically read and write data from any part of the database.
32
+ - High availability (typical uptime 99.999%) or critical-level reliability.
33
+ - Scalability.
34
+
35
+ Use **Realtime Database** instead for simple data models requiring simple lookups and extremely low-latency synchronization (typical response times under 10ms).
36
+
37
+ ---
38
+
39
+ ## 2. Setup and Configuration
40
+
41
+ ```
42
+ flutter pub add cloud_firestore
43
+ ```
44
+
45
+ ```dart
46
+ import 'package:cloud_firestore/cloud_firestore.dart';
47
+
48
+ final db = FirebaseFirestore.instance; // after Firebase.initializeApp()
49
+ ```
50
+
51
+ **Location:**
52
+ - Select the database location closest to your users and compute resources.
53
+ - Use **multi-region** locations for critical apps (maximum availability and durability).
54
+ - Use **regional** locations for lower costs and lower write latency for latency-sensitive apps.
55
+
56
+ **iOS/macOS:** Consider pre-compiled frameworks to improve build times:
57
+ ```ruby
58
+ pod 'FirebaseFirestore',
59
+ :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git',
60
+ :tag => 'IOS_SDK_VERSION'
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 3. Document Structure
66
+
67
+ - Avoid document IDs `.` and `..` (special meaning in Firestore paths).
68
+ - Avoid forward slashes (`/`) in document IDs (path separators).
69
+ - **Do not** use monotonically increasing document IDs (e.g., `Customer1`, `Customer2`) — causes write hotspots.
70
+ - Use Firestore's **automatic document IDs** when possible:
71
+
72
+ ```dart
73
+ db.collection("users").add(user).then((DocumentReference doc) =>
74
+ print('DocumentSnapshot added with ID: ${doc.id}'));
75
+ ```
76
+
77
+ - Avoid these characters in field names (require extra escaping): `.` `[` `]` `*` `` ` ``
78
+ - Use **subcollections** within documents to organize complex, hierarchical data rather than deeply nested objects.
79
+
80
+ ---
81
+
82
+ ## 4. Indexing
83
+
84
+ - Set **collection-level index exemptions** to reduce write latency and storage costs.
85
+ - Disable Descending & Array indexing for fields that don't need them.
86
+ - Exempt string fields with long values that aren't used for querying.
87
+ - Exempt fields with sequential values (e.g., timestamps) from indexing if not used in queries — avoids the 500 writes/second index limit.
88
+ - Add single-field exemptions for TTL fields.
89
+ - Exempt large array or map fields not used in queries — avoids the 40,000 index entries per document limit.
90
+ - Firestore queries are indexed by default; query performance is proportional to the result set size, not the dataset size.
91
+
92
+ ---
93
+
94
+ ## 5. Read and Write Operations
95
+
96
+ - **Always use asynchronous calls** to minimize latency impact:
97
+
98
+ ```dart
99
+ await db.collection("users").get().then((event) {
100
+ for (var doc in event.docs) {
101
+ print("${doc.id} => ${doc.data()}");
102
+ }
103
+ });
104
+ ```
105
+
106
+ - **Do not use offsets for pagination** — use cursors instead to avoid retrieving and being billed for skipped documents.
107
+ - Implement **transaction retries** when accessing Firestore directly through REST or RPC APIs.
108
+ - For writing a large number of documents, use a **bulk writer** instead of the atomic batch writer.
109
+ - Execute independent operations (e.g., a document lookup and a query) **in parallel**, not sequentially.
110
+ - Firestore queries are **shallow**: they only return documents in a specific collection or collection group, not subcollection data.
111
+ - Be aware of write rate limits: ~1 write per second per document.
112
+
113
+ ---
114
+
115
+ ## 6. Designing for Scale
116
+
117
+ - Avoid high read or write rates to **lexicographically close documents** (hotspotting).
118
+ - Avoid creating new documents with **monotonically increasing fields** (like timestamps) at a very high rate.
119
+ - Avoid **deleting documents** in a collection at a high rate.
120
+ - **Gradually increase traffic** when writing to the database at a high rate.
121
+ - Avoid queries that skip over recently deleted data — use `start_at` to find the correct start point.
122
+ - Distribute writes across different document paths to avoid contention.
123
+ - Firestore scales automatically to ~1 million concurrent connections and 10,000 writes/second.
124
+
125
+ ---
126
+
127
+ ## 7. Real-time Updates
128
+
129
+ - **Limit** the number of simultaneous real-time listeners.
130
+ - **Detach listeners** when they are no longer needed:
131
+
132
+ ```dart
133
+ final subscription = db.collection("users")
134
+ .snapshots()
135
+ .listen((event) {
136
+ // Handle the data
137
+ });
138
+
139
+ // When no longer needed:
140
+ subscription.cancel();
141
+ ```
142
+
143
+ - Use **compound queries** to filter data server-side rather than filtering on the client.
144
+ - For large collections, use queries to limit the data being listened to — never listen to an entire large collection.
145
+ - For presence functionality (online/offline status), implement custom presence solutions as described in Firebase documentation.
146
+
147
+ ---
148
+
149
+ ## 8. Security
150
+
151
+ - Always use **Firebase Security Rules** to protect Firestore data.
152
+ - **Validate user input** before submitting to Firestore to prevent injection attacks.
153
+ - Use **transactions** for operations that require atomic updates to multiple documents.
154
+ - Implement proper **error handling** for all Firestore operations.
155
+ - Never store sensitive information in Firestore without proper access controls.
156
+ - Security rules **do not cascade** unless you use a wildcard.
157
+ - If a query's results might contain data the user doesn't have access to, **the entire query fails**.
158
+
159
+ ---
160
+
161
+ ## References
162
+
163
+ - [Cloud Firestore Flutter documentation](https://firebase.google.com/docs/firestore/quickstart?hl=en&authuser=0&platform=flutter)
164
+ - [Cloud Firestore best practices](https://firebase.google.com/docs/firestore/best-practices)
165
+ - [Cloud Firestore security rules](https://firebase.google.com/docs/firestore/security/get-started)
@@ -0,0 +1,148 @@
1
+ ---
2
+ name: firebase-cloud-functions
3
+ description: Calls Firebase Cloud Functions from Flutter apps. Use when setting up callable functions, passing data to functions, handling errors from function calls, optimizing performance, or testing with the Firebase Emulator Suite.
4
+ routing: manual
5
+ stacks: [flutter]
6
+ source: https://github.com/evanca/flutter-ai-rules
7
+ license: MIT
8
+ ---
9
+
10
+ # Firebase Cloud Functions Skill
11
+
12
+ This skill defines how to correctly call Firebase Cloud Functions from Flutter applications.
13
+
14
+ ## When to Use
15
+
16
+ Use this skill when:
17
+
18
+ * Setting up and configuring Cloud Functions in a Flutter project.
19
+ * Calling callable functions and handling their results.
20
+ * Handling errors from function calls.
21
+ * Optimizing function call performance.
22
+ * Testing with the Firebase Emulator Suite.
23
+
24
+ ---
25
+
26
+ ## 1. Setup and Configuration
27
+
28
+ ```
29
+ flutter pub add cloud_functions
30
+ ```
31
+
32
+ ```dart
33
+ import 'package:cloud_functions/cloud_functions.dart';
34
+
35
+ // After Firebase.initializeApp():
36
+ final functions = FirebaseFunctions.instance;
37
+ ```
38
+
39
+ - Initialize Firebase before using any Cloud Functions features.
40
+ - For region-specific deployments, specify the region when getting the instance.
41
+ - Deploy callable functions to Firebase **before** attempting to call them from your Flutter app.
42
+ - Consider implementing **App Check** to prevent abuse of your Cloud Functions.
43
+
44
+ ---
45
+
46
+ ## 2. Calling Functions
47
+
48
+ Use `httpsCallable` to reference a function, then `call` to invoke it:
49
+
50
+ ```dart
51
+ final result = await FirebaseFunctions.instance
52
+ .httpsCallable('functionName')
53
+ .call(data);
54
+ ```
55
+
56
+ - Pass data as a `Map` — it is automatically serialized to JSON:
57
+
58
+ ```dart
59
+ final result = await FirebaseFunctions.instance
60
+ .httpsCallable('addMessage')
61
+ .call({
62
+ "text": messageText,
63
+ "push": true,
64
+ });
65
+ ```
66
+
67
+ - Access the result via the `data` property — it is automatically deserialized from JSON:
68
+
69
+ ```dart
70
+ final responseData = result.data;
71
+ // Cast to expected type if needed:
72
+ final responseString = result.data as String;
73
+ ```
74
+
75
+ - **Do not** pass authentication tokens in function parameters — they are automatically included by the SDK.
76
+ - Keep function names consistent between client code and server-side implementations.
77
+
78
+ ---
79
+
80
+ ## 3. Error Handling
81
+
82
+ Always wrap function calls in `try-catch` and check for `FirebaseFunctionsException`:
83
+
84
+ ```dart
85
+ try {
86
+ final result = await FirebaseFunctions.instance
87
+ .httpsCallable('functionName')
88
+ .call(data);
89
+ // Handle successful result
90
+ } catch (e) {
91
+ if (e is FirebaseFunctionsException) {
92
+ print('Error code: ${e.code}');
93
+ print('Error message: ${e.message}');
94
+ print('Error details: ${e.details}');
95
+ } else {
96
+ print('Error: $e');
97
+ }
98
+ }
99
+ ```
100
+
101
+ - Handle network connectivity issues and timeouts appropriately.
102
+ - Provide meaningful error messages to users when function calls fail.
103
+ - Consider implementing retry logic for transient errors.
104
+
105
+ ---
106
+
107
+ ## 4. Performance Optimization
108
+
109
+ Set a timeout appropriate to the expected execution time:
110
+
111
+ ```dart
112
+ final callable = FirebaseFunctions.instance.httpsCallable(
113
+ 'functionName',
114
+ options: HttpsCallableOptions(
115
+ timeout: const Duration(seconds: 30),
116
+ ),
117
+ );
118
+ ```
119
+
120
+ - Minimize the amount of data passed to and from functions to reduce latency.
121
+ - Use batch operations when possible to reduce the number of function calls.
122
+ - Consider client-side caching for frequently used function results.
123
+ - Monitor function performance in the Firebase Console to identify bottlenecks.
124
+ - Account for **cold starts** for infrequently used functions.
125
+ - Implement proper loading states in the UI while waiting for function responses.
126
+
127
+ ---
128
+
129
+ ## 5. Testing and Development
130
+
131
+ Use the Firebase Emulator Suite for local development and testing:
132
+
133
+ ```dart
134
+ FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);
135
+ ```
136
+
137
+ - Test functions with both valid and invalid inputs to ensure proper validation.
138
+ - Verify that functions handle authentication correctly.
139
+ - Test with different user roles and permissions to ensure proper access control.
140
+ - Implement unit tests for client-side function calling logic.
141
+ - Use integration tests to verify end-to-end function behavior.
142
+
143
+ ---
144
+
145
+ ## References
146
+
147
+ - [Cloud Functions for Firebase Flutter documentation](https://firebase.google.com/docs/functions/callable?platform=flutter)
148
+ - [Firebase Emulator Suite](https://firebase.google.com/docs/emulator-suite)