Add Firestore support
This commit is contained in:
+25
-83
@@ -1,6 +1,8 @@
|
||||
import 'package:como_gasto/graph_widget.dart';
|
||||
import 'package:como_gasto/month_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
@@ -25,12 +27,18 @@ class HomePage extends StatefulWidget {
|
||||
class _HomePageState extends State<HomePage> {
|
||||
PageController _controller;
|
||||
int currentPage = 9;
|
||||
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,
|
||||
@@ -79,13 +87,20 @@ class _HomePageState extends State<HomePage> {
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
_selector(),
|
||||
_expenses(),
|
||||
_graph(),
|
||||
Container(
|
||||
color: Colors.blueAccent.withOpacity(0.15),
|
||||
height: 24.0,
|
||||
StreamBuilder<QuerySnapshot>(
|
||||
stream: _query,
|
||||
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> data) {
|
||||
if (data.hasData) {
|
||||
return MonthWidget(
|
||||
documents: data.data.documents,
|
||||
);
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
),
|
||||
_list(),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -127,6 +142,10 @@ class _HomePageState extends State<HomePage> {
|
||||
onPageChanged: (newPage) {
|
||||
setState(() {
|
||||
currentPage = newPage;
|
||||
_query = Firestore.instance
|
||||
.collection('expenses')
|
||||
.where("month", isEqualTo: currentPage + 1)
|
||||
.snapshots();
|
||||
});
|
||||
},
|
||||
controller: _controller,
|
||||
@@ -147,81 +166,4 @@ class _HomePageState extends State<HomePage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _expenses() {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Text("\$2361,41",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 40.0,
|
||||
),
|
||||
),
|
||||
Text("Total expenses",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16.0,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _graph() {
|
||||
return Container(
|
||||
height: 250.0,
|
||||
child: GraphWidget(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _item(IconData icon, String name, int percent, double value) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, size: 32.0,),
|
||||
title: Text(name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0
|
||||
),
|
||||
),
|
||||
subtitle: Text("$percent% of expenses",
|
||||
style: TextStyle(
|
||||
fontSize: 16.0,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
trailing: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blueAccent.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(5.0),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text("\$$value",
|
||||
style: TextStyle(
|
||||
color: Colors.blueAccent,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 16.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _list() {
|
||||
return Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: 15,
|
||||
itemBuilder: (BuildContext context, int index) =>
|
||||
_item(FontAwesomeIcons.shoppingCart, "Shopping", 14, 145.12),
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
color: Colors.blueAccent.withOpacity(0.15),
|
||||
height: 8.0,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user