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
+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,
);
}