mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-04-03 14:22:03 +00:00
Added covid-19 example app and Updated the readme (#73)
This commit is contained in:
51
covid19_mobile_app/lib/widgets/graph.dart
Normal file
51
covid19_mobile_app/lib/widgets/graph.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:bezier_chart/bezier_chart.dart';
|
||||
|
||||
// Widget that will build the graph
|
||||
Widget buildGraph(
|
||||
BuildContext context, List<Map<String, dynamic>> datesAndValues) {
|
||||
// Data is avalaible from a particular date and we are getting that here
|
||||
final fromDate = datesAndValues[0]['date'];
|
||||
|
||||
// Data is avalaible until a particular date and we are getting that here
|
||||
final toDate = datesAndValues.last['date'];
|
||||
|
||||
// Add dates and values corresponding to those dates
|
||||
// in a list
|
||||
List<DataPoint<DateTime>> dataPoints = [];
|
||||
for (final dateAndValue in datesAndValues) {
|
||||
dataPoints.add(DataPoint<DateTime>(
|
||||
value: double.parse(dateAndValue['value'].toString()),
|
||||
xAxis: dateAndValue['date']));
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
),
|
||||
height: MediaQuery.of(context).size.height / 2,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: BezierChart(
|
||||
fromDate: fromDate,
|
||||
bezierChartScale: BezierChartScale.WEEKLY,
|
||||
toDate: toDate,
|
||||
selectedDate: toDate,
|
||||
series: [
|
||||
BezierLine(
|
||||
data: dataPoints,
|
||||
),
|
||||
],
|
||||
config: BezierChartConfig(
|
||||
physics: BouncingScrollPhysics(),
|
||||
verticalIndicatorStrokeWidth: 3.0,
|
||||
verticalIndicatorColor: Colors.black26,
|
||||
showVerticalIndicator: true,
|
||||
verticalIndicatorFixedPosition: false,
|
||||
backgroundColor: Colors.transparent,
|
||||
footerHeight: 30.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user