mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
web/chart: fix sample (#909)
This commit is contained in:
@@ -36,11 +36,11 @@ class SliderLine extends StatefulWidget {
|
||||
final List<charts.Series> seriesList;
|
||||
final bool animate;
|
||||
|
||||
SliderLine(this.seriesList, {this.animate});
|
||||
const SliderLine(this.seriesList, {this.animate, Key key}) : super(key: key);
|
||||
|
||||
/// Creates a [LineChart] with sample data and no transition.
|
||||
factory SliderLine.withSampleData() {
|
||||
return new SliderLine(
|
||||
return SliderLine(
|
||||
_createSampleData(),
|
||||
// Disable animations for image tests.
|
||||
animate: false,
|
||||
@@ -52,22 +52,22 @@ class SliderLine extends StatefulWidget {
|
||||
// It is used for creating random series data to demonstrate animation in
|
||||
// the example app only.
|
||||
factory SliderLine.withRandomData() {
|
||||
return new SliderLine(_createRandomData());
|
||||
return SliderLine(_createRandomData());
|
||||
}
|
||||
|
||||
/// Create random data.
|
||||
static List<charts.Series<LinearSales, num>> _createRandomData() {
|
||||
final random = new Random();
|
||||
final random = Random();
|
||||
|
||||
final data = [
|
||||
new LinearSales(0, random.nextInt(100)),
|
||||
new LinearSales(1, random.nextInt(100)),
|
||||
new LinearSales(2, random.nextInt(100)),
|
||||
new LinearSales(3, random.nextInt(100)),
|
||||
LinearSales(0, random.nextInt(100)),
|
||||
LinearSales(1, random.nextInt(100)),
|
||||
LinearSales(2, random.nextInt(100)),
|
||||
LinearSales(3, random.nextInt(100)),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -80,19 +80,19 @@ class SliderLine extends StatefulWidget {
|
||||
// We need a Stateful widget to build the selection details with the current
|
||||
// selection as the state.
|
||||
@override
|
||||
State<StatefulWidget> createState() => new _SliderCallbackState();
|
||||
State<StatefulWidget> createState() => _SliderCallbackState();
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
static List<charts.Series<LinearSales, int>> _createSampleData() {
|
||||
final data = [
|
||||
new LinearSales(0, 5),
|
||||
new LinearSales(1, 25),
|
||||
new LinearSales(2, 100),
|
||||
new LinearSales(3, 75),
|
||||
LinearSales(0, 5),
|
||||
LinearSales(1, 25),
|
||||
LinearSales(2, 100),
|
||||
LinearSales(3, 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<LinearSales, int>(
|
||||
charts.Series<LinearSales, int>(
|
||||
id: 'Sales',
|
||||
domainFn: (LinearSales sales, _) => sales.year,
|
||||
measureFn: (LinearSales sales, _) => sales.sales,
|
||||
@@ -126,9 +126,9 @@ class _SliderCallbackState extends State<SliderLine> {
|
||||
Widget build(BuildContext context) {
|
||||
// The children consist of a Chart and Text widgets below to hold the info.
|
||||
final children = <Widget>[
|
||||
new SizedBox(
|
||||
SizedBox(
|
||||
height: 150.0,
|
||||
child: new charts.LineChart(
|
||||
child: charts.LineChart(
|
||||
widget.seriesList,
|
||||
animate: widget.animate,
|
||||
// Configures a [Slider] behavior.
|
||||
@@ -159,7 +159,7 @@ class _SliderCallbackState extends State<SliderLine> {
|
||||
// [style] takes in a [SliderStyle] configuration object, and
|
||||
// configures the color and sizing of the slider line and handle.
|
||||
behaviors: [
|
||||
new charts.Slider(
|
||||
charts.Slider(
|
||||
initialDomainValue: 1.0, onChangeCallback: _onSliderChange),
|
||||
],
|
||||
)),
|
||||
@@ -167,23 +167,23 @@ class _SliderCallbackState extends State<SliderLine> {
|
||||
|
||||
// If there is a slider change event, then include the details.
|
||||
if (_sliderDomainValue != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text('Slider domain value: $_sliderDomainValue')));
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text('Slider domain value: $_sliderDomainValue')));
|
||||
}
|
||||
if (_sliderPosition != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text(
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text(
|
||||
'Slider position: ${_sliderPosition.x}, ${_sliderPosition.y}')));
|
||||
}
|
||||
if (_sliderDragState != null) {
|
||||
children.add(new Padding(
|
||||
padding: new EdgeInsets.only(top: 5.0),
|
||||
child: new Text('Slider drag state: $_sliderDragState')));
|
||||
children.add(Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Text('Slider drag state: $_sliderDragState')));
|
||||
}
|
||||
|
||||
return new Column(children: children);
|
||||
return Column(children: children);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user