Skip to content
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

#11 Upgraded the Firebase packages Hacktoberfest2020 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 29

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
applicationId "com.nathanglover.catbox"
minSdkVersion 16
minSdkVersion 20
multiDexEnabled true
targetSdkVersion 27
targetSdkVersion 29
versionCode 6
versionName "1.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
//signingConfig signingConfigs.debug
signingConfig signingConfigs.release
// signingConfig signingConfigs.debug
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.nathanglover.catbox;

import android.os.Bundle;
//import android.os.Bundle;
//
//import io.flutter.app.FlutterActivity;
//import io.flutter.plugins.GeneratedPluginRegistrant;

import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// GeneratedPluginRegistrant.registerWith(this);
// }
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:3.2.1'
}
}
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Mar 31 02:04:09 AWST 2018
#Mon Oct 19 19:16:30 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
15 changes: 7 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import 'package:catbox/ui/cat_list.dart';
import 'package:flutter/material.dart';

void main() async {
runApp(new CatBoxApp());
runApp(CatBoxApp());
}

class CatBoxApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.blue,
accentColor: Colors.pinkAccent,
fontFamily: 'Ubuntu'
),
home: new CatList(),
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
accentColor: Colors.pinkAccent,
fontFamily: 'Ubuntu'),
home: CatList(),
);
}
}
55 changes: 28 additions & 27 deletions lib/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ class CatApi {
static FirebaseAuth _auth = FirebaseAuth.instance;
static GoogleSignIn _googleSignIn = new GoogleSignIn();

FirebaseUser firebaseUser;

CatApi(FirebaseUser user) {
User firebaseUser;
final _instane = FirebaseFirestore.instance;
CatApi(User user) {
this.firebaseUser = user;
}

static Future<CatApi> signInWithGoogle() async {
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
FirebaseUser user = await _auth.signInWithGoogle(
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
assert(user.email != null);
assert(user.displayName != null);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final UserCredential user = await _auth.signInWithCredential(credential);
assert(user.user.email != null);
assert(user.user.displayName != null);
assert(!user.user.isAnonymous);
assert(await user.user.getIdToken() != null);

FirebaseUser currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);
User currentUser = _auth.currentUser;
assert(user.user.uid == currentUser.uid);

return new CatApi(user);
return new CatApi(user.user);
}

Cat _fromDocumentSnapshot(DocumentSnapshot snapshot) {
final data = snapshot.data;
Cat _fromdocSnapshot(DocumentSnapshot snapshot) {
final data = snapshot.data();

return new Cat(
documentId: snapshot.documentID,
documentId: snapshot.id,
externalId: data['id'],
name: data['name'],
description: data['description'],
Expand All @@ -50,40 +51,40 @@ class CatApi {
}

Future likeCat(Cat cat) async {
await Firestore.instance
await _instane
.collection('likes')
.document('${cat.documentId}:${this.firebaseUser.uid}')
.setData({});
.doc('${cat.documentId}:${this.firebaseUser.uid}')
.set({});
}

Future unlikeCat(Cat cat) async {
await Firestore.instance
await _instane
.collection('likes')
.document('${cat.documentId}:${this.firebaseUser.uid}')
.doc('${cat.documentId}:${this.firebaseUser.uid}')
.delete();
}

Future<bool> hasLikedCat(Cat cat) async {
final like = await Firestore.instance
final like = await _instane
.collection('likes')
.document('${cat.documentId}:${this.firebaseUser.uid}')
.doc('${cat.documentId}:${this.firebaseUser.uid}')
.get();

return like.exists;
}

Future<List<Cat>> getAllCats() async {
return (await Firestore.instance.collection('cats').getDocuments())
.documents
.map((snapshot) => _fromDocumentSnapshot(snapshot))
return (await _instane.collection('cats').get())
.docs
.map((snapshot) => _fromdocSnapshot(snapshot))
.toList();
}

StreamSubscription watch(Cat cat, void onChange(Cat cat)) {
return Firestore.instance
return _instane
.collection('cats')
.document(cat.documentId)
.doc(cat.documentId)
.snapshots()
.listen((snapshot) => onChange(_fromDocumentSnapshot(snapshot)));
.listen((snapshot) => onChange(_fromdocSnapshot(snapshot)));
}
}
8 changes: 4 additions & 4 deletions lib/ui/cat_details/details_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CatDetailBody extends StatelessWidget {
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
cat.location,
style: textTheme.subhead.copyWith(color: Colors.white),
style: textTheme.subtitle1.copyWith(color: Colors.white),
),
),
],
Expand All @@ -48,7 +48,7 @@ class CatDetailBody extends StatelessWidget {
children: [
new Text(
cat.name,
style: textTheme.headline.copyWith(color: Colors.white),
style: textTheme.headline5.copyWith(color: Colors.white),
),
new Padding(
padding: const EdgeInsets.only(top: 4.0),
Expand All @@ -58,8 +58,8 @@ class CatDetailBody extends StatelessWidget {
padding: const EdgeInsets.only(top: 16.0),
child: new Text(
cat.description,
style:
textTheme.body1.copyWith(color: Colors.white70, fontSize: 16.0),
style: textTheme.bodyText2
.copyWith(color: Colors.white70, fontSize: 16.0),
),
),
new Padding(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/cat_details/footer/showcase_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DetailsShowcase extends StatelessWidget {
child: new Text(
cat.description,
textAlign: TextAlign.center,
style: textTheme.subhead.copyWith(color: Colors.white),
style: textTheme.subtitle1.copyWith(color: Colors.white),
),
);
}
Expand Down
11 changes: 5 additions & 6 deletions lib/ui/cat_details/header/details_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ class _CatDetailHeaderState extends State<CatDetailHeader> {
size: 16.0,
),
new Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
_likeCounter.toString(),
style: textTheme.subhead.copyWith(color: Colors.white),
)
)
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
_likeCounter.toString(),
style: textTheme.subtitle1.copyWith(color: Colors.white),
))
],
),
);
Expand Down
45 changes: 21 additions & 24 deletions lib/ui/cat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _CatListState extends State<CatList> {
setState(() {
_api = api;
_cats = cats;
_profileImage = new NetworkImage(api.firebaseUser.photoUrl);
_profileImage = new NetworkImage(api.firebaseUser.photoURL);
});
}

