Skip to content

Included idx specific changes #101

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

Merged
merged 9 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions data_connect/README.idx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Firebase Data Connect Quickstart

## Introduction

This quickstart is a movie review app to demonstrate the use of Firebase Data Connect with a Cloud SQL database. For more information about Firebase Data Connect visit [the docs](https://firebase.google.com/docs/data-connect/).


## Getting Started

Follow these steps to get up and running with Firebase Data Connect. For more detailed instructions, check out the [official documentation](https://firebase.google.com/docs/data-connect/quickstart).

### 1. Connect to your Firebase project

1. If you haven't already, create a Firebase project.
1. In the [Firebase console](https://console.firebase.google.com), click
**Add project**, then follow the on-screen instructions.
2. Enable Email/Password Sign-in method [here](https://console.firebase.google.com/project/_/authentication/providers).

### 2. Configure flutterfire

This will automatically download and set up firebase for your project:
```sh
flutterfire configure -y -a com.example.dataconnect

### 3. Start Emulators

1. Click on the Firebase Data Connect icon on the VS Code sidebar to load the Extension.
a. Sign in with your Google Account if you haven't already.
2. Click on "Connect a Firebase project" and choose the project where you have set up Data Connect.
3. Click on "Start Emulators" - this should generate the Flutter SDK for you and start the emulators.

### 4. Populate the database
In VS Code, open the `quickstart-flutter/dataconnect/dataconnect/moviedata_insert.gql` file and click the
`Run (local)` button at the top of the file.

If you’d like to confirm that the data was correctly inserted,
open `quickstart-flutter/dataconnect/movie-connector/queries.gql` and run the `ListMovies` query.

### 5. Running the app

The app should already be running in the preview. If there's no preview, try one of the following:
* Ctrl/Cmd + SHIFT + P, Reload Window
* Ctrl/Cmd + SHIFT + P, Open Web Preview
5 changes: 3 additions & 2 deletions data_connect/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
# 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
analyzer:

analyzer:
exclude:
lib/movies_connector/**
- lib/movies_connector/**
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`
Expand Down
14 changes: 14 additions & 0 deletions data_connect/firebase.idx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"dataconnect": {
"source": "dataconnect"
},
"emulators": {
"dataconnect": {
"port": 9403
},
"ui": {
"enabled": false
},
"singleProjectMode": true
}
}
2 changes: 1 addition & 1 deletion data_connect/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: _showMessage
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(30.0),
Expand Down
185 changes: 185 additions & 0 deletions data_connect/lib/main.idx.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import 'package:dataconnect/models/movie.dart';
import 'package:dataconnect/movie_state.dart';
import 'package:dataconnect/router.dart';
import 'package:dataconnect/widgets/list_movies.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
import 'util/auth.dart';
import 'movies_connector/movies.dart';

bool isSetup = false;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
usePathUrlStrategy();
try {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
isSetup = true;

await Auth.instance.init();
int port = 443;
String hostName = Uri.base.host;
bool isSecure = true;
if (!kIsWeb) {
hostName = '10.0.2.2';
port = 9403;
isSecure = false;
}
MoviesConnector.instance.dataConnect
.useDataConnectEmulator(hostName, port, isSecure: isSecure);
} catch (_) {
// The user hasn't run ./installDeps.sh yet
}

runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
theme: ThemeData.dark(),
routerConfig: router,
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
List<ListMoviesMovies> _topMovies = [];
List<ListMoviesMovies> _latestMovies = [];
bool _showMessage = true;

@override
void initState() {
super.initState();

if (isSetup) {
MovieState.getTopTenMovies().then((res) {
if (res.data.movies.isNotEmpty) {
if (mounted) {
setState(() {
_showMessage = false;
_topMovies = res.data.movies;
});
}
}
});

MovieState.getTopTenMovies().then((res) {
setState(() {
_latestMovies = res.data.movies;
});
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: _showMessage || !isSetup
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(30.0),
child: isSetup
? Text(
'Go to the Firebase Data Connect extension, and click start Emulators. ${_latestMovies.isEmpty ? 'Then open dataconnect/moviedata_insert.gql and the click "Run(local)".' : ''} Then, refresh the page.')
: const NumberedList(bullets: [
'Make sure you already have a Firebase Project',
'In the sidebar, open The Firebase Data Connect Extension',
'Sign into your google account associated with your firebase project',
'Select your firebase project',
'Open a new terminal (by clicking the + icon below) and Run "flutterfire configure -y -a com.example.dataconnect"',
'Refresh this preview page'
]))
],
))
: Column(
children: <Widget>[
ListMovies(
title: 'Top 10 Movies',
movies: _topMovies
.map(
(e) => Movie(
id: e.id,
title: e.title,
imageUrl: e.imageUrl,
description: e.description),
)
.toList()),
ListMovies(
title: 'Latest Movies',
movies: _latestMovies
.map(
(e) => Movie(
id: e.id,
title: e.title,
imageUrl: e.imageUrl,
description: e.description),
)
.toList()),
],
),
)),
);
}
}

