Created
March 16, 2021 20:46
-
-
Save imaNNeo/2ed984a72781641cceab55a8a94cb7e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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:example/radar_chart/radar_chart_page.dart'; | |
import 'package:example/scatter_chart/scatter_chart_page.dart'; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:fl_chart/fl_chart.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'FlChart Demo', | |
showPerformanceOverlay: false, | |
theme: ThemeData( | |
primaryColor: const Color(0xff262545), | |
primaryColorDark: const Color(0xff201f39), | |
brightness: Brightness.dark, | |
), | |
home: Scaffold( | |
backgroundColor: Colors.white, | |
body: Center( | |
child: SizedBox( | |
width: 300, | |
height: 150, | |
child: MyCustomizedChart(), | |
), | |
), | |
), | |
); | |
} | |
} | |
class MyCustomizedChart extends StatefulWidget { | |
@override | |
_MyCustomizedChartState createState() => _MyCustomizedChartState(); | |
} | |
class _MyCustomizedChartState extends State<MyCustomizedChart> { | |
final Color lineDefaultColor = Colors.green.withOpacity(0.4); | |
final Color lineTouchedColor = Colors.green; | |
Color currentColor; | |
@override | |
void initState() { | |
super.initState(); | |
currentColor = lineDefaultColor; | |
} | |
@override | |
Widget build(BuildContext context) { | |
return LineChart( | |
LineChartData( | |
lineBarsData: [ | |
LineChartBarData( | |
colors: [currentColor], | |
spots: [ | |
FlSpot(0, 0), | |
FlSpot(1, 1), | |
FlSpot(2, 1.5), | |
FlSpot(3, 1), | |
FlSpot(4, 2), | |
FlSpot(5, 1), | |
], | |
) | |
], | |
lineTouchData: LineTouchData(touchCallback: (LineTouchResponse response) { | |
setState(() { | |
if (response.touchInput is FlPanStart || | |
response.touchInput is FlPanMoveUpdate || | |
response.touchInput is FlLongPressStart || | |
response.touchInput is FlLongPressMoveUpdate) { | |
currentColor = lineTouchedColor; | |
} else { | |
currentColor = lineDefaultColor; | |
} | |
}); | |
})), | |
); | |
} | |
} |
Author
imaNNeo
commented
Mar 16, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment