Add screen to add expenses

This commit is contained in:
Ricardo Markiewicz
2019-05-08 15:15:32 -03:00
parent eb622bf75d
commit 8565676896
6 changed files with 462 additions and 158 deletions
+4 -4
View File
@@ -153,9 +153,9 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
BoringSSL-GRPC: 2a230d9cd93e7ce39916044f645cebb31f37dde6 BoringSSL-GRPC: 2a230d9cd93e7ce39916044f645cebb31f37dde6
cloud_firestore: 980813a98d8beb5c321b589845fabf6c4c5bd571 cloud_firestore: cd6e849ecb8ab43e5a7a5f1f169304ca65436c03
Firebase: 02f3281965c075426141a0ce1277e9de6649cab9 Firebase: 02f3281965c075426141a0ce1277e9de6649cab9
firebase_core: c96aa8b2fcf7f5167d32f22034f502f9304952b8 firebase_core: ce5006bb48508ee4e71e0f429a3f519bb8ee2961
FirebaseAnalytics: 23851fe602c872130a2c5c55040b302120346cc2 FirebaseAnalytics: 23851fe602c872130a2c5c55040b302120346cc2
FirebaseAuth: d85d052354447f30b4b2a805ab91b511458b56a6 FirebaseAuth: d85d052354447f30b4b2a805ab91b511458b56a6
FirebaseAuthInterop: 0ffa57668be100582bb7643d4fcb7615496c41fc FirebaseAuthInterop: 0ffa57668be100582bb7643d4fcb7615496c41fc
@@ -163,7 +163,7 @@ SPEC CHECKSUMS:
FirebaseDatabase: 23acb0c53cd4d4070a427b60100b2e4aaa97c45d FirebaseDatabase: 23acb0c53cd4d4070a427b60100b2e4aaa97c45d
FirebaseFirestore: ccdaffb8a73c591ff61872b8f7905ad0c237ef50 FirebaseFirestore: ccdaffb8a73c591ff61872b8f7905ad0c237ef50
FirebaseInstanceID: bd6fc5a258884e206fd5c474ebe4f5b00e21770e FirebaseInstanceID: bd6fc5a258884e206fd5c474ebe4f5b00e21770e
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296 Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
GoogleAppMeasurement: 6cf307834da065863f9faf4c0de0a936d81dd832 GoogleAppMeasurement: 6cf307834da065863f9faf4c0de0a936d81dd832
GoogleUtilities: 111a012f4c3a29c9e7c954c082fafd6ee3c999c0 GoogleUtilities: 111a012f4c3a29c9e7c954c082fafd6ee3c999c0
"gRPC-C++": e76441995900ac90e9bd98644ab4733f12521edf "gRPC-C++": e76441995900ac90e9bd98644ab4733f12521edf
@@ -175,4 +175,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: ebd43b443038e611b86ede96e613bd6033c49497 PODFILE CHECKSUM: ebd43b443038e611b86ede96e613bd6033c49497
COCOAPODS: 1.5.3 COCOAPODS: 1.6.1
+12 -2
View File
@@ -20,6 +20,7 @@
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
A6A775CC0410D5E148B36BC7 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EC1352646DE8B1C75FB9257 /* Pods_Runner.framework */; }; A6A775CC0410D5E148B36BC7 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EC1352646DE8B1C75FB9257 /* Pods_Runner.framework */; };
CFF572AD227F58EC009AA360 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = CFF572AC227F58EC009AA360 /* GoogleService-Info.plist */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
@@ -40,13 +41,16 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
1D188F69AC2C1AEA7F766AE2 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
47AE0F36804CB50B9938F627 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
6EC1352646DE8B1C75FB9257 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6EC1352646DE8B1C75FB9257 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
714068D4226768AA00F32532 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; }; 714068D4226768AA00F32532 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
848AEC1F9140B31C18CDC953 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; }; 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
@@ -55,6 +59,7 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CFF572AC227F58EC009AA360 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../../../Downloads/GoogleService-Info.plist"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@@ -119,6 +124,7 @@
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
714068D4226768AA00F32532 /* GoogleService-Info.plist */, 714068D4226768AA00F32532 /* GoogleService-Info.plist */,
97C147021CF9000F007C117D /* Info.plist */, 97C147021CF9000F007C117D /* Info.plist */,
CFF572AC227F58EC009AA360 /* GoogleService-Info.plist */,
97C146F11CF9000F007C117D /* Supporting Files */, 97C146F11CF9000F007C117D /* Supporting Files */,
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
@@ -138,6 +144,9 @@
B2B921052E5B0B1DDFA66EF4 /* Pods */ = { B2B921052E5B0B1DDFA66EF4 /* Pods */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
1D188F69AC2C1AEA7F766AE2 /* Pods-Runner.debug.xcconfig */,
848AEC1F9140B31C18CDC953 /* Pods-Runner.release.xcconfig */,
47AE0F36804CB50B9938F627 /* Pods-Runner.profile.xcconfig */,
); );
name = Pods; name = Pods;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -212,6 +221,7 @@
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
714068D5226768AA00F32532 /* GoogleService-Info.plist in Resources */, 714068D5226768AA00F32532 /* GoogleService-Info.plist in Resources */,
CFF572AD227F58EC009AA360 /* GoogleService-Info.plist in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -238,7 +248,7 @@
files = ( files = (
); );
inputPaths = ( inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/BoringSSL-GRPC/openssl_grpc.framework", "${BUILT_PRODUCTS_DIR}/BoringSSL-GRPC/openssl_grpc.framework",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework", "${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework",
@@ -263,7 +273,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0; showEnvVarsInLog = 0;
}; };
9740EEB61CF901F6004384FC /* Run Script */ = { 9740EEB61CF901F6004384FC /* Run Script */ = {
+75
View File
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
class CategorySelectionWidget extends StatefulWidget {
final Map<String, IconData> categories;
final Function(String) onValueChanged;
const CategorySelectionWidget({Key key, this.categories, this.onValueChanged}) : super(key: key);
@override
_CategorySelectionWidgetState createState() =>
_CategorySelectionWidgetState();
}
class CategoryWidget extends StatelessWidget {
final String name;
final IconData icon;
final bool selected;
const CategoryWidget({Key key, this.name, this.icon, this.selected})
: super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
border: Border.all(
color: selected ? Colors.blueAccent : Colors.grey,
width: selected ? 3.0 : 1.0,
),
),
child: Icon(icon),
),
Text(name),
],
),
);
}
}
class _CategorySelectionWidgetState extends State<CategorySelectionWidget> {
String currentItem = "Shopping";
@override
Widget build(BuildContext context) {
var widgets = <Widget>[];
widget.categories.forEach((name, icon) {
widgets.add(GestureDetector(
onTap: () {
setState(() {
currentItem = name;
});
widget.onValueChanged(name);
},
child: CategoryWidget(
name: name,
icon: icon,
selected: name == currentItem,
),
));
});
return ListView(
scrollDirection: Axis.horizontal,
children: widgets,
);
}
}
+6 -152
View File
@@ -1,8 +1,6 @@
import 'package:como_gasto/graph_widget.dart'; import 'package:como_gasto/pages/add_page.dart';
import 'package:como_gasto/month_widget.dart'; import 'package:como_gasto/pages/home_page.dart';
import 'package:flutter/material.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()); void main() => runApp(MyApp());
@@ -14,156 +12,12 @@ class MyApp extends StatelessWidget {
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
home: HomePage(), routes: {
); '/': (BuildContext contex) => HomePage(),
} '/add': (BuildContext contex) => AddPage(),
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
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,
);
}
Widget _bottomAction(IconData icon) {
return InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(icon),
),
onTap: () {},
);
}
@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),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
),
body: _body(),
);
}
Widget _body() {
return SafeArea(
child: Column(
children: <Widget>[
_selector(),
StreamBuilder<QuerySnapshot>(
stream: _query,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> data) {
if (data.hasData) {
return MonthWidget(
documents: data.data.documents,
);
}
return Center(
child: CircularProgressIndicator(),
);
}, },
),
],
),
); );
} }
}
Widget _pageItem(String name, int position) {
var _alignment;
final selected = TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.blueGrey,
);
final unselected = TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.normal,
color: Colors.blueGrey.withOpacity(0.4),
);
if (position == currentPage) {
_alignment = Alignment.center;
} else if (position > currentPage) {
_alignment = Alignment.centerRight;
} else {
_alignment = Alignment.centerLeft;
}
return Align(
alignment: _alignment,
child: Text(name,
style: position == currentPage ? selected : unselected,
),
);
}
Widget _selector() {
return SizedBox.fromSize(
size: Size.fromHeight(70.0),
child: PageView(
onPageChanged: (newPage) {
setState(() {
currentPage = newPage;
_query = Firestore.instance
.collection('expenses')
.where("month", isEqualTo: currentPage + 1)
.snapshots();
});
},
controller: _controller,
children: <Widget>[
_pageItem("Enero", 0),
_pageItem("Febrero", 1),
_pageItem("Marzo", 2),
_pageItem("Abril", 3),
_pageItem("Mayo", 4),
_pageItem("Junio", 5),
_pageItem("Julio", 6),
_pageItem("Agosto", 7),
_pageItem("Septiembre", 8),
_pageItem("Octubre", 9),
_pageItem("Noviembre", 10),
_pageItem("Diciembre", 11),
],
),
);
}
}
+207
View File
@@ -0,0 +1,207 @@
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';
class AddPage extends StatefulWidget {
@override
_AddPageState createState() => _AddPageState();
}
class _AddPageState extends State<AddPage> {
String category;
int value = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text(
"Category",
style: TextStyle(
color: Colors.grey,
),
),
centerTitle: false,
actions: <Widget>[
IconButton(
icon: Icon(
Icons.close,
color: Colors.grey,
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
body: _body(),
);
}
Widget _body() {
return Column(
children: <Widget>[
_categorySelector(),
_currentValue(),
_numpad(),
_submit(),
],
);
}
Widget _categorySelector() {
return Container(
height: 80.0,
child: CategorySelectionWidget(
categories: {
"Shopping": Icons.shopping_cart,
"Alcohol": FontAwesomeIcons.beer,
"Fast food": FontAwesomeIcons.hamburger,
"Bills": FontAwesomeIcons.wallet,
},
onValueChanged: (newCategory) => category = newCategory,
),
);
}
Widget _currentValue() {
var realValue = value / 100.0;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 32.0),
child: Text(
"\$${realValue.toStringAsFixed(2)}",
style: TextStyle(
fontSize: 50.0,
color: Colors.blueAccent,
fontWeight: FontWeight.w500,
),
),
);
}
Widget _num(String text, double height) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
setState(() {
if (text == ",") {
value = value * 100;
} else {
value = value * 10 + int.parse(text);
}
});
},
child: Container(
height: height,
child: Center(
child: Text(
text,
style: TextStyle(
fontSize: 40,
color: Colors.grey,
),
),
),
),
);
}
Widget _numpad() {
return Expanded(
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
var height = constraints.biggest.height / 4;
return Table(
border: TableBorder.all(
color: Colors.grey,
width: 1.0,
),
children: [
TableRow(children: [
_num("1", height),
_num("2", height),
_num("3", height),
]),
TableRow(children: [
_num("4", height),
_num("5", height),
_num("6", height),
]),
TableRow(children: [
_num("7", height),
_num("8", height),
_num("9", height),
]),
TableRow(children: [
_num(",", height),
_num("0", height),
GestureDetector(
onTap: () {
setState(() {
value = value ~/ 10;
});
},
child: Container(
height: height,
child: Center(
child: Icon(
Icons.backspace,
color: Colors.grey,
size: 40,
),
),
),
),
]),
],
);
}),
);
}
Widget _submit() {
return Builder(builder: (BuildContext context) {
return Hero(
tag: "add_button",
child: Container(
height: 50.0,
width: double.infinity,
decoration: BoxDecoration(color: Colors.blueAccent),
child: MaterialButton(
child: Text(
"Add expense",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: () {
if (value > 0 && category != "") {
Firestore.instance
.collection('expenses')
.document()
.setData({
"category": category,
"value": value / 100.0,
"month": DateTime.now().month,
"day": DateTime.now().day,
});
Navigator.of(context).pop();
} else {
Scaffold.of(context).showSnackBar(
SnackBar(content: Text("Select a value and a cagtegory")));
}
},
),
),
);
});
}
}
+158
View File
@@ -0,0 +1,158 @@
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';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
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,
);
}
Widget _bottomAction(IconData icon) {
return InkWell(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(icon),
),
onTap: () {},
);
}
@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),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Hero(
tag: "add_button",
child: Icon(Icons.add),
),
onPressed: () {
Navigator.of(context).pushNamed('/add');
},
),
body: _body(),
);
}
Widget _body() {
return SafeArea(
child: Column(
children: <Widget>[
_selector(),
StreamBuilder<QuerySnapshot>(
stream: _query,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> data) {
if (data.hasData) {
return MonthWidget(
documents: data.data.documents,
);
}
return Center(
child: CircularProgressIndicator(),
);
},
),
],
),
);
}
Widget _pageItem(String name, int position) {
var _alignment;
final selected = TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.blueGrey,
);
final unselected = TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.normal,
color: Colors.blueGrey.withOpacity(0.4),
);
if (position == currentPage) {
_alignment = Alignment.center;
} else if (position > currentPage) {
_alignment = Alignment.centerRight;
} else {
_alignment = Alignment.centerLeft;
}
return Align(
alignment: _alignment,
child: Text(
name,
style: position == currentPage ? selected : unselected,
),
);
}
Widget _selector() {
return SizedBox.fromSize(
size: Size.fromHeight(70.0),
child: PageView(
onPageChanged: (newPage) {
setState(() {
currentPage = newPage;
_query = Firestore.instance
.collection('expenses')
.where("month", isEqualTo: currentPage + 1)
.snapshots();
});
},
controller: _controller,
children: <Widget>[
_pageItem("Enero", 0),
_pageItem("Febrero", 1),
_pageItem("Marzo", 2),
_pageItem("Abril", 3),
_pageItem("Mayo", 4),
_pageItem("Junio", 5),
_pageItem("Julio", 6),
_pageItem("Agosto", 7),
_pageItem("Septiembre", 8),
_pageItem("Octubre", 9),
_pageItem("Noviembre", 10),
_pageItem("Diciembre", 11),
],
),
);
}
}