Expand Down Expand Up @@ -60,7 +60,8 @@ class _CatListState extends State<CatList> {
),
title: new Text(
cat.name,
style: new TextStyle(fontWeight: FontWeight.bold, color: Colors.black54),
style: new TextStyle(
fontWeight: FontWeight.bold, color: Colors.black54),
),
subtitle: new Text(cat.description),
isThreeLine: true,
Expand All @@ -74,11 +75,11 @@ class _CatListState extends State<CatList> {

_navigateToCatDetails(Cat cat, Object avatarTag) {
Navigator.of(context).push(
new FadePageRoute(
FadePageRoute(
builder: (c) {
return new CatDetailsPage(cat, avatarTag: avatarTag);
return CatDetailsPage(cat, avatarTag: avatarTag);
},
settings: new RouteSettings(),
settings: RouteSettings(),
),
);
}
Expand All @@ -97,18 +98,15 @@ class _CatListState extends State<CatList> {
Widget _buildBody() {
return new Container(
margin: const EdgeInsets.fromLTRB(
8.0, // A left margin of 8.0
56.0, // A top margin of 56.0
8.0, // A right margin of 8.0
0.0 // A bottom margin of 0.0
),
8.0, // A left margin of 8.0
56.0, // A top margin of 56.0
8.0, // A right margin of 8.0
0.0 // A bottom margin of 0.0
),
child: new Column(
// A column widget can have several
// widgets that are placed in a top down fashion
children: <Widget>[
_getAppTitleWidget(),
_getListViewWidget()
],
children: <Widget>[_getAppTitleWidget(), _getListViewWidget()],
),
);
}
Expand All @@ -120,15 +118,12 @@ class _CatListState extends State<CatList> {

Widget _getListViewWidget() {
return new Flexible(
child: new RefreshIndicator(
onRefresh: refresh,
child: new ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: _cats.length,
itemBuilder: _buildCatItem
)
)
);
child: new RefreshIndicator(
onRefresh: refresh,
child: new ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: _cats.length,
itemBuilder: _buildCatItem)));
}

@override
Expand All @@ -140,7 +135,9 @@ class _CatListState extends State<CatList> {
onPressed: () {
// Do something when FAB is pressed
},
tooltip: _api != null ? 'Signed-in: ' + _api.firebaseUser.displayName : 'Not Signed-in',
tooltip: _api != null
? 'Signed-in: ' + _api.firebaseUser.displayName
: 'Not Signed-in',
backgroundColor: Colors.blue,
child: new CircleAvatar(
backgroundImage: _profileImage,
Expand Down
Loading