class NumberedList extends StatelessWidget {
const NumberedList({super.key, required this.bullets});

final List<String> bullets;

@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.fromLTRB(16, 15, 16, 16),
child: Column(
children: bullets
.asMap()
.keys
.map((index) => Row(children: [
Text(
"${index + 1}.",
style: const TextStyle(
fontSize: 16, height: 1.55, color: Colors.white),
),
const SizedBox(
width: 5,
),
Expanded(
child: Text(
bullets[index],
textAlign: TextAlign.left,
softWrap: true,
style: const TextStyle(
fontSize: 16,
color: Colors.white,
height: 1.55,
),
),
)
]))
.toList()));
}
}
58 changes: 17 additions & 41 deletions data_connect/lib/movies_connector/add_favorited_movie.dart
Original file line number Diff line number Diff line change
@@ -1,49 +1,32 @@
part of movies_connector;
part of 'movies.dart';

class AddFavoritedMovieVariablesBuilder {
String movieId;

FirebaseDataConnect _dataConnect;

AddFavoritedMovieVariablesBuilder(
this._dataConnect, {
required String this.movieId,
});
Deserializer<AddFavoritedMovieData> dataDeserializer =
(dynamic json) => AddFavoritedMovieData.fromJson(jsonDecode(json));
Serializer<AddFavoritedMovieVariables> varsSerializer =
(AddFavoritedMovieVariables vars) => jsonEncode(vars.toJson());
Future<OperationResult<AddFavoritedMovieData, AddFavoritedMovieVariables>>
execute() {
return this.ref().execute();
final FirebaseDataConnect _dataConnect;
AddFavoritedMovieVariablesBuilder(this._dataConnect, {required this.movieId,});
Deserializer<AddFavoritedMovieData> dataDeserializer = (dynamic json) => AddFavoritedMovieData.fromJson(jsonDecode(json));
Serializer<AddFavoritedMovieVariables> varsSerializer = (AddFavoritedMovieVariables vars) => jsonEncode(vars.toJson());
Future<OperationResult<AddFavoritedMovieData, AddFavoritedMovieVariables>> execute() {
return ref().execute();
}

MutationRef<AddFavoritedMovieData, AddFavoritedMovieVariables> ref() {
AddFavoritedMovieVariables vars = AddFavoritedMovieVariables(
movieId: movieId,
);

return _dataConnect.mutation(
"AddFavoritedMovie", dataDeserializer, varsSerializer, vars);
AddFavoritedMovieVariables vars= AddFavoritedMovieVariables(movieId: movieId,);
return _dataConnect.mutation("AddFavoritedMovie", dataDeserializer, varsSerializer, vars);
}
}

class AddFavoritedMovieFavoriteMovieUpsert {
String userId;

String movieId;

AddFavoritedMovieFavoriteMovieUpsert.fromJson(dynamic json)
: userId = nativeFromJson<String>(json['userId']),
movieId = nativeFromJson<String>(json['movieId']) {}
AddFavoritedMovieFavoriteMovieUpsert.fromJson(dynamic json):
userId = nativeFromJson<String>(json['userId']),movieId = nativeFromJson<String>(json['movieId']);

Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['userId'] = nativeToJson<String>(userId);

json['movieId'] = nativeToJson<String>(movieId);

return json;
}

Expand All @@ -55,16 +38,12 @@ class AddFavoritedMovieFavoriteMovieUpsert {

class AddFavoritedMovieData {
AddFavoritedMovieFavoriteMovieUpsert favorite_movie_upsert;

AddFavoritedMovieData.fromJson(dynamic json)
: favorite_movie_upsert = AddFavoritedMovieFavoriteMovieUpsert.fromJson(
json['favorite_movie_upsert']) {}
AddFavoritedMovieData.fromJson(dynamic json):
favorite_movie_upsert = AddFavoritedMovieFavoriteMovieUpsert.fromJson(json['favorite_movie_upsert']);

Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['favorite_movie_upsert'] = favorite_movie_upsert.toJson();

return json;
}

Expand All @@ -75,21 +54,18 @@ class AddFavoritedMovieData {

class AddFavoritedMovieVariables {
String movieId;

@Deprecated(
'fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
AddFavoritedMovieVariables.fromJson(Map<String, dynamic> json)
: movieId = nativeFromJson<String>(json['movieId']) {}
@Deprecated('fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
AddFavoritedMovieVariables.fromJson(Map<String, dynamic> json):
movieId = nativeFromJson<String>(json['movieId']);

Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['movieId'] = nativeToJson<String>(movieId);

return json;
}

AddFavoritedMovieVariables({
required this.movieId,
});
}

Loading
Loading