Add animations and details page screen

This commit is contained in:
Ricardo Markiewicz
2019-06-28 11:48:17 -03:00
parent de396d9fa3
commit ffbec2acfd
9 changed files with 392 additions and 81 deletions
+15
View File
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
class AddPageTransition extends PageRouteBuilder {
final Widget page;
final Widget background;
AddPageTransition({this.page, this.background})
: super(
transitionDuration: Duration(microseconds: 1),
pageBuilder: (context, animation1, animation2) => page,
transitionsBuilder: (context, animation1, animation, child) =>
Stack(
children: <Widget>[background, child],
));
}
+30 -4
View File
@@ -3,16 +3,42 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart';
class GraphWidget extends StatefulWidget {
class PieGraphWidget extends StatefulWidget {
final List<double> data;
const GraphWidget({Key key, this.data}) : super(key: key);
const PieGraphWidget({Key key, this.data}) : super(key: key);
@override
_GraphWidgetState createState() => _GraphWidgetState();
_PieGraphWidgetState createState() => _PieGraphWidgetState();
}
class _GraphWidgetState extends State<GraphWidget> {
class _PieGraphWidgetState extends State<PieGraphWidget> {
@override
Widget build(BuildContext context) {
List<Series<double, num>> series = [
Series<double, int>(
id: 'Gasto',
domainFn: (value, index) => index,
measureFn: (value, _) => value,
data: widget.data,
strokeWidthPxFn: (_, __) => 4,
)
];
return PieChart(series);
}
}
class LinesGraphWidget extends StatefulWidget {
final List<double> data;
const LinesGraphWidget({Key key, this.data}) : super(key: key);
@override
_LinesGraphWidgetState createState() => _LinesGraphWidgetState();
}
class _LinesGraphWidgetState extends State<LinesGraphWidget> {
_onSelectionChanged(SelectionModel model) {
final selectedDatum = model.selectedDatum;
+14 -1
View File
@@ -1,5 +1,7 @@
import 'package:como_gasto/add_page_transition.dart';
import 'package:como_gasto/login_state.dart';
import 'package:como_gasto/pages/add_page.dart';
import 'package:como_gasto/pages/details_page.dart';
import 'package:como_gasto/pages/home_page.dart';
import 'package:como_gasto/pages/login_page.dart';
import 'package:flutter/material.dart';
@@ -17,6 +19,18 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
onGenerateRoute: (settings) {
if (settings.name == '/details') {
DetailsParams params = settings.arguments;
return MaterialPageRoute(
builder: (BuildContext context) {
return DetailsPage(
params: params ,
);
}
);
}
},
routes: {
'/': (BuildContext context) {
var state = Provider.of<LoginState>(context);
@@ -26,7 +40,6 @@ class MyApp extends StatelessWidget {
return LoginPage();
}
},
'/add': (BuildContext contex) => AddPage(),
},
),
);
+29 -7
View File
@@ -1,15 +1,23 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:como_gasto/graph_widget.dart';
import 'package:como_gasto/pages/details_page.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
enum GraphType {
LINES,
PIE,
}
class MonthWidget extends StatefulWidget {
final List<DocumentSnapshot> documents;
final double total;
final List<double> perDay;
final Map<String, double> categories;
final GraphType graphType;
final int month;
MonthWidget({Key key, this.documents, days})
MonthWidget({Key key, @required this.month, this.graphType, this.documents, days})
:
total = documents.map((doc) => doc['value'])
.fold(0.0, (a, b) => a + b),
@@ -72,16 +80,30 @@ class _MonthWidgetState extends State<MonthWidget> {
}
Widget _graph() {
return Container(
height: 250.0,
child: GraphWidget(
data: widget.perDay,
),
);
if (widget.graphType == GraphType.LINES) {
return Container(
height: 250.0,
child: LinesGraphWidget(
data: widget.perDay,
),
);
} else {
var perCategory = widget.categories.keys.map((name) => widget.categories[name] / widget.total).toList();
return Container(
height: 250.0,
child: PieGraphWidget(
data: perCategory,
),
);
}
}
Widget _item(IconData icon, String name, int percent, double value) {
return ListTile(
onTap: () {
Navigator.of(context).pushNamed("/details",
arguments: DetailsParams(name, widget.month));
},
leading: Icon(icon, size: 32.0,),
title: Text(name,
style: TextStyle(
+147 -61
View File
@@ -7,51 +7,101 @@ import 'package:provider/provider.dart';
import '../login_state.dart';
class AddPage extends StatefulWidget {
final Rect buttonRect;
const AddPage({Key key, this.buttonRect}) : super(key: key);
@override
_AddPageState createState() => _AddPageState();
}
class _AddPageState extends State<AddPage> {
class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation _buttonAnimation;
Animation _pageAnimation;
String category;
int value = 0;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 750),
);
_buttonAnimation = Tween<double>(begin: 0, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn)
);
_pageAnimation = Tween<double>(begin: -1, end: 1.0).animate(
CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn)
);
_controller.addListener(() {
print(_controller.value);
setState(() {});
});
_controller.addStatusListener((status) {
if (status == AnimationStatus.dismissed) {
Navigator.of(context).pop();
}
});
_controller.forward();
}
@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,
var h = MediaQuery.of(context).size.height;
return Stack(
children: [
Transform.translate(
offset: Offset(0, h * (1 - _pageAnimation.value)),
child: 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: () {
_controller.reverse();
},
)
],
),
body: _body(),
),
),
centerTitle: false,
actions: <Widget>[
IconButton(
icon: Icon(
Icons.close,
color: Colors.grey,
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
body: _body(),
_submit(),
],
);
}
Widget _body() {
var h = MediaQuery.of(context).size.height;
return Column(
children: <Widget>[
_categorySelector(),
_currentValue(),
_numpad(),
_submit(),
SizedBox(
height: h - widget.buttonRect.top,
)
],
);
}
@@ -169,45 +219,81 @@ class _AddPageState extends State<AddPage> {
}
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,
if (_controller.value < 1) {
var buttonWidth = widget.buttonRect.right - widget.buttonRect.left;
var w = MediaQuery.of(context).size.width;
return Positioned(
left: widget.buttonRect.left * (1 - _buttonAnimation.value),
//<-- Margin from left
right: (w - widget.buttonRect.right) * (1 - _buttonAnimation.value),
//<-- Margin from right
top: widget.buttonRect.top,
//<-- Margin from top
bottom: (MediaQuery.of(context).size.height - widget.buttonRect.bottom) *
(1 - _buttonAnimation.value),
//<-- Margin from bottom
child: Container(
width: double.infinity,
//<-- Blue cirle
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
buttonWidth * (1 - _buttonAnimation.value)),
color: Colors.blueAccent,
),
child: MaterialButton(
child: Text(
"Add expense",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
),
onPressed: () {
var user = Provider.of<LoginState>(context).currentUser();
if (value > 0 && category != "") {
Firestore.instance
.collection('users')
.document(user.uid)
.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")));
}
},
),
),
);
} else {
return Positioned(
top: widget.buttonRect.top,
bottom: 0,
left: 0,
right: 0,
child: Builder(builder: (BuildContext context) {
return Container(
decoration: BoxDecoration(color: Colors.blueAccent),
child: MaterialButton(
child: Text(
"Add expense",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: () {
var user = Provider.of<LoginState>(context).currentUser();
if (value > 0 && category != "") {
Firestore.instance
.collection('users')
.document(user.uid)
.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")));
}
},
),
);
}),
);
});
}
}
}
+110
View File
@@ -0,0 +1,110 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../login_state.dart';
class DetailsParams {
final String categoryName;
final int month;
DetailsParams(this.categoryName, this.month);
}
class DetailsPage extends StatefulWidget {
final DetailsParams params;
const DetailsPage({Key key, this.params}) : super(key: key);
@override
_DetailsPageState createState() => _DetailsPageState();
}
class _DetailsPageState extends State<DetailsPage> {
@override
Widget build(BuildContext context) {
return Consumer<LoginState>(
builder: (BuildContext context, LoginState state, Widget child) {
var user = Provider.of<LoginState>(context).currentUser();
var _query = Firestore.instance
.collection('users')
.document(user.uid)
.collection('expenses')
.where("month", isEqualTo: widget.params.month + 1)
.where("category", isEqualTo: widget.params.categoryName)
.snapshots();
return Scaffold(
appBar: AppBar(
title: Text(widget.params.categoryName),
),
body: StreamBuilder<QuerySnapshot>(
stream: _query,
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> data) {
if (data.hasData) {
return ListView.builder(
itemBuilder: (BuildContext context, int index) {
var document = data.data.documents[index];
return Dismissible(
key: Key(document.documentID),
onDismissed: (direction) {
Firestore.instance
.collection('users')
.document(user.uid)
.collection('expenses')
.document(document.documentID)
.delete();
},
child: ListTile(
leading: Stack(
children: <Widget>[
Icon(
Icons.calendar_today,
size: 40,
),
Positioned(
left: 0,
right: 0,
bottom: 8,
child: Text(
document["day"].toString(),
textAlign: TextAlign.center,
),
)
],
),
title: Container(
decoration: BoxDecoration(
color: Colors.blueAccent.withOpacity(0.2),
borderRadius: BorderRadius.circular(5.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"\$${document["value"]}",
style: TextStyle(
color: Colors.blueAccent,
fontWeight: FontWeight.w500,
fontSize: 16.0,
),
),
),
),
),
);
},
itemCount: data.data.documents.length,
);
}
return Center(
child: CircularProgressIndicator(),
);
},
));
},
);
}
}
+39 -8
View File
@@ -1,8 +1,11 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:como_gasto/add_page_transition.dart';
import 'package:como_gasto/month_widget.dart';
import 'package:como_gasto/pages/add_page.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:rect_getter/rect_getter.dart';
import '../login_state.dart';
import '../utils.dart';
@@ -13,9 +16,13 @@ class HomePage extends StatefulWidget {
}
class _HomePageState extends State<HomePage> {
var globalKey = RectGetter.createGlobalKey();
Rect buttonRect;
PageController _controller;
int currentPage = DateTime.now().month - 1;
Stream<QuerySnapshot> _query;
GraphType currentType = GraphType.LINES;
@override
void initState() {
@@ -57,22 +64,44 @@ class _HomePageState extends State<HomePage> {
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_bottomAction(FontAwesomeIcons.history, () {}),
_bottomAction(FontAwesomeIcons.chartPie, () {}),
_bottomAction(FontAwesomeIcons.chartLine, () {
setState(() {
currentType = GraphType.LINES;
});
}),
_bottomAction(FontAwesomeIcons.chartPie, () {
setState(() {
currentType = GraphType.PIE;
});
}),
SizedBox(width: 48.0),
_bottomAction(FontAwesomeIcons.wallet, () {}),
_bottomAction(Icons.settings, () {
_bottomAction(FontAwesomeIcons.signOutAlt, () {
Provider.of<LoginState>(context).logout();
}),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Navigator.of(context).pushNamed('/add');
},
floatingActionButton: RectGetter(
key: globalKey,
child: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
buttonRect = RectGetter.getRectFromKey(globalKey);
print(buttonRect);
var page = AddPageTransition(
background: widget,
page: AddPage(
buttonRect: buttonRect,
),
);
Navigator.of(context).push(page);
},
),
),
body: _body(),
);
@@ -91,6 +120,8 @@ class _HomePageState extends State<HomePage> {
return MonthWidget(
days: daysInMonth(currentPage + 1),
documents: data.data.documents,
graphType: currentType,
month: currentPage,
);
}
+7
View File
@@ -151,6 +151,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
rect_getter:
dependency: "direct main"
description:
name: rect_getter
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1"
shared_preferences:
dependency: "direct main"
description:
+1
View File
@@ -30,6 +30,7 @@ dependencies:
google_sign_in: ^4.0.1+3
firebase_auth: ^0.11.1
shared_preferences: ^0.5.2
rect_getter: ^0.0.1
dev_dependencies:
flutter_test: