Skip to content

Instantly share code, notes, and snippets.

@DrMabuse23
Last active July 3, 2017 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrMabuse23/b955d16c191b4d91ac507523c99677d4 to your computer and use it in GitHub Desktop.
Save DrMabuse23/b955d16c191b4d91ac507523c99677d4 to your computer and use it in GitHub Desktop.
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: new ChartPage()));
}
class ChartPage extends StatefulWidget {
@override
ChartPageState createState() => new ChartPageState();
}
class ChartPageState extends State<ChartPage> {
double dataSet = 0.1;
void changeData(double value) {
setState(() {
dataSet = value;
});
}
Widget buildRange() {
return (new Center(
child: new Container(
height: 220.0,
child: new Row(
children: <Widget>[
new Flexible(
child: new Slider(
max: 100.0,
value: dataSet,
divisions: 10,
label: dataSet.toString(),
activeColor: Colors.blueGrey,
min: 0.0,
onChanged: (value) => changeData(value)),
),
new Flexible(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
new CustomPaint(
size: new Size(200.0, 100.0),
painter: new BarChartPainter(dataSet * 2),
),
new Padding(
padding: const EdgeInsets.fromLTRB(15.0, 15.0, 0.0, 0.0),
child: new Text(
dataSet.toString() + ' m',
textAlign: TextAlign.left,
maxLines: 1,
style: new TextStyle(
color: Colors.blueAccent,
decoration: TextDecoration.underline,
decorationColor: Colors.red,
decorationStyle: TextDecorationStyle.wavy,
),
),
)
],
),
)
],
),
)));
}
Widget buildCard() {
return (new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const ListTile(
leading: const Icon(Icons.album),
title: const Text('The Enchanted Nightingale'),
subtitle:
const Text('Music by Julie Gable. Lyrics by Sidney Stein.'),
),
new Flexible(
child: buildRange()
),
new ButtonTheme.bar(
// make buttons use the appropriate styles for cards
child: new ButtonBar(
children: <Widget>[
new FlatButton(
child: const Text('BUY TICKETS'),
onPressed: () {/* ... */},
),
new FlatButton(
child: const Text('LISTEN'),
onPressed: () {/* ... */},
),
],
),
),
],
),
));
}
@override
Widget build(BuildContext context) {
const height = 200.0;
return new Scaffold(
body: buildCard(),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.refresh),
onPressed: () => changeData(100.0),
),
);
}
}
class BarChartPainter extends CustomPainter {
static const barWidth = 10.0;
BarChartPainter(this.barHeight);
final double barHeight;
@override
void paint(Canvas canvas, Size size) {
final paint = new Paint()
..color = Colors.blue[400]
..style = PaintingStyle.fill;
canvas.drawRect(
new Rect.fromLTWH(
(size.width - barWidth) / 2.0,
size.height - barHeight,
barWidth,
barHeight,
),
paint,
);
}
@override
bool shouldRepaint(BarChartPainter old) => barHeight != old.barHeight;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment