first commit

This commit is contained in:
Ricardo Markiewicz
2019-04-09 11:22:59 -03:00
commit 30324991f5
58 changed files with 1829 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart';
class GraphWidget extends StatefulWidget {
@override
_GraphWidgetState createState() => _GraphWidgetState();
}
class _GraphWidgetState extends State<GraphWidget> {
var data;
@override
void initState() {
super.initState();
var r = Random();
data = List<double>.generate(30, (i) => r.nextDouble() * 1500);
}
_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: 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,
),
),
);
}
}
+227
View File
@@ -0,0 +1,227 @@
import 'package:como_gasto/graph_widget.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
PageController _controller;
int currentPage = 9;
@override
void initState() {
super.initState();
_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(),
_expenses(),
_graph(),
Container(
color: Colors.blueAccent.withOpacity(0.15),
height: 24.0,
),
_list(),
],
),
);
}
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;
});
},
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),
],
),
);
}
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,
);
},
),
);
}
}