-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add deploy Dart on Firebase Functions codelab sample #1277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jhuleatt
wants to merge
5
commits into
dart-launch
Choose a base branch
from
add-codelab-dart-functions-4853368971760704869
base: dart-launch
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c06587
Add deploy Dart on Firebase Functions codelab sample
google-labs-jules[bot] c6fd5e4
Add deploy Dart on Firebase Functions codelab sample
google-labs-jules[bot] 62902c8
Fix Dart CI failure by skipping flutter projects
google-labs-jules[bot] 5ee1bb3
Update server.dart
rodydavis 5adb94a
Add deploy Dart on Firebase Functions codelab sample
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Miscellaneous | ||
| *.class | ||
| *.log | ||
| *.pyc | ||
| *.swp | ||
| .DS_Store | ||
| .atom/ | ||
| .build/ | ||
| .buildlog/ | ||
| .history | ||
| .svn/ | ||
| .swiftpm/ | ||
| migrate_working_dir/ | ||
|
|
||
| # IntelliJ related | ||
| *.iml | ||
| *.ipr | ||
| *.iws | ||
| .idea/ | ||
|
|
||
| # The .vscode folder contains launch configuration and tasks you configure in | ||
| # VS Code which you may wish to be included in version control, so this line | ||
| # is commented out by default. | ||
| #.vscode/ | ||
|
|
||
| # Flutter/Dart/Pub related | ||
| **/doc/api/ | ||
| **/ios/Flutter/.last_build_id | ||
| .dart_tool/ | ||
| .flutter-plugins-dependencies | ||
| .pub-cache/ | ||
| .pub/ | ||
| /build/ | ||
| /coverage/ | ||
|
|
||
| # Symbolication related | ||
| app.*.symbols | ||
|
|
||
| # Obfuscation related | ||
| app.*.map.json | ||
|
|
||
| # Android Studio will place build artifacts here | ||
| /android/app/debug | ||
| /android/app/profile | ||
| /android/app/release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Codelab Dart Functions | ||
|
|
||
| This project contains the source code for the "Deploy Dart on Firebase Functions" codelab. | ||
|
|
||
| See [the codelab](https://codelabs.developers.google.com/deploy-dart-on-firebase-functions) for full instructions. | ||
|
|
||
| ## Running locally | ||
|
|
||
| This uses the Firebase emulator suite to test without deploying. | ||
|
|
||
| 1. Ensure Firebase CLI is installed. | ||
| 2. Initialize emulators in the root of the project: `firebase init emulators` | ||
| 3. Start the emulators: `firebase emulators:start` | ||
| 4. Run the flutter application `flutter run`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # This file configures the analyzer, which statically analyzes Dart code to | ||
| # check for errors, warnings, and lints. | ||
| # | ||
| # The issues identified by the analyzer are surfaced in the UI of Dart-enabled | ||
| # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be | ||
| # invoked from the command line by running `flutter analyze`. | ||
|
|
||
| # The following line activates a set of recommended lints for Flutter apps, | ||
| # packages, and plugins designed to encourage good coding practices. | ||
| include: package:flutter_lints/flutter.yaml | ||
|
|
||
| linter: | ||
| # The lint rules applied to this project can be customized in the | ||
| # section below to disable rules from the `package:flutter_lints/flutter.yaml` | ||
| # included above or to enable additional rules. A list of all available lints | ||
| # and their documentation is published at https://dart.dev/lints. | ||
| # | ||
| # Instead of disabling a lint rule for the entire project in the | ||
| # section below, it can also be suppressed for a single line of code | ||
| # or a specific dart file by using the `// ignore: name_of_lint` and | ||
| # `// ignore_for_file: name_of_lint` syntax on the line or in the file | ||
| # producing the lint. | ||
| rules: | ||
| # avoid_print: false # Uncomment to disable the `avoid_print` rule | ||
| # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule | ||
|
|
||
| # Additional information about this file can be found at | ||
| # https://dart.dev/guides/language/analysis-options |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "functions": [ | ||
| { | ||
| "source": "functions", | ||
| "codebase": "dart-codelab-dart-functions", | ||
| "ignore": [ | ||
| "node_modules", | ||
| ".git", | ||
| "firebase-debug.log", | ||
| "firebase-debug.*.log", | ||
| "*.local" | ||
| ], | ||
| "predeploy": [ | ||
| "dart pub get --directory=\"$RESOURCE_DIR\"", | ||
| "dart run build_runner build --delete-conflicting-outputs --directory=\"$RESOURCE_DIR\"" | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import 'dart:convert'; | ||
| import 'package:firebase_functions/firebase_functions.dart'; | ||
| import 'package:google_cloud_firestore/google_cloud_firestore.dart' | ||
| show FieldValue; | ||
| import 'package:shared/shared.dart'; | ||
|
|
||
| void main(List<String> args) async { | ||
| await fireUp(args, (firebase) { | ||
|
|
||
| // 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. | ||
| // ignore: avoid_print | ||
| print('Incrementing counter on the server...'); | ||
|
|
||
| // Get firestore database instance | ||
| final firestore = firebase.adminApp.firestore(); | ||
|
|
||
| // Get a reference to the counter document | ||
| final counterDoc = firestore.collection('counters').doc('global'); | ||
|
|
||
| // Get the current snapshot for the count data | ||
| final snapshot = await counterDoc.get(); | ||
|
|
||
| // 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 + step, | ||
|
rodydavis marked this conversation as resolved.
|
||
| ); | ||
| } else { | ||
| throw FailedPreconditionError( | ||
| 'only GET and POST requests are allowed', | ||
| ); | ||
|
rodydavis marked this conversation as resolved.
|
||
| } | ||
| } else { | ||
| // 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'}, | ||
| ); | ||
| }); | ||
|
|
||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| targets: | ||
| $default: | ||
| sources: | ||
| - "bin/**" | ||
| - "lib/**" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.