Skip to content

Commit 407f95f

Browse files
authored
Included idx specific changes (#101)
1 parent bd35f61 commit 407f95f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+718
-3411
lines changed

data_connect/README.idx.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Firebase Data Connect Quickstart
2+
3+
## Introduction
4+
5+
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/).
6+
7+
8+
## Getting Started
9+
10+
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).
11+
12+
### 1. Connect to your Firebase project
13+
14+
1. If you haven't already, create a Firebase project.
15+
1. In the [Firebase console](https://console.firebase.google.com), click
16+
**Add project**, then follow the on-screen instructions.
17+
2. Enable Email/Password Sign-in method [here](https://console.firebase.google.com/project/_/authentication/providers).
18+
19+
### 2. Configure flutterfire
20+
21+
This will automatically download and set up firebase for your project:
22+
```sh
23+
flutterfire configure -y -a com.example.dataconnect
24+
25+
### 3. Start Emulators
26+
27+
1. Click on the Firebase Data Connect icon on the VS Code sidebar to load the Extension.
28+
a. Sign in with your Google Account if you haven't already.
29+
2. Click on "Connect a Firebase project" and choose the project where you have set up Data Connect.
30+
3. Click on "Start Emulators" - this should generate the Flutter SDK for you and start the emulators.
31+
32+
### 4. Populate the database
33+
In VS Code, open the `quickstart-flutter/dataconnect/dataconnect/moviedata_insert.gql` file and click the
34+
`Run (local)` button at the top of the file.
35+
36+
If you’d like to confirm that the data was correctly inserted,
37+
open `quickstart-flutter/dataconnect/movie-connector/queries.gql` and run the `ListMovies` query.
38+
39+
### 5. Running the app
40+
41+
The app should already be running in the preview. If there's no preview, try one of the following:
42+
* Ctrl/Cmd + SHIFT + P, Reload Window
43+
* Ctrl/Cmd + SHIFT + P, Open Web Preview

data_connect/analysis_options.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
# The following line activates a set of recommended lints for Flutter apps,
99
# packages, and plugins designed to encourage good coding practices.
1010
include: package:flutter_lints/flutter.yaml
11-
analyzer:
11+
12+
analyzer:
1213
exclude:
13-
lib/movies_connector/**
14+
- lib/movies_connector/**
1415
linter:
1516
# The lint rules applied to this project can be customized in the
1617
# section below to disable rules from the `package:flutter_lints/flutter.yaml`

data_connect/firebase.idx.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"dataconnect": {
3+
"source": "dataconnect"
4+
},
5+
"emulators": {
6+
"dataconnect": {
7+
"port": 9403
8+
},
9+
"ui": {
10+
"enabled": false
11+
},
12+
"singleProjectMode": true
13+
}
14+
}

data_connect/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class _MyHomePageState extends State<MyHomePage> {
7979
child: _showMessage
8080
? Column(
8181
mainAxisAlignment: MainAxisAlignment.center,
82-
crossAxisAlignment: CrossAxisAlignment.center,
82+
crossAxisAlignment: CrossAxisAlignment.start,
8383
children: [
8484
Padding(
8585
padding: const EdgeInsets.all(30.0),

data_connect/lib/main.idx.dart

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import 'package:dataconnect/models/movie.dart';
2+
import 'package:dataconnect/movie_state.dart';
3+
import 'package:dataconnect/router.dart';
4+
import 'package:dataconnect/widgets/list_movies.dart';
5+
import 'package:flutter/foundation.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:firebase_core/firebase_core.dart';
8+
import 'firebase_options.dart';
9+
import 'package:flutter_web_plugins/url_strategy.dart';
10+
import 'util/auth.dart';
11+
import 'movies_connector/movies.dart';
12+
13+
bool isSetup = false;
14+
void main() async {
15+
WidgetsFlutterBinding.ensureInitialized();
16+
usePathUrlStrategy();
17+
try {
18+
await Firebase.initializeApp(
19+
options: DefaultFirebaseOptions.currentPlatform,
20+
);
21+
isSetup = true;
22+
23+
await Auth.instance.init();
24+
int port = 443;
25+
String hostName = Uri.base.host;
26+
bool isSecure = true;
27+
if (!kIsWeb) {
28+
hostName = '10.0.2.2';
29+
port = 9403;
30+
isSecure = false;
31+
}
32+
MoviesConnector.instance.dataConnect
33+
.useDataConnectEmulator(hostName, port, isSecure: isSecure);
34+
} catch (_) {
35+
// The user hasn't run ./installDeps.sh yet
36+
}
37+
38+
runApp(const MyApp());
39+
}
40+
41+
class MyApp extends StatelessWidget {
42+
const MyApp({super.key});
43+
44+
// This widget is the root of your application.
45+
@override
46+
Widget build(BuildContext context) {
47+
return MaterialApp.router(
48+
theme: ThemeData.dark(),
49+
routerConfig: router,
50+
);
51+
}
52+
}
53+
54+
class MyHomePage extends StatefulWidget {
55+
const MyHomePage({super.key});
56+
57+
@override
58+
State<MyHomePage> createState() => _MyHomePageState();
59+
}
60+
61+
class _MyHomePageState extends State<MyHomePage> {
62+
List<ListMoviesMovies> _topMovies = [];
63+
List<ListMoviesMovies> _latestMovies = [];
64+
bool _showMessage = true;
65+
66+
@override
67+
void initState() {
68+
super.initState();
69+
70+
if (isSetup) {
71+
MovieState.getTopTenMovies().then((res) {
72+
if (res.data.movies.isNotEmpty) {
73+
if (mounted) {
74+
setState(() {
75+
_showMessage = false;
76+
_topMovies = res.data.movies;
77+
});
78+
}
79+
}
80+
});
81+
82+
MovieState.getTopTenMovies().then((res) {
83+
setState(() {
84+
_latestMovies = res.data.movies;
85+
});
86+
});
87+
}
88+
}
89+
90+
@override
91+
Widget build(BuildContext context) {
92+
return Scaffold(
93+
body: SafeArea(
94+
child: SingleChildScrollView(
95+
child: _showMessage || !isSetup
96+
? Center(
97+
child: Column(
98+
mainAxisAlignment: MainAxisAlignment.center,
99+
crossAxisAlignment: CrossAxisAlignment.start,
100+
children: [
101+
Padding(
102+
padding: const EdgeInsets.all(30.0),
103+
child: isSetup
104+
? Text(
105+
'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.')
106+
: const NumberedList(bullets: [
107+
'Make sure you already have a Firebase Project',
108+
'In the sidebar, open The Firebase Data Connect Extension',
109+
'Sign into your google account associated with your firebase project',
110+
'Select your firebase project',
111+
'Open a new terminal (by clicking the + icon below) and Run "flutterfire configure -y -a com.example.dataconnect"',
112+
'Refresh this preview page'
113+
]))
114+
],
115+
))
116+
: Column(
117+
children: <Widget>[
118+
ListMovies(
119+
title: 'Top 10 Movies',
120+
movies: _topMovies
121+
.map(
122+
(e) => Movie(
123+
id: e.id,
124+
title: e.title,
125+
imageUrl: e.imageUrl,
126+
description: e.description),
127+
)
128+
.toList()),
129+
ListMovies(
130+
title: 'Latest Movies',
131+
movies: _latestMovies
132+
.map(
133+
(e) => Movie(
134+
id: e.id,
135+
title: e.title,
136+
imageUrl: e.imageUrl,
137+
description: e.description),
138+
)
139+
.toList()),
140+
],
141+
),
142+
)),
143+
);
144+
}
145+
}
146+
147+
class NumberedList extends StatelessWidget {
148+
const NumberedList({super.key, required this.bullets});
149+
150+
final List<String> bullets;
151+
152+
@override
153+
Widget build(BuildContext context) {
154+
return Container(
155+
alignment: Alignment.centerLeft,
156+
padding: const EdgeInsets.fromLTRB(16, 15, 16, 16),
157+
child: Column(
158+
children: bullets
159+
.asMap()
160+
.keys
161+
.map((index) => Row(children: [
162+
Text(
163+
"${index + 1}.",
164+
style: const TextStyle(
165+
fontSize: 16, height: 1.55, color: Colors.white),
166+
),
167+
const SizedBox(
168+
width: 5,
169+
),
170+
Expanded(
171+
child: Text(
172+
bullets[index],
173+
textAlign: TextAlign.left,
174+
softWrap: true,
175+
style: const TextStyle(
176+
fontSize: 16,
177+
color: Colors.white,
178+
height: 1.55,
179+
),
180+
),
181+
)
182+
]))
183+
.toList()));
184+
}
185+
}
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,32 @@
1-
part of movies_connector;
1+
part of 'movies.dart';
22

33
class AddFavoritedMovieVariablesBuilder {
44
String movieId;
55

6-
FirebaseDataConnect _dataConnect;
7-
8-
AddFavoritedMovieVariablesBuilder(
9-
this._dataConnect, {
10-
required String this.movieId,
11-
});
12-
Deserializer<AddFavoritedMovieData> dataDeserializer =
13-
(dynamic json) => AddFavoritedMovieData.fromJson(jsonDecode(json));
14-
Serializer<AddFavoritedMovieVariables> varsSerializer =
15-
(AddFavoritedMovieVariables vars) => jsonEncode(vars.toJson());
16-
Future<OperationResult<AddFavoritedMovieData, AddFavoritedMovieVariables>>
17-
execute() {
18-
return this.ref().execute();
6+
final FirebaseDataConnect _dataConnect;
7+
AddFavoritedMovieVariablesBuilder(this._dataConnect, {required this.movieId,});
8+
Deserializer<AddFavoritedMovieData> dataDeserializer = (dynamic json) => AddFavoritedMovieData.fromJson(jsonDecode(json));
9+
Serializer<AddFavoritedMovieVariables> varsSerializer = (AddFavoritedMovieVariables vars) => jsonEncode(vars.toJson());
10+
Future<OperationResult<AddFavoritedMovieData, AddFavoritedMovieVariables>> execute() {
11+
return ref().execute();
1912
}
2013

2114
MutationRef<AddFavoritedMovieData, AddFavoritedMovieVariables> ref() {
22-
AddFavoritedMovieVariables vars = AddFavoritedMovieVariables(
23-
movieId: movieId,
24-
);
25-
26-
return _dataConnect.mutation(
27-
"AddFavoritedMovie", dataDeserializer, varsSerializer, vars);
15+
AddFavoritedMovieVariables vars= AddFavoritedMovieVariables(movieId: movieId,);
16+
return _dataConnect.mutation("AddFavoritedMovie", dataDeserializer, varsSerializer, vars);
2817
}
2918
}
3019

3120
class AddFavoritedMovieFavoriteMovieUpsert {
3221
String userId;
33-
3422
String movieId;
35-
36-
AddFavoritedMovieFavoriteMovieUpsert.fromJson(dynamic json)
37-
: userId = nativeFromJson<String>(json['userId']),
38-
movieId = nativeFromJson<String>(json['movieId']) {}
23+
AddFavoritedMovieFavoriteMovieUpsert.fromJson(dynamic json):
24+
userId = nativeFromJson<String>(json['userId']),movieId = nativeFromJson<String>(json['movieId']);
3925

4026
Map<String, dynamic> toJson() {
4127
Map<String, dynamic> json = {};
42-
4328
json['userId'] = nativeToJson<String>(userId);
44-
4529
json['movieId'] = nativeToJson<String>(movieId);
46-
4730
return json;
4831
}
4932

@@ -55,16 +38,12 @@ class AddFavoritedMovieFavoriteMovieUpsert {
5538

5639
class AddFavoritedMovieData {
5740
AddFavoritedMovieFavoriteMovieUpsert favorite_movie_upsert;
58-
59-
AddFavoritedMovieData.fromJson(dynamic json)
60-
: favorite_movie_upsert = AddFavoritedMovieFavoriteMovieUpsert.fromJson(
61-
json['favorite_movie_upsert']) {}
41+
AddFavoritedMovieData.fromJson(dynamic json):
42+
favorite_movie_upsert = AddFavoritedMovieFavoriteMovieUpsert.fromJson(json['favorite_movie_upsert']);
6243

6344
Map<String, dynamic> toJson() {
6445
Map<String, dynamic> json = {};
65-
6646
json['favorite_movie_upsert'] = favorite_movie_upsert.toJson();
67-
6847
return json;
6948
}
7049

@@ -75,21 +54,18 @@ class AddFavoritedMovieData {
7554

7655
class AddFavoritedMovieVariables {
7756
String movieId;
78-
79-
@Deprecated(
80-
'fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
81-
AddFavoritedMovieVariables.fromJson(Map<String, dynamic> json)
82-
: movieId = nativeFromJson<String>(json['movieId']) {}
57+
@Deprecated('fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
58+
AddFavoritedMovieVariables.fromJson(Map<String, dynamic> json):
59+
movieId = nativeFromJson<String>(json['movieId']);
8360

8461
Map<String, dynamic> toJson() {
8562
Map<String, dynamic> json = {};
86-
8763
json['movieId'] = nativeToJson<String>(movieId);
88-
8964
return json;
9065
}
9166

9267
AddFavoritedMovieVariables({
9368
required this.movieId,
9469
});
9570
}
71+

0 commit comments

Comments
 (0)