Add theme switcher
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AddPageTransition extends PageRouteBuilder {
|
||||
final Widget page;
|
||||
|
||||
AddPageTransition({this.page})
|
||||
: super(
|
||||
transitionDuration: Duration(microseconds: 1),
|
||||
pageBuilder: (context, animation1, animation2) => page,
|
||||
transitionsBuilder: (context, animation1, animation, child) => child);
|
||||
|
||||
@override
|
||||
bool get opaque => false;
|
||||
}
|
||||
@@ -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 = "";
|
||||
|
||||
@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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:charts_flutter/flutter.dart';
|
||||
|
||||
class PieGraphWidget extends StatefulWidget {
|
||||
final List<double> data;
|
||||
|
||||
const PieGraphWidget({Key key, this.data}) : super(key: key);
|
||||
|
||||
@override
|
||||
_PieGraphWidgetState createState() => _PieGraphWidgetState();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
var time;
|
||||
final measures = <String, double>{};
|
||||
|
||||
// We get the model that updated with a list of [SeriesDatum] which is
|
||||
// simply a pair of series & datum.
|
||||
//
|
||||
// Walk the selection updating the measures map, storing off the sales and
|
||||
// series name for each selection point.
|
||||
if (selectedDatum.isNotEmpty) {
|
||||
time = selectedDatum.first.datum;
|
||||
selectedDatum.forEach((SeriesDatum datumPair) {
|
||||
measures[datumPair.series.displayName] = datumPair.datum;
|
||||
});
|
||||
}
|
||||
|
||||
print(time);
|
||||
print(measures);
|
||||
|
||||
// Request a build.
|
||||
//setState(() {
|
||||
//_time = time;
|
||||
//_measures = measures;
|
||||
//});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Series<double, num>> series = [
|
||||
Series<double, int>(
|
||||
id: 'Gasto',
|
||||
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (value, index) => index,
|
||||
measureFn: (value, _) => value,
|
||||
data: widget.data,
|
||||
strokeWidthPxFn: (_, __) => 4,
|
||||
)
|
||||
];
|
||||
|
||||
return LineChart(series,
|
||||
animate: false,
|
||||
selectionModels: [
|
||||
SelectionModelConfig(
|
||||
type: SelectionModelType.info,
|
||||
changedListener: _onSelectionChanged,
|
||||
)
|
||||
],
|
||||
domainAxis: NumericAxisSpec(
|
||||
tickProviderSpec: StaticNumericTickProviderSpec(
|
||||
[
|
||||
TickSpec(0, label: '01'),
|
||||
TickSpec(4, label: '05'),
|
||||
TickSpec(9, label: '10'),
|
||||
TickSpec(14, label: '15'),
|
||||
TickSpec(19, label: '20'),
|
||||
TickSpec(24, label: '25'),
|
||||
TickSpec(29, label: '30'),
|
||||
]
|
||||
)
|
||||
),
|
||||
primaryMeasureAxis: NumericAxisSpec(
|
||||
tickProviderSpec: BasicNumericTickProviderSpec(
|
||||
desiredTickCount: 4,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:como_gasto/others/graph_widget.dart';
|
||||
import 'package:como_gasto/pages/details_page_container.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, @required this.month, this.graphType, this.documents, days})
|
||||
:
|
||||
total = documents.map((doc) => doc['value'])
|
||||
.fold(0.0, (a, b) => a + b),
|
||||
perDay = List.generate(days, (int index) {
|
||||
return documents.where((doc) => doc['day'] == (index + 1))
|
||||
.map((doc) => doc['value'])
|
||||
.fold(0.0, (a, b) => a + b);
|
||||
}),
|
||||
categories = documents.fold({}, (Map<String, double> map, document) {
|
||||
if (!map.containsKey(document['category'])) {
|
||||
map[document['category']] = 0.0;
|
||||
}
|
||||
|
||||
map[document['category']] += document['value'];
|
||||
return map;
|
||||
}),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_MonthWidgetState createState() => _MonthWidgetState();
|
||||
}
|
||||
|
||||
class _MonthWidgetState extends State<MonthWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print(widget.categories);
|
||||
return Expanded(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
_expenses(),
|
||||
_graph(),
|
||||
Container(
|
||||
color: Colors.blueAccent.withOpacity(0.15),
|
||||
height: 24.0,
|
||||
),
|
||||
_list(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _expenses() {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Text("\$${widget.total.toStringAsFixed(2)}",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 40.0,
|
||||
),
|
||||
),
|
||||
Text("Total expenses",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16.0,
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _graph() {
|
||||
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) {
|
||||
if (name == null) {
|
||||
name = "";
|
||||
}
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed("/details",
|
||||
arguments: DetailsParams(name, widget.month));
|
||||
},
|
||||
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: widget.categories.keys.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var key = widget.categories.keys.elementAt(index);
|
||||
var data = widget.categories[key];
|
||||
return _item(FontAwesomeIcons.shoppingCart, key, 100 * data ~/ widget.total, data);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
color: Colors.blueAccent.withOpacity(0.15),
|
||||
height: 8.0,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user