Flutter SDKs for Firebase Data Connect

Flutter SDKs for Firebase Data Connect

Maneesh Tewani, Software Engineer

With Firebase Data Connect’s recent public preview launch, we’re excited to announce the launch of one of the most requested features: native Flutter SDKs for Data Connect! In this post, we’ll go over how to use them in your app.

What is Firebase Data Connect?

At Google I/O, we launched Firebase Data Connect, a backend-as-a-service powered by a Cloud SQL Postgres database that’s high performance, scalable, and secure. It utilizes GraphQL to provide users a way to define your data and the relationships between them, as well as interactions with your data.

Our existing offering provided Android, iOS, and Web support, and now we’re excited to announce a new set of SDKs for Flutter, written entirely in native Dart. With a new generated SDK, in a few lines of Flutter code, you get access to your Cloud SQL data with full type-safety included!

Instead of having to type out parseJsonToMyMovie(myOrm().select('title, genre, description').from('movies'));, all you have to do is call MoviesConnector.instance.listMovies(); and you’re good to go!

Can’t wait to try it out? Install our VSCode extension and follow the steps below, or take a look at the documentation.

Getting started

If you haven’t already, add Firebase to your Flutter app by following these steps.

To start generating the new Flutter SDK, add the following configuration to your dataconnect/connector/connector.yaml file:


Article content

The outputDir specifies where the generated SDKs should live, and the package defines the name of the new Dart package where the generated code will live.

Next, let’s add some tables to our schema:


Article content

Add a new query to our list of operations:


Article content

Note: We use PUBLIC in the example below as this doesn’t expose sensitive information. We recommend using stricter auth on restrictive operations.

And add a new mutation to add a new movie into the list:


Article content

Now let’s call it!

First, install the Data Connect core SDKs:


Article content

Then, add the following to your main.dart:

...

import 'package:fdc_flutter_blog_post/generated/movies.dart';

...

// Add logic to log in a user

...

// Add a movie if one doesn't exist already

await MoviesConnector.instance

.createMovie(

title: "Quantum Paradox",

genre: "sci--fi",

imageUrl:

"https://firebasestorage.googleapis.com/v0/b/fdc-web-quickstart.appspot.com/o/movie%2Fquantum_paradox.jpeg?alt=media&token=4142e2a1-bf43-43b5-b7cf-6616be3fd4e3")

.execute();

// Call the ListMovies query we created earlier

MoviesConnector.instance.listMovies().execute().then((res) {

setState(() {

_movies = res.data.movies;

});

});



Here’s a sample app using that query:


Article content
Movie review app

Learn More!

To learn more about developing Flutter apps using Data Connect, visit our documentation, and try out our quickstart by cloning our GitHub repo!

I just passed this I'm highest scholar with a triples fires account...

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore content categories