Skip to content

Commit 903643c

Browse files
mzdmditman
authored andcommitted
FlutterFire plugins & SDK updates (#5)
1 parent 3996cb7 commit 903643c

File tree

15 files changed

+102
-111
lines changed

15 files changed

+102
-111
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:pedantic/analysis_options.yaml
1+
include: package:pedantic/analysis_options.yaml

android/app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 28
29+
compileSdkVersion 29
3030

3131
sourceSets {
3232
main.java.srcDirs += 'src/main/kotlin'
@@ -40,7 +40,8 @@ android {
4040
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4141
applicationId "com.example.friendlyeats"
4242
minSdkVersion 21
43-
targetSdkVersion 28
43+
targetSdkVersion 29
44+
multiDexEnabled true
4445
versionCode flutterVersionCode.toInteger()
4546
versionName flutterVersionName
4647
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -61,9 +62,10 @@ flutter {
6162

6263
dependencies {
6364
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
65+
implementation 'com.android.support:multidex:1.0.3'
6466
testImplementation 'junit:junit:4.12'
65-
androidTestImplementation 'androidx.test:runner:1.1.1'
66-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
67+
androidTestImplementation 'androidx.test:runner:1.3.0'
68+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
6769
}
6870

6971
apply plugin: 'com.google.gms.google-services'

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.0'
9+
classpath 'com.android.tools.build:gradle:4.0.1'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
classpath 'com.google.gms:google-services:4.3.3'
1212
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jun 23 08:50:38 CEST 2017
1+
#Sun Sep 06 18:43:15 CEST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

firebase.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hosting": {
3-
"predeploy": "flutter clean; flutter build web",
3+
"predeploy": "flutter clean & flutter build web",
44
"public": "build/web",
55
"ignore": [
66
"firebase.json",

lib/main.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import 'package:firebase_core/firebase_core.dart';
1516
import 'package:flutter/material.dart';
1617

1718
import 'src/app.dart' deferred as app;
1819

19-
void main() {
20-
final Future<void> loadedLibrary = app.loadLibrary();
20+
void main() async {
21+
// Initialize Firebase
22+
WidgetsFlutterBinding.ensureInitialized();
23+
await Firebase.initializeApp();
24+
25+
final Future<void> loadedLibrary = await app.loadLibrary();
2126
runApp(
2227
FutureBuilder(
2328
future: loadedLibrary,

lib/src/home_page.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class HomePage extends StatefulWidget {
3939

4040
class _HomePageState extends State<HomePage> {
4141
_HomePageState() {
42-
FirebaseAuth.instance.signInAnonymously().then((AuthResult auth) {
42+
FirebaseAuth.instance
43+
.signInAnonymously()
44+
.then((UserCredential userCredential) {
4345
_currentSubscription =
4446
data.loadAllRestaurants().listen(_updateRestaurants);
4547
});

lib/src/model/restaurant.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class Restaurant {
4141

4242
Restaurant.fromSnapshot(DocumentSnapshot snapshot)
4343
: assert(snapshot != null),
44-
id = snapshot.documentID,
45-
name = snapshot['name'],
46-
category = snapshot['category'],
47-
city = snapshot['city'],
48-
avgRating = snapshot['avgRating'].toDouble(),
49-
numRatings = snapshot['numRatings'],
50-
price = snapshot['price'],
51-
photo = snapshot['photo'],
44+
id = snapshot.id,
45+
name = snapshot.data()['name'],
46+
category = snapshot.data()['category'],
47+
city = snapshot.data()['city'],
48+
avgRating = snapshot.data()['avgRating'].toDouble(),
49+
numRatings = snapshot.data()['numRatings'],
50+
price = snapshot.data()['price'],
51+
photo = snapshot.data()['photo'],
5252
reference = snapshot.reference;
5353

5454
factory Restaurant.random() {

lib/src/model/review.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class Review {
3131

3232
Review.fromSnapshot(DocumentSnapshot snapshot)
3333
: assert(snapshot != null),
34-
id = snapshot.documentID,
35-
rating = snapshot['rating'].toDouble(),
36-
text = snapshot['text'],
37-
userName = snapshot['userName'],
38-
userId = snapshot['userId'],
39-
timestamp = snapshot['timestamp'],
34+
id = snapshot.id,
35+
rating = snapshot.data()['rating'].toDouble(),
36+
text = snapshot.data()['text'],
37+
userName = snapshot.data()['userName'],
38+
userId = snapshot.data()['userId'],
39+
timestamp = snapshot.data()['timestamp'],
4040
reference = snapshot.reference;
4141

4242
Review.fromUserInput({this.rating, this.text, this.userName, this.userId})

lib/src/restaurant_page.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,20 @@ class RestaurantPage extends StatefulWidget {
4545

4646
class _RestaurantPageState extends State<RestaurantPage> {
4747
_RestaurantPageState({@required String restaurantId}) {
48-
FirebaseAuth.instance.signInAnonymously().then((AuthResult auth) {
48+
FirebaseAuth.instance
49+
.signInAnonymously()
50+
.then((UserCredential userCredential) {
4951
data.getRestaurant(restaurantId).then((Restaurant restaurant) {
5052
_currentReviewSubscription?.cancel();
5153
setState(() {
52-
if (auth.user.displayName == null || auth.user.displayName.isEmpty) {
54+
if (userCredential.user.displayName == null ||
55+
userCredential.user.displayName.isEmpty) {
5356
_userName = 'Anonymous (${kIsWeb ? "Web" : "Mobile"})';
5457
} else {
55-
_userName = auth.user.displayName;
58+
_userName = userCredential.user.displayName;
5659
}
5760
_restaurant = restaurant;
58-
_userId = auth.user.uid;
61+
_userId = userCredential.user.uid;
5962

6063
// Initialize the reviews snapshot...
6164
_currentReviewSubscription = _restaurant.reference
@@ -65,7 +68,7 @@ class _RestaurantPageState extends State<RestaurantPage> {
6568
.listen((QuerySnapshot reviewSnap) {
6669
setState(() {
6770
_isLoading = false;
68-
_reviews = reviewSnap.documents.map((DocumentSnapshot doc) {
71+
_reviews = reviewSnap.docs.map((DocumentSnapshot doc) {
6972
return Review.fromSnapshot(doc);
7073
}).toList();
7174
});

0 commit comments

Comments
 (0)