Add login

This commit is contained in:
Ricardo Markiewicz
2019-06-07 21:34:27 -03:00
parent a2eab2f31c
commit de396d9fa3
13 changed files with 387 additions and 137 deletions
+119 -91
View File
@@ -1,115 +1,127 @@
PODS:
- BoringSSL-GRPC (0.0.2):
- BoringSSL-GRPC/Implementation (= 0.0.2)
- BoringSSL-GRPC/Interface (= 0.0.2)
- BoringSSL-GRPC/Implementation (0.0.2):
- BoringSSL-GRPC/Interface (= 0.0.2)
- BoringSSL-GRPC/Interface (0.0.2)
- BoringSSL-GRPC (0.0.3):
- BoringSSL-GRPC/Implementation (= 0.0.3)
- BoringSSL-GRPC/Interface (= 0.0.3)
- BoringSSL-GRPC/Implementation (0.0.3):
- BoringSSL-GRPC/Interface (= 0.0.3)
- BoringSSL-GRPC/Interface (0.0.3)
- cloud_firestore (0.0.1):
- Firebase/Auth
- Firebase/Core
- Firebase/Database
- Firebase/Firestore
- Firebase/Firestore (~> 6.0)
- Flutter
- Firebase/Auth (5.18.0):
- Firebase/Auth (6.0.0):
- Firebase/CoreOnly
- FirebaseAuth (= 5.4.0)
- Firebase/Core (5.18.0):
- FirebaseAuth (~> 6.0.0)
- Firebase/Core (6.0.0):
- Firebase/CoreOnly
- FirebaseAnalytics (= 5.7.0)
- Firebase/CoreOnly (5.18.0):
- FirebaseCore (= 5.3.1)
- Firebase/Database (5.18.0):
- FirebaseAnalytics (= 6.0.0)
- Firebase/CoreOnly (6.0.0):
- FirebaseCore (= 6.0.0)
- Firebase/Firestore (6.0.0):
- Firebase/CoreOnly
- FirebaseDatabase (= 5.1.0)
- Firebase/Firestore (5.18.0):
- Firebase/CoreOnly
- FirebaseFirestore (= 1.0.2)
- FirebaseFirestore (~> 1.3.0)
- firebase_auth (0.0.1):
- Firebase/Auth (~> 6.0)
- Firebase/Core
- Flutter
- firebase_core (0.0.1):
- Firebase/Core
- Flutter
- FirebaseAnalytics (5.7.0):
- FirebaseCore (~> 5.3)
- FirebaseInstanceID (~> 3.6)
- GoogleAppMeasurement (= 5.7.0)
- GoogleUtilities/AppDelegateSwizzler (~> 5.2)
- GoogleUtilities/MethodSwizzler (~> 5.2)
- GoogleUtilities/Network (~> 5.2)
- "GoogleUtilities/NSData+zlib (~> 5.2)"
- FirebaseAnalytics (6.0.0):
- FirebaseCore (~> 6.0)
- FirebaseInstanceID (~> 4.0)
- GoogleAppMeasurement (= 6.0.0)
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/MethodSwizzler (~> 6.0)
- GoogleUtilities/Network (~> 6.0)
- "GoogleUtilities/NSData+zlib (~> 6.0)"
- nanopb (~> 0.3)
- FirebaseAuth (5.4.0):
- FirebaseAuth (6.0.0):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 5.2)
- GoogleUtilities/Environment (~> 5.2)
- FirebaseCore (~> 6.0)
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/Environment (~> 6.0)
- GTMSessionFetcher/Core (~> 1.1)
- FirebaseAuthInterop (1.0.0)
- FirebaseCore (5.3.1):
- GoogleUtilities/Logger (~> 5.2)
- FirebaseDatabase (5.1.0):
- FirebaseCore (6.0.0):
- GoogleUtilities/Environment (~> 6.0)
- GoogleUtilities/Logger (~> 6.0)
- FirebaseFirestore (1.3.0):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 5.2)
- leveldb-library (~> 1.18)
- FirebaseFirestore (1.0.2):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 5.2)
- FirebaseFirestore/abseil-cpp (= 1.0.2)
- "gRPC-C++ (= 0.0.6)"
- FirebaseCore (~> 6.0)
- FirebaseFirestore/abseil-cpp (= 1.3.0)
- "gRPC-C++ (= 0.0.8)"
- leveldb-library (~> 1.20)
- nanopb (~> 0.3.901)
- Protobuf (~> 3.1)
- FirebaseFirestore/abseil-cpp (1.0.2):
- FirebaseFirestore/abseil-cpp (1.3.0):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 5.2)
- "gRPC-C++ (= 0.0.6)"
- FirebaseCore (~> 6.0)
- "gRPC-C++ (= 0.0.8)"
- leveldb-library (~> 1.20)
- nanopb (~> 0.3.901)
- Protobuf (~> 3.1)
- FirebaseInstanceID (3.7.0):
- FirebaseCore (~> 5.2)
- GoogleUtilities/Environment (~> 5.2)
- GoogleUtilities/UserDefaults (~> 5.2)
- FirebaseInstanceID (4.0.0):
- FirebaseCore (~> 6.0)
- GoogleUtilities/Environment (~> 6.0)
- GoogleUtilities/UserDefaults (~> 6.0)
- Flutter (1.0.0)
- GoogleAppMeasurement (5.7.0):
- GoogleUtilities/AppDelegateSwizzler (~> 5.2)
- GoogleUtilities/MethodSwizzler (~> 5.2)
- GoogleUtilities/Network (~> 5.2)
- "GoogleUtilities/NSData+zlib (~> 5.2)"
- google_sign_in (0.0.1):
- Flutter
- GoogleSignIn (~> 4.0)
- GoogleAppMeasurement (6.0.0):
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/MethodSwizzler (~> 6.0)
- GoogleUtilities/Network (~> 6.0)
- "GoogleUtilities/NSData+zlib (~> 6.0)"
- nanopb (~> 0.3)
- GoogleUtilities/AppDelegateSwizzler (5.3.7):
- GoogleSignIn (4.4.0):
- "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
- "GoogleToolboxForMac/NSString+URLArguments (~> 2.1)"
- GTMSessionFetcher/Core (~> 1.1)
- GoogleToolboxForMac/DebugUtils (2.2.1):
- GoogleToolboxForMac/Defines (= 2.2.1)
- GoogleToolboxForMac/Defines (2.2.1)
- "GoogleToolboxForMac/NSDictionary+URLArguments (2.2.1)":
- GoogleToolboxForMac/DebugUtils (= 2.2.1)
- GoogleToolboxForMac/Defines (= 2.2.1)
- "GoogleToolboxForMac/NSString+URLArguments (= 2.2.1)"
- "GoogleToolboxForMac/NSString+URLArguments (2.2.1)"
- GoogleUtilities/AppDelegateSwizzler (6.1.0):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (5.3.7)
- GoogleUtilities/Logger (5.3.7):
- GoogleUtilities/Environment (6.1.0)
- GoogleUtilities/Logger (6.1.0):
- GoogleUtilities/Environment
- GoogleUtilities/MethodSwizzler (5.3.7):
- GoogleUtilities/MethodSwizzler (6.1.0):
- GoogleUtilities/Logger
- GoogleUtilities/Network (5.3.7):
- GoogleUtilities/Network (6.1.0):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (5.3.7)"
- GoogleUtilities/Reachability (5.3.7):
- "GoogleUtilities/NSData+zlib (6.1.0)"
- GoogleUtilities/Reachability (6.1.0):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (5.3.7):
- GoogleUtilities/UserDefaults (6.1.0):
- GoogleUtilities/Logger
- "gRPC-C++ (0.0.6)":
- "gRPC-C++/Implementation (= 0.0.6)"
- "gRPC-C++/Interface (= 0.0.6)"
- "gRPC-C++/Implementation (0.0.6)":
- "gRPC-C++/Interface (= 0.0.6)"
- gRPC-Core (= 1.17.0)
- "gRPC-C++ (0.0.8)":
- "gRPC-C++/Implementation (= 0.0.8)"
- "gRPC-C++/Interface (= 0.0.8)"
- "gRPC-C++/Implementation (0.0.8)":
- "gRPC-C++/Interface (= 0.0.8)"
- gRPC-Core (= 1.19.0)
- nanopb (~> 0.3)
- "gRPC-C++/Interface (0.0.6)"
- gRPC-Core (1.17.0):
- gRPC-Core/Implementation (= 1.17.0)
- gRPC-Core/Interface (= 1.17.0)
- gRPC-Core/Implementation (1.17.0):
- BoringSSL-GRPC (= 0.0.2)
- gRPC-Core/Interface (= 1.17.0)
- "gRPC-C++/Interface (0.0.8)"
- gRPC-Core (1.19.0):
- gRPC-Core/Implementation (= 1.19.0)
- gRPC-Core/Interface (= 1.19.0)
- gRPC-Core/Implementation (1.19.0):
- BoringSSL-GRPC (= 0.0.3)
- gRPC-Core/Interface (= 1.19.0)
- nanopb (~> 0.3)
- gRPC-Core/Interface (1.17.0)
- GTMSessionFetcher/Core (1.2.1)
- gRPC-Core/Interface (1.19.0)
- GTMSessionFetcher/Core (1.2.2)
- leveldb-library (1.20)
- nanopb (0.3.901):
- nanopb/decode (= 0.3.901)
@@ -117,11 +129,16 @@ PODS:
- nanopb/decode (0.3.901)
- nanopb/encode (0.3.901)
- Protobuf (3.7.0)
- shared_preferences (0.0.1):
- Flutter
DEPENDENCIES:
- cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`)
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- Flutter (from `.symlinks/flutter/ios`)
- google_sign_in (from `.symlinks/plugins/google_sign_in/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
SPEC REPOS:
https://github.com/cocoapods/specs.git:
@@ -131,10 +148,11 @@ SPEC REPOS:
- FirebaseAuth
- FirebaseAuthInterop
- FirebaseCore
- FirebaseDatabase
- FirebaseFirestore
- FirebaseInstanceID
- GoogleAppMeasurement
- GoogleSignIn
- GoogleToolboxForMac
- GoogleUtilities
- "gRPC-C++"
- gRPC-Core
@@ -146,32 +164,42 @@ SPEC REPOS:
EXTERNAL SOURCES:
cloud_firestore:
:path: ".symlinks/plugins/cloud_firestore/ios"
firebase_auth:
:path: ".symlinks/plugins/firebase_auth/ios"
firebase_core:
:path: ".symlinks/plugins/firebase_core/ios"
Flutter:
:path: ".symlinks/flutter/ios"
google_sign_in:
:path: ".symlinks/plugins/google_sign_in/ios"
shared_preferences:
:path: ".symlinks/plugins/shared_preferences/ios"
SPEC CHECKSUMS:
BoringSSL-GRPC: 2a230d9cd93e7ce39916044f645cebb31f37dde6
cloud_firestore: cd6e849ecb8ab43e5a7a5f1f169304ca65436c03
Firebase: 02f3281965c075426141a0ce1277e9de6649cab9
BoringSSL-GRPC: db8764df3204ccea016e1c8dd15d9a9ad63ff318
cloud_firestore: c6f34148c1dfbb57a6147f9bb49c1c9f5c27036e
Firebase: fa80b9d987ca014a1ba9357496ef2a0178b28b12
firebase_auth: 7a2cc520766f90212b845a5b35316601707bfa25
firebase_core: ce5006bb48508ee4e71e0f429a3f519bb8ee2961
FirebaseAnalytics: 23851fe602c872130a2c5c55040b302120346cc2
FirebaseAuth: d85d052354447f30b4b2a805ab91b511458b56a6
FirebaseAnalytics: 1743c5f4de3687d0745709dfdc4b1dea1484f44c
FirebaseAuth: efc72b0f6fe075d2a6de8d81a6d9de83ef2b47eb
FirebaseAuthInterop: 0ffa57668be100582bb7643d4fcb7615496c41fc
FirebaseCore: 52f851b30e11360f1e67cf04b1edfebf0a47a2d3
FirebaseDatabase: 23acb0c53cd4d4070a427b60100b2e4aaa97c45d
FirebaseFirestore: ccdaffb8a73c591ff61872b8f7905ad0c237ef50
FirebaseInstanceID: bd6fc5a258884e206fd5c474ebe4f5b00e21770e
FirebaseCore: e38f025287b413255a53acc1945d048a112047f7
FirebaseFirestore: 0537b2a960a4819fae2834e688e5daeb571c81d6
FirebaseInstanceID: 0e0348a3c00a734fa376a070f5ad4533ad975cb5
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
GoogleAppMeasurement: 6cf307834da065863f9faf4c0de0a936d81dd832
GoogleUtilities: 111a012f4c3a29c9e7c954c082fafd6ee3c999c0
"gRPC-C++": e76441995900ac90e9bd98644ab4733f12521edf
gRPC-Core: 4028031ed2c5267cca0d846c876d8046b1ecb9b6
GTMSessionFetcher: 32aeca0aa144acea523e1c8e053089dec2cb98ca
google_sign_in: 27e70a98b529f0b076d4b19f231b81da28b1750b
GoogleAppMeasurement: 7f028ea162b72c8f326daec74afc95d94f7a47d6
GoogleSignIn: 7ff245e1a7b26d379099d3243a562f5747e23d39
GoogleToolboxForMac: b3553629623a3b1bff17f555e736cd5a6d95ad55
GoogleUtilities: 84df567c76ca84f67b7bb40e769fdd4acc746a10
"gRPC-C++": 98be881723177d8c4faf5fdffacb582c7b4971a2
gRPC-Core: bd9472c8daa2e414b9f8038ba667bf56ce0e02b8
GTMSessionFetcher: 61bb0f61a4cb560030f1222021178008a5727a23
leveldb-library: 08cba283675b7ed2d99629a4bc5fd052cd2bb6a5
nanopb: 2901f78ea1b7b4015c860c2fdd1ea2fee1a18d48
Protobuf: 7a877b7f3e5964e3fce995e2eb323dbc6831bb5a
shared_preferences: 1feebfa37bb57264736e16865e7ffae7fc99b523
PODFILE CHECKSUM: ebd43b443038e611b86ede96e613bd6033c49497
+27
View File
@@ -166,6 +166,7 @@
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
7ABCEBC0434A5B0DE57E84C1 /* [CP] Embed Pods Frameworks */,
7F4095247A5D5D5EAA04F4B0 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
@@ -252,30 +253,56 @@
"${BUILT_PRODUCTS_DIR}/BoringSSL-GRPC/openssl_grpc.framework",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework",
"${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework",
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework",
"${BUILT_PRODUCTS_DIR}/gRPC-C++/grpcpp.framework",
"${BUILT_PRODUCTS_DIR}/gRPC-Core/grpc.framework",
"${BUILT_PRODUCTS_DIR}/leveldb-library/leveldb.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl_grpc.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GTMSessionFetcher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/grpcpp.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/grpc.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/leveldb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
7F4095247A5D5D5EAA04F4B0 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh",
"${PODS_ROOT}/GoogleSignIn/Resources/GoogleSignIn.bundle",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleSignIn.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
+1 -1
View File
@@ -46,7 +46,7 @@ class CategoryWidget extends StatelessWidget {
}
class _CategorySelectionWidgetState extends State<CategorySelectionWidget> {
String currentItem = "Shopping";
String currentItem = "";
@override
Widget build(BuildContext context) {
+75
View File
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LoginState with ChangeNotifier {
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
SharedPreferences _prefs;
bool _loggedIn = false;
bool _loading = true;
FirebaseUser _user;
LoginState() {
loginState();
}
bool isLoggedIn() => _loggedIn;
bool isLoading() => _loading;
FirebaseUser currentUser() => _user;
void login() async {
_loading = true;
notifyListeners();
_user = await _handleSignIn();
_loading = false;
if (_user != null) {
_prefs.setBool('isLoggedIn', true);
_loggedIn = true;
notifyListeners();
} else {
_loggedIn = false;
notifyListeners();
}
}
void logout() {
_prefs.clear();
_googleSignIn.signOut();
_loggedIn = false;
notifyListeners();
}
Future<FirebaseUser> _handleSignIn() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
print("signed in " + user.displayName);
return user;
}
void loginState() async {
_prefs = await SharedPreferences.getInstance();
if (_prefs.containsKey('isLoggedIn')) {
_user = await _auth.currentUser();
_loggedIn = _user != null;
_loading = false;
notifyListeners();
} else {
_loading = false;
notifyListeners();
}
}
}
+21 -8
View File
@@ -1,21 +1,34 @@
import 'package:como_gasto/login_state.dart';
import 'package:como_gasto/pages/add_page.dart';
import 'package:como_gasto/pages/home_page.dart';
import 'package:como_gasto/pages/login_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
return ChangeNotifierProvider<LoginState>(
builder: (BuildContext context) => LoginState(),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routes: {
'/': (BuildContext context) {
var state = Provider.of<LoginState>(context);
if (state.isLoggedIn()) {
return HomePage();
} else {
return LoginPage();
}
},
'/add': (BuildContext contex) => AddPage(),
},
),
routes: {
'/': (BuildContext contex) => HomePage(),
'/add': (BuildContext contex) => AddPage(),
},
);
}
}
+2 -2
View File
@@ -9,11 +9,11 @@ class MonthWidget extends StatefulWidget {
final List<double> perDay;
final Map<String, double> categories;
MonthWidget({Key key, this.documents})
MonthWidget({Key key, this.documents, days})
:
total = documents.map((doc) => doc['value'])
.fold(0.0, (a, b) => a + b),
perDay = List.generate(30, (int index) {
perDay = List.generate(days, (int index) {
return documents.where((doc) => doc['day'] == (index + 1))
.map((doc) => doc['value'])
.fold(0.0, (a, b) => a + b);
+6
View File
@@ -2,6 +2,9 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:como_gasto/category_selection_widget.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import '../login_state.dart';
class AddPage extends StatefulWidget {
@override
@@ -182,8 +185,11 @@ class _AddPageState extends State<AddPage> {
),
),
onPressed: () {
var user = Provider.of<LoginState>(context).currentUser();
if (value > 0 && category != "") {
Firestore.instance
.collection('users')
.document(user.uid)
.collection('expenses')
.document()
.setData({
+48 -32
View File
@@ -2,6 +2,10 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:como_gasto/month_widget.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import '../login_state.dart';
import '../utils.dart';
class HomePage extends StatefulWidget {
@override
@@ -10,61 +14,69 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
PageController _controller;
int currentPage = 9;
int currentPage = DateTime.now().month - 1;
Stream<QuerySnapshot> _query;
@override
void initState() {
super.initState();
_query = Firestore.instance
.collection('expenses')
.where("month", isEqualTo: currentPage + 1)
.snapshots();
_controller = PageController(
initialPage: currentPage,
viewportFraction: 0.4,
);
}
Widget _bottomAction(IconData icon) {
Widget _bottomAction(IconData icon, Function callback) {
return InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(icon),
),
onTap: () {},
onTap: callback,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomAppBar(
notchMargin: 8.0,
shape: CircularNotchedRectangle(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_bottomAction(FontAwesomeIcons.history),
_bottomAction(FontAwesomeIcons.chartPie),
SizedBox(width: 48.0),
_bottomAction(FontAwesomeIcons.wallet),
_bottomAction(Icons.settings),
],
return Consumer<LoginState>(
builder: (BuildContext context, LoginState state, Widget child) {
var user = Provider.of<LoginState>(context).currentUser();
_query = Firestore.instance
.collection('users')
.document(user.uid)
.collection('expenses')
.where("month", isEqualTo: currentPage + 1)
.snapshots();
return Scaffold(
bottomNavigationBar: BottomAppBar(
notchMargin: 8.0,
shape: CircularNotchedRectangle(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_bottomAction(FontAwesomeIcons.history, () {}),
_bottomAction(FontAwesomeIcons.chartPie, () {}),
SizedBox(width: 48.0),
_bottomAction(FontAwesomeIcons.wallet, () {}),
_bottomAction(Icons.settings, () {
Provider.of<LoginState>(context).logout();
}),
],
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Navigator.of(context).pushNamed('/add');
},
),
body: _body(),
);
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Navigator.of(context).pushNamed('/add');
},
),
body: _body(),
);
});
}
Widget _body() {
@@ -77,6 +89,7 @@ class _HomePageState extends State<HomePage> {
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> data) {
if (data.hasData) {
return MonthWidget(
days: daysInMonth(currentPage + 1),
documents: data.data.documents,
);
}
@@ -127,8 +140,11 @@ class _HomePageState extends State<HomePage> {
child: PageView(
onPageChanged: (newPage) {
setState(() {
var user = Provider.of<LoginState>(context).currentUser();
currentPage = newPage;
_query = Firestore.instance
.collection('users')
.document(user.uid)
.collection('expenses')
.where("month", isEqualTo: currentPage + 1)
.snapshots();
+29
View File
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../login_state.dart';
class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Consumer<LoginState>(
builder: (BuildContext context, LoginState value, Widget child) {
if (value.isLoading()) {
return CircularProgressIndicator();
} else {
return child;
}
},
child: RaisedButton(
child: Text("Sign In"),
onPressed: () {
Provider.of<LoginState>(context).login();
},
),
),
),
);
}
}
+15
View File
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class Demo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
Provider<String>.value(
value: 'Hello World',
child: Consumer<String>(
builder: (context, value, child) => Text(value),
),
);
}
}
+9
View File
@@ -0,0 +1,9 @@
int daysInMonth(int month) {
var now = DateTime.now();
var lastDayDateTime = (month < 12) ?
new DateTime(now.year, month + 1, 0) : new DateTime(now.year + 1, 1, 0);
return lastDayDateTime.day;
}
+30 -2
View File
@@ -42,7 +42,7 @@ packages:
name: cloud_firestore
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.13+1"
version: "0.11.0+2"
collection:
dependency: transitive
description:
@@ -57,13 +57,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
firebase_auth:
dependency: "direct main"
description:
name: firebase_auth
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.1"
firebase_core:
dependency: transitive
description:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.4"
version: "0.4.0+1"
flutter:
dependency: "direct main"
description: flutter
@@ -81,6 +88,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.4.0"
google_sign_in:
dependency: "direct main"
description:
name: google_sign_in
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.1+3"
intl:
dependency: transitive
description:
@@ -123,6 +137,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
quiver:
dependency: transitive
description:
@@ -130,6 +151,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.2"
sky_engine:
dependency: transitive
description: flutter
+5 -1
View File
@@ -21,11 +21,15 @@ dependencies:
sdk: flutter
charts_flutter: ^0.6.0
font_awesome_flutter: ^8.4.0
cloud_firestore: ^0.9.13+1
cloud_firestore: ^0.11.0+2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
provider: ^2.0.1
google_sign_in: ^4.0.1+3
firebase_auth: ^0.11.1
shared_preferences: ^0.5.2
dev_dependencies:
flutter_test: