Created
October 20, 2020 11:05
-
-
Save melwinlobo18/a9850a09cc742558b6176a7f19814dd2 to your computer and use it in GitHub Desktop.
Text gets blurred when fl_chart is used
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:fl_chart/fl_chart.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
home: MyHomePage(title: 'Flutter Chart'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
void initState() { | |
super.initState(); | |
// Timer(Duration(microseconds: 0), () { | |
// /// start the intro | |
// intro.start(context); | |
// }); | |
} | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
SizedBox( | |
height: 20, | |
), | |
Padding( | |
padding: const EdgeInsets.only(left: 20.0), | |
child: Text( | |
"Resolved Defects Graph", | |
style: TextStyle(color: Colors.black.withOpacity(0.7)), | |
), | |
), | |
Container( | |
height: 250, | |
child: Row( | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: [ | |
Expanded( | |
child: Card( | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(15), | |
), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
Padding( | |
padding: | |
const EdgeInsets.only(left: 16, right: 8, top: 8), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
Text( | |
"Resolved Defects Graph", | |
style: TextStyle( | |
color: Colors.black.withOpacity(0.7)), | |
), | |
], | |
), | |
), | |
SizedBox( | |
height: 5, | |
), | |
BuildsChart(), | |
], | |
), | |
), | |
), | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
class BuildsChart extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() => BuildsChartState(); | |
} | |
class BuildsChartState extends State<BuildsChart> { | |
final Color barBackgroundColor = const Color(0xff72d8bf); | |
final Duration animDuration = const Duration(milliseconds: 250); | |
int touchedIndex; | |
bool isPlaying = false; | |
final List<Color> colors = [ | |
Colors.blueAccent, | |
Colors.deepOrangeAccent, | |
Colors.deepPurpleAccent, | |
Colors.lightGreen, | |
Colors.pinkAccent, | |
]; | |
final List<double> values = [20, 40, 100, 30, 50]; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
height: 180, | |
margin: const EdgeInsets.symmetric(horizontal: 20.0), | |
child: BarChart( | |
mainBarData(), | |
swapAnimationDuration: animDuration, | |
), | |
); | |
} | |
BarChartGroupData makeGroupData( | |
int x, | |
double y, { | |
bool isTouched = false, | |
Color barColor = Colors.white, | |
double width = 22, | |
List<int> showTooltips = const [], | |
}) { | |
return BarChartGroupData( | |
x: x, | |
barRods: [ | |
BarChartRodData( | |
y: 100, | |
colors: [Colors.transparent], | |
width: 15, | |
rodStackItems: [ | |
BarChartRodStackItem(0, y, Colors.blueAccent), | |
BarChartRodStackItem( | |
y, | |
100, | |
Colors.grey.withOpacity(0.2), | |
), | |
], | |
), | |
], | |
showingTooltipIndicators: showTooltips, | |
); | |
} | |
List<BarChartGroupData> showingGroups() { | |
List<BarChartGroupData> barChartGroupData = []; | |
for (int i = 0; i < 5; i++) { | |
barChartGroupData.add( | |
makeGroupData( | |
i, | |
values[i], | |
isTouched: i == touchedIndex, | |
barColor: colors[i], | |
), | |
); | |
} | |
return barChartGroupData; | |
} | |
BarChartData mainBarData() { | |
return BarChartData( | |
alignment: BarChartAlignment.spaceBetween, | |
titlesData: FlTitlesData( | |
show: true, | |
bottomTitles: SideTitles( | |
showTitles: true, | |
getTextStyles: (value) => const TextStyle( | |
fontSize: 12, | |
color: Colors.grey, | |
), | |
margin: 8, | |
getTitles: (double value) { | |
switch (value.toInt()) { | |
case 0: | |
return 'CQ1'; | |
case 1: | |
return 'CQ2'; | |
case 2: | |
return 'CQ3'; | |
case 3: | |
return 'CQ4'; | |
case 4: | |
return 'CQ5'; | |
default: | |
return ''; | |
} | |
}, | |
), | |
topTitles: SideTitles( | |
showTitles: true, | |
getTextStyles: (value) => const TextStyle( | |
fontSize: 12, | |
color: Colors.grey, | |
), | |
margin: 0, | |
getTitles: (double value) { | |
switch (value.toInt()) { | |
case 0: | |
return '20'; | |
case 1: | |
return '40'; | |
case 2: | |
return '100'; | |
case 3: | |
return '30'; | |
case 4: | |
return '50'; | |
default: | |
return ''; | |
} | |
}, | |
), | |
leftTitles: SideTitles( | |
showTitles: false, | |
), | |
), | |
borderData: FlBorderData( | |
show: false, | |
), | |
barGroups: showingGroups(), | |
barTouchData: BarTouchData( | |
enabled: false, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment