From 7d14185e5884125b6e4993494cb50e6c62d5ba7a Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:17:27 -0400 Subject: [PATCH 1/6] add increment sample --- .../https-increment-number/.gitignore | 5 + .../https-increment-number/README.md | 56 +++++++++ .../https-increment-number/bin/server.dart | 107 ++++++++++++++++++ .../https-increment-number/firebase.json | 6 + .../https-increment-number/functions.yaml | 23 ++++ .../https-increment-number/pubspec.yaml | 38 +++++++ 6 files changed, 235 insertions(+) create mode 100644 Dart/quickstarts/https-increment-number/.gitignore create mode 100644 Dart/quickstarts/https-increment-number/README.md create mode 100644 Dart/quickstarts/https-increment-number/bin/server.dart create mode 100644 Dart/quickstarts/https-increment-number/firebase.json create mode 100644 Dart/quickstarts/https-increment-number/functions.yaml create mode 100644 Dart/quickstarts/https-increment-number/pubspec.yaml diff --git a/Dart/quickstarts/https-increment-number/.gitignore b/Dart/quickstarts/https-increment-number/.gitignore new file mode 100644 index 0000000000..8ae1a6ef6d --- /dev/null +++ b/Dart/quickstarts/https-increment-number/.gitignore @@ -0,0 +1,5 @@ +.dart_tool/ +.packages +build/ +*.dart_tool +pubspec.lock diff --git a/Dart/quickstarts/https-increment-number/README.md b/Dart/quickstarts/https-increment-number/README.md new file mode 100644 index 0000000000..a1ffb9ac0d --- /dev/null +++ b/Dart/quickstarts/https-increment-number/README.md @@ -0,0 +1,56 @@ +# HTTPS Increment Number Quickstart + +This quickstart demonstrates how to handle HTTP requests for Cloud Functions using Dart. +It features two endpoints: +- `incrementLocal`: Simple POST request that takes a local count and returns it incremented by 1. +- `incrementSynced`: GET and POST endpoints that sync a counter variable to Firestore, returning the newly updated count. + +## Prerequisites + +1. Add your Firebase project to this Quickstart: + ```bash + firebase use --add + ``` +2. Enable Firestore in the Firebase Console and configure the emulator for local testing. + +## Local Testing + +First, fetch dependencies: +```bash +dart pub get +``` + +Then, you can use the Firebase CLI to test the function: +```bash +firebase emulators:start --only functions +``` + +Note: To test `incrementSynced`, ensure you also start the Firestore emulator: `firebase emulators:start --only functions,firestore`. + +### Testing `incrementLocal` + +In a separate terminal, use cURL to POST to the function (replace the URL with the one provided by the emulator): + +```bash +curl -X POST http://127.0.0.1:5001/YOUR_PROJECT/us-central1/increment-local \ + -H "Content-Type: application/json" \ + -d '{"count": 5}' +``` + +You should see: +```json +{"message":"Local increment complete!","newCount":6} +``` + +### Testing `incrementSynced` + +To test using Firestore, fetch the initial count: +```bash +curl -X GET http://127.0.0.1:5001/YOUR_PROJECT/us-central1/increment-synced +``` + +Then increment it using POST: +```bash +curl -X POST http://127.0.0.1:5001/YOUR_PROJECT/us-central1/increment-synced \ + -H "Content-Type: application/json" +``` diff --git a/Dart/quickstarts/https-increment-number/bin/server.dart b/Dart/quickstarts/https-increment-number/bin/server.dart new file mode 100644 index 0000000000..abac619d8a --- /dev/null +++ b/Dart/quickstarts/https-increment-number/bin/server.dart @@ -0,0 +1,107 @@ +import 'dart:convert'; +import 'package:dart_firebase_admin/dart_firebase_admin.dart'; +import 'package:firebase_functions/firebase_functions.dart'; +import 'package:google_cloud_firestore/google_cloud_firestore.dart'; + +const incrementCallable = 'incrementSynced'; + +class IncrementResponse { + final String message; + final int newCount; + + IncrementResponse({required this.message, required this.newCount}); + + Map toJson() => { + 'message': message, + 'newCount': newCount, + }; +} + +void main(List args) async { + // Get firestore admin instance + final firestore = FirebaseApp.instance.firestore(); + + await fireUp(args, (firebase) { + + // [START dartHttpIncrementLocal] + firebase.https.onRequest(name: 'incrementLocal', (request) async { + print('Incrementing counter locally...'); + + if (request.method != 'POST') { + return Response(405, body: 'Method Not Allowed'); + } + + int currentCount = 0; + final bodyString = await request.readAsString(); + if (bodyString.isNotEmpty) { + try { + final body = jsonDecode(bodyString) as Map; + currentCount = body['count'] as int? ?? 0; + } catch (e) { + return Response.badRequest(body: 'Invalid JSON request'); + } + } + + final response = IncrementResponse( + message: 'Local increment complete!', + newCount: currentCount + 1, + ); + + return Response( + 200, + body: jsonEncode(response.toJson()), + headers: {'Content-Type': 'application/json'}, + ); + }); + // [END dartHttpIncrementLocal] + + // [START dartHttpIncrementSynced] + firebase.https.onRequest(name: incrementCallable, (request) async { + print('Processing synced counter request...'); + + // Get a reference to the counter document + final counterDoc = firestore.collection('counters').doc('global'); + + if (request.method == 'GET') { + // Handle GET request to read the current counter + final snapshot = await counterDoc.get(); + final currentCount = snapshot.data()?['count'] as int? ?? 0; + + final response = IncrementResponse( + message: 'Cloud-sync fetched!', + newCount: currentCount, + ); + + return Response( + 200, + body: jsonEncode(response.toJson()), + headers: {'Content-Type': 'application/json'}, + ); + } else if (request.method == 'POST') { + // Handle POST request to increment the counter + final snapshot = await counterDoc.get(); + final currentCount = snapshot.data()?['count'] as int? ?? 0; + + // Increment count by one + await counterDoc.set({ + 'count': FieldValue.increment(1), + }, options: SetOptions.merge()); + + final response = IncrementResponse( + message: 'Cloud-sync complete!', + newCount: currentCount + 1, + ); + + return Response( + 200, + body: jsonEncode(response.toJson()), + headers: {'Content-Type': 'application/json'}, + ); + } else { + return Response(405, body: 'Method Not Allowed'); + } + }); + // [END dartHttpIncrementSynced] + + }); +} diff --git a/Dart/quickstarts/https-increment-number/firebase.json b/Dart/quickstarts/https-increment-number/firebase.json new file mode 100644 index 0000000000..2d344ac70f --- /dev/null +++ b/Dart/quickstarts/https-increment-number/firebase.json @@ -0,0 +1,6 @@ +{ + "functions": { + "source": ".", + "codebase": "dart-quickstarts-https-increment-number" + } +} diff --git a/Dart/quickstarts/https-increment-number/functions.yaml b/Dart/quickstarts/https-increment-number/functions.yaml new file mode 100644 index 0000000000..05776f93ef --- /dev/null +++ b/Dart/quickstarts/https-increment-number/functions.yaml @@ -0,0 +1,23 @@ +specVersion: v1alpha1 +requiredAPIs: + - api: cloudfunctions.googleapis.com + reason: Required for Cloud Functions +endpoints: + increment-local: + platform: gcfv2 + region: + - us-central1 + httpsTrigger: {} + baseImageUri: us-central1-docker.pkg.dev/serverless-runtimes/google-24/runtimes/osonly24 + command: + - ./bin/server + entryPoint: increment-local + increment-synced: + platform: gcfv2 + region: + - us-central1 + httpsTrigger: {} + baseImageUri: us-central1-docker.pkg.dev/serverless-runtimes/google-24/runtimes/osonly24 + command: + - ./bin/server + entryPoint: increment-synced diff --git a/Dart/quickstarts/https-increment-number/pubspec.yaml b/Dart/quickstarts/https-increment-number/pubspec.yaml new file mode 100644 index 0000000000..0c28ce128e --- /dev/null +++ b/Dart/quickstarts/https-increment-number/pubspec.yaml @@ -0,0 +1,38 @@ +name: https_increment_number +description: HTTPS trigger examples showcasing state increment operations. +publish_to: none + +environment: + sdk: ^3.11.0 + +dependencies: + firebase_functions: + git: + url: https://github.com/firebase/firebase-functions-dart + ref: main + dart_firebase_admin: + git: + url: https://github.com/firebase/firebase-admin-dart + path: packages/dart_firebase_admin + ref: main + google_cloud_firestore: + git: + url: https://github.com/firebase/firebase-admin-dart + path: packages/google_cloud_firestore + ref: main + +dev_dependencies: + build_runner: ^2.10.5 + lints: ^6.0.0 + +dependency_overrides: + dart_firebase_admin: + git: + url: https://github.com/firebase/firebase-admin-dart + path: packages/dart_firebase_admin + ref: main + google_cloud_firestore: + git: + url: https://github.com/firebase/firebase-admin-dart + path: packages/google_cloud_firestore + ref: main From 72fc89a2f2880965dd05ba84d62c8627f8eba07e Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:18:51 -0400 Subject: [PATCH 2/6] remove autogenerated file --- .../https-increment-number/functions.yaml | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 Dart/quickstarts/https-increment-number/functions.yaml diff --git a/Dart/quickstarts/https-increment-number/functions.yaml b/Dart/quickstarts/https-increment-number/functions.yaml deleted file mode 100644 index 05776f93ef..0000000000 --- a/Dart/quickstarts/https-increment-number/functions.yaml +++ /dev/null @@ -1,23 +0,0 @@ -specVersion: v1alpha1 -requiredAPIs: - - api: cloudfunctions.googleapis.com - reason: Required for Cloud Functions -endpoints: - increment-local: - platform: gcfv2 - region: - - us-central1 - httpsTrigger: {} - baseImageUri: us-central1-docker.pkg.dev/serverless-runtimes/google-24/runtimes/osonly24 - command: - - ./bin/server - entryPoint: increment-local - increment-synced: - platform: gcfv2 - region: - - us-central1 - httpsTrigger: {} - baseImageUri: us-central1-docker.pkg.dev/serverless-runtimes/google-24/runtimes/osonly24 - command: - - ./bin/server - entryPoint: increment-synced From 33edd23350a505c18f6fd56039874b7064868852 Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:27:09 -0400 Subject: [PATCH 3/6] test in emulator --- .gitignore | 2 ++ Dart/quickstarts/https-increment-number/bin/server.dart | 6 +++--- Dart/quickstarts/https-increment-number/firebase.json | 3 +++ Dart/quickstarts/https-increment-number/firestore.rules | 8 ++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 Dart/quickstarts/https-increment-number/firestore.rules diff --git a/.gitignore b/.gitignore index 127eafecb4..9535b26697 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ **/.firebase **/.firebaserc **/.runtimeconfig.json +**/functions.yaml +**/firestore-debug.log */npm-debug.log lerna-debug.log *~ diff --git a/Dart/quickstarts/https-increment-number/bin/server.dart b/Dart/quickstarts/https-increment-number/bin/server.dart index abac619d8a..6d41d41bb4 100644 --- a/Dart/quickstarts/https-increment-number/bin/server.dart +++ b/Dart/quickstarts/https-increment-number/bin/server.dart @@ -18,9 +18,6 @@ class IncrementResponse { } void main(List args) async { - // Get firestore admin instance - final firestore = FirebaseApp.instance.firestore(); - await fireUp(args, (firebase) { // [START dartHttpIncrementLocal] @@ -59,6 +56,9 @@ void main(List args) async { firebase.https.onRequest(name: incrementCallable, (request) async { print('Processing synced counter request...'); + // Get firestore admin instance + final firestore = FirebaseApp.instance.firestore(); + // Get a reference to the counter document final counterDoc = firestore.collection('counters').doc('global'); diff --git a/Dart/quickstarts/https-increment-number/firebase.json b/Dart/quickstarts/https-increment-number/firebase.json index 2d344ac70f..e155cc8e57 100644 --- a/Dart/quickstarts/https-increment-number/firebase.json +++ b/Dart/quickstarts/https-increment-number/firebase.json @@ -2,5 +2,8 @@ "functions": { "source": ".", "codebase": "dart-quickstarts-https-increment-number" + }, + "firestore": { + "rules": "firestore.rules" } } diff --git a/Dart/quickstarts/https-increment-number/firestore.rules b/Dart/quickstarts/https-increment-number/firestore.rules new file mode 100644 index 0000000000..0e33c9c2d4 --- /dev/null +++ b/Dart/quickstarts/https-increment-number/firestore.rules @@ -0,0 +1,8 @@ +rules_version = '2'; +service cloud.firestore { + match /databases/{database}/documents { + match /{document=**} { + allow read: if true; + } + } +} From 30f20c442e2702f1dc7e9bb15755a529815f3449 Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:34:15 -0400 Subject: [PATCH 4/6] use demo-example --- .../https-increment-number/README.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Dart/quickstarts/https-increment-number/README.md b/Dart/quickstarts/https-increment-number/README.md index a1ffb9ac0d..a84020417d 100644 --- a/Dart/quickstarts/https-increment-number/README.md +++ b/Dart/quickstarts/https-increment-number/README.md @@ -5,13 +5,7 @@ It features two endpoints: - `incrementLocal`: Simple POST request that takes a local count and returns it incremented by 1. - `incrementSynced`: GET and POST endpoints that sync a counter variable to Firestore, returning the newly updated count. -## Prerequisites -1. Add your Firebase project to this Quickstart: - ```bash - firebase use --add - ``` -2. Enable Firestore in the Firebase Console and configure the emulator for local testing. ## Local Testing @@ -20,19 +14,17 @@ First, fetch dependencies: dart pub get ``` -Then, you can use the Firebase CLI to test the function: +Then, you can use the Firebase CLI to test the function locally. To ensure both endpoints work properly, make sure to start both the functions and firestore emulators: ```bash -firebase emulators:start --only functions +firebase emulators:start --project="demo-example" --only firestore,functions ``` -Note: To test `incrementSynced`, ensure you also start the Firestore emulator: `firebase emulators:start --only functions,firestore`. - ### Testing `incrementLocal` In a separate terminal, use cURL to POST to the function (replace the URL with the one provided by the emulator): ```bash -curl -X POST http://127.0.0.1:5001/YOUR_PROJECT/us-central1/increment-local \ +curl -X POST http://127.0.0.1:5001/demo-example/us-central1/increment-local \ -H "Content-Type: application/json" \ -d '{"count": 5}' ``` @@ -46,11 +38,11 @@ You should see: To test using Firestore, fetch the initial count: ```bash -curl -X GET http://127.0.0.1:5001/YOUR_PROJECT/us-central1/increment-synced +curl -X GET http://127.0.0.1:5001/demo-example/us-central1/increment-synced ``` Then increment it using POST: ```bash -curl -X POST http://127.0.0.1:5001/YOUR_PROJECT/us-central1/increment-synced \ +curl -X POST http://127.0.0.1:5001/demo-example/us-central1/increment-synced \ -H "Content-Type: application/json" ``` From 5c40153ee7465d6be79becf5200ae6e3908dce97 Mon Sep 17 00:00:00 2001 From: Jeff Huleatt <3759507+jhuleatt@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:38:24 -0400 Subject: [PATCH 5/6] refine --- .../https-increment-number/bin/server.dart | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Dart/quickstarts/https-increment-number/bin/server.dart b/Dart/quickstarts/https-increment-number/bin/server.dart index 6d41d41bb4..c5699ddc47 100644 --- a/Dart/quickstarts/https-increment-number/bin/server.dart +++ b/Dart/quickstarts/https-increment-number/bin/server.dart @@ -3,23 +3,17 @@ import 'package:dart_firebase_admin/dart_firebase_admin.dart'; import 'package:firebase_functions/firebase_functions.dart'; import 'package:google_cloud_firestore/google_cloud_firestore.dart'; -const incrementCallable = 'incrementSynced'; - class IncrementResponse { final String message; final int newCount; IncrementResponse({required this.message, required this.newCount}); - Map toJson() => { - 'message': message, - 'newCount': newCount, - }; + Map toJson() => {'message': message, 'newCount': newCount}; } void main(List args) async { await fireUp(args, (firebase) { - // [START dartHttpIncrementLocal] firebase.https.onRequest(name: 'incrementLocal', (request) async { print('Incrementing counter locally...'); @@ -53,7 +47,7 @@ void main(List args) async { // [END dartHttpIncrementLocal] // [START dartHttpIncrementSynced] - firebase.https.onRequest(name: incrementCallable, (request) async { + firebase.https.onRequest(name: 'incrementSynced', (request) async { print('Processing synced counter request...'); // Get firestore admin instance @@ -62,11 +56,12 @@ void main(List args) async { // Get a reference to the counter document final counterDoc = firestore.collection('counters').doc('global'); - if (request.method == 'GET') { - // Handle GET request to read the current counter - final snapshot = await counterDoc.get(); - final currentCount = snapshot.data()?['count'] as int? ?? 0; + // Fetch the current counter value + final snapshot = await counterDoc.get(); + final currentCount = snapshot.data()?['count'] as int? ?? 0; + if (request.method == 'GET') { + // Handle GET request to respond with the current counter final response = IncrementResponse( message: 'Cloud-sync fetched!', newCount: currentCount, @@ -79,8 +74,6 @@ void main(List args) async { ); } else if (request.method == 'POST') { // Handle POST request to increment the counter - final snapshot = await counterDoc.get(); - final currentCount = snapshot.data()?['count'] as int? ?? 0; // Increment count by one await counterDoc.set({ @@ -102,6 +95,5 @@ void main(List args) async { } }); // [END dartHttpIncrementSynced] - }); } From 2ebee4de9b1bd62bbaefe0cd6b20b6def78fadf3 Mon Sep 17 00:00:00 2001 From: Jeff <3759507+jhuleatt@users.noreply.github.com> Date: Fri, 10 Apr 2026 13:33:50 -0400 Subject: [PATCH 6/6] Refactor Dart counter sample to use a shared package (#1267) - Created a new `shared` package to hold `IncrementResponse` and `incrementCallable`. - Updated `https-increment-number/pubspec.yaml` to depend on the `shared` package. - Replaced `https-increment-number/bin/server.dart` with updated user code, fixing syntax errors. - Added appropriate `.gitignore` files to exclude generated Dart tooling and locks. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- .../https-increment-number/bin/server.dart | 130 +++++++----------- .../https-increment-number/pubspec.yaml | 2 + Dart/quickstarts/shared/.gitignore | 5 + Dart/quickstarts/shared/lib/shared.dart | 19 +++ Dart/quickstarts/shared/pubspec.yaml | 6 + 5 files changed, 80 insertions(+), 82 deletions(-) create mode 100644 Dart/quickstarts/shared/.gitignore create mode 100644 Dart/quickstarts/shared/lib/shared.dart create mode 100644 Dart/quickstarts/shared/pubspec.yaml diff --git a/Dart/quickstarts/https-increment-number/bin/server.dart b/Dart/quickstarts/https-increment-number/bin/server.dart index c5699ddc47..12f11c1dc5 100644 --- a/Dart/quickstarts/https-increment-number/bin/server.dart +++ b/Dart/quickstarts/https-increment-number/bin/server.dart @@ -1,99 +1,65 @@ import 'dart:convert'; -import 'package:dart_firebase_admin/dart_firebase_admin.dart'; import 'package:firebase_functions/firebase_functions.dart'; -import 'package:google_cloud_firestore/google_cloud_firestore.dart'; - -class IncrementResponse { - final String message; - final int newCount; - - IncrementResponse({required this.message, required this.newCount}); - - Map toJson() => {'message': message, 'newCount': newCount}; -} +import 'package:google_cloud_firestore/google_cloud_firestore.dart' + show FieldValue; +import 'package:shared/shared.dart'; void main(List args) async { await fireUp(args, (firebase) { - // [START dartHttpIncrementLocal] - firebase.https.onRequest(name: 'incrementLocal', (request) async { - print('Incrementing counter locally...'); - - if (request.method != 'POST') { - return Response(405, body: 'Method Not Allowed'); - } - - int currentCount = 0; - final bodyString = await request.readAsString(); - if (bodyString.isNotEmpty) { - try { - final body = jsonDecode(bodyString) as Map; - currentCount = body['count'] as int? ?? 0; - } catch (e) { - return Response.badRequest(body: 'Invalid JSON request'); - } - } - - final response = IncrementResponse( - message: 'Local increment complete!', - newCount: currentCount + 1, - ); - - return Response( - 200, - body: jsonEncode(response.toJson()), - headers: {'Content-Type': 'application/json'}, - ); - }); - // [END dartHttpIncrementLocal] + // Listen for calls to the http request and name defined in the shared package. + firebase.https.onRequest(name: incrementCallable, (request) async { + // In a production app, verify the user with request.auth?.uid here. + print('Incrementing counter on the server...'); - // [START dartHttpIncrementSynced] - firebase.https.onRequest(name: 'incrementSynced', (request) async { - print('Processing synced counter request...'); - - // Get firestore admin instance - final firestore = FirebaseApp.instance.firestore(); + // Get firestore database instance + final firestore = firebase.adminApp.firestore(); // Get a reference to the counter document final counterDoc = firestore.collection('counters').doc('global'); - // Fetch the current counter value + // Get the current snapshot for the count data final snapshot = await counterDoc.get(); - final currentCount = snapshot.data()?['count'] as int? ?? 0; - - if (request.method == 'GET') { - // Handle GET request to respond with the current counter - final response = IncrementResponse( - message: 'Cloud-sync fetched!', - newCount: currentCount, - ); - - return Response( - 200, - body: jsonEncode(response.toJson()), - headers: {'Content-Type': 'application/json'}, - ); - } else if (request.method == 'POST') { - // Handle POST request to increment the counter - - // Increment count by one - await counterDoc.set({ - 'count': FieldValue.increment(1), - }, options: SetOptions.merge()); - - final response = IncrementResponse( - message: 'Cloud-sync complete!', - newCount: currentCount + 1, - ); - return Response( - 200, - body: jsonEncode(response.toJson()), - headers: {'Content-Type': 'application/json'}, - ); + // Increment response we will send back + IncrementResponse incrementResponse; + + // Check for the current count and if the snapshot exists + if (snapshot.data() case {'count': int value} when snapshot.exists) { + if (request.method == 'GET') { + // Get the current result + incrementResponse = IncrementResponse( + success: true, + message: 'Read-only sync complete', + newCount: value, + ); + } else if (request.method == 'POST') { + // Increment count by one + final step = request.url.queryParameters['step'] as int? ?? 1; + await counterDoc.update({'count': FieldValue.increment(step)}); + incrementResponse = IncrementResponse( + success: true, + message: 'Atomic increment complete', + newCount: value + 1, + ); + } else { + return Response(405, body: 'Method Not Allowed'); + } } else { - return Response(405, body: 'Method Not Allowed'); + // Create a new document with a count of 1 + await counterDoc.set({'count': 1}); + incrementResponse = const IncrementResponse( + success: true, + message: 'Cloud-sync complete', + newCount: 1, + ); } + + // Return the response as JSON + return Response( + 200, + body: jsonEncode(incrementResponse.toJson()), + headers: {'Content-Type': 'application/json'}, + ); }); - // [END dartHttpIncrementSynced] }); } diff --git a/Dart/quickstarts/https-increment-number/pubspec.yaml b/Dart/quickstarts/https-increment-number/pubspec.yaml index 0c28ce128e..b18643ae2d 100644 --- a/Dart/quickstarts/https-increment-number/pubspec.yaml +++ b/Dart/quickstarts/https-increment-number/pubspec.yaml @@ -6,6 +6,8 @@ environment: sdk: ^3.11.0 dependencies: + shared: + path: ../shared firebase_functions: git: url: https://github.com/firebase/firebase-functions-dart diff --git a/Dart/quickstarts/shared/.gitignore b/Dart/quickstarts/shared/.gitignore new file mode 100644 index 0000000000..8ae1a6ef6d --- /dev/null +++ b/Dart/quickstarts/shared/.gitignore @@ -0,0 +1,5 @@ +.dart_tool/ +.packages +build/ +*.dart_tool +pubspec.lock diff --git a/Dart/quickstarts/shared/lib/shared.dart b/Dart/quickstarts/shared/lib/shared.dart new file mode 100644 index 0000000000..bfbc6405b4 --- /dev/null +++ b/Dart/quickstarts/shared/lib/shared.dart @@ -0,0 +1,19 @@ +class IncrementResponse { + final bool success; + final String message; + final int newCount; + + const IncrementResponse({ + required this.success, + required this.message, + required this.newCount, + }); + + Map toJson() => { + 'success': success, + 'message': message, + 'newCount': newCount, + }; +} + +const String incrementCallable = 'incrementSynced'; diff --git a/Dart/quickstarts/shared/pubspec.yaml b/Dart/quickstarts/shared/pubspec.yaml new file mode 100644 index 0000000000..be30da55fa --- /dev/null +++ b/Dart/quickstarts/shared/pubspec.yaml @@ -0,0 +1,6 @@ +name: shared +description: Shared classes. +publish_to: none + +environment: + sdk: ^3.11.0