Add login
This commit is contained in:
@@ -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
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user