This is a demo of a full stack application built with Dart and Flutter.
The frontend is a desktop Flutter app that sends a name that you enter to the backend and then displays the response (a greeting in various languages) in a snackbar (an ephemeral popup widget for displaying messages at the bottom of the page).
The backend is a Dart function app that was generated using the
Functions Framework for Dart. It serves an HTTP endpoint that accepts a
JSON-encoded request body and returns a JSON-encoded response body. For the
demo, the function is hosted on localhost and on Cloud Run, a fully
managed serverless platform on Google Cloud.
Change directory to backend.
cd backendYou can run the function on your local machine by entering:
dart run build_runner build --delete-conflicting-outputs
dart run bin/server.dart --port=8080 --target=functionIf you have make installed on your system, you can just enter:
make runOutput:
Listening on :8080For more details see backend/README.
If you have created a Google Cloud project and updated your local gcloud
configuration with the project ID, you can deploy the backend in a single step.
For example, assuming your project ID is dart-demo and you want
to deploy the function as a service called greeting, enter:
gcloud beta run deploy greeting --allow-unauthenticated --source=.Output:
Building using Dockerfile and deploying container to Cloud Run service [greeting] in project [dart-demo] region [us-central1]
✓ Building and deploying new service... Done.
✓ Uploading sources...
✓ Building Container... Logs are available at [https://console.cloud.google.com/cloud-build/builds/df7f07d1-d88b-4443-a2b1-bdfd3cdab15b?project=700116488077].
✓ Creating Revision... Revision deployment finished. Waiting for health check to begin.
✓ Routing traffic...
✓ Setting IAM Policy...
Done.
Service [greeting] revision [greeting-00001-yen] has been deployed and is
serving
100 percent of traffic.
Service URL: https://greeting-gpua4upw6q-uc.a.run.appThe function app endpoint is the Service URL printed on the last line.
See Quickstart: Cloud Run for details on setting up and using a Google Cloud project.
If you have curl installed on your system, you can enter the following:
URL=http://localhost:8080 # or your Cloud Run service URL
curl -X POST -H "content-type: application/json" -d '{ "name": "World" }' -w "\n" $URLOutput (example):
{"salutation":"Hello","name":"World"}Change directory to frontend.
cd frontendThe following assumes running on the macos desktop.
flutter run -d macosor
flutter run -d macos -t lib/main_dev.dartexport GREETING_URL={Cloud Run service URL}
flutter run -d macos -t lib/main_prod.dart