简体   繁体   English

错误:“预期 1 个位置参数,但找到 0 个”flutter dart 错误

[英]Error: “1 positional argument(s) expected, but 0 found” flutter dart error

I'm trying to build an app with some charts, and I started with this example, but it doesn't have the first part that initiates the app, so I tried adding:我正在尝试使用一些图表构建一个应用程序,我从这个示例开始,但它没有启动应用程序的第一部分,所以我尝试添加:

void main() {
  runApp(SimpleTimeSeriesChart());
}

but I get但我明白了

1 positional argument(s) expected, but 0 found.应有 1 个位置参数,但找到了 0 个。 Try adding the missing arguments.尝试添加缺少的 arguments。

in the second line.在第二行。 I don't know what I am doing wrong.我不知道我做错了什么。 Can anyone please help me explain what am I doing wrong and what is the solution?谁能帮我解释我做错了什么以及解决方案是什么? The message is pretty clear, but I don't know which argument I need to add.信息很清楚,但我不知道我需要添加哪个参数。 Also, can anyone point me to some documentation about this particular issue?另外,任何人都可以向我指出有关此特定问题的一些文档吗? Thank you!谢谢!

 import 'package:flutter/material.dart'; import 'package:charts_flutter/flutter.dart' as charts; void main() { runApp(SimpleTimeSeriesChart()); } class SimpleTimeSeriesChart extends StatelessWidget { final List < charts.Series > seriesList; final bool animate; SimpleTimeSeriesChart(this.seriesList, { this.animate }); /// Creates a [TimeSeriesChart] with sample data and no transition. factory SimpleTimeSeriesChart.withSampleData() { return new SimpleTimeSeriesChart( _createSampleData(), // Disable animations for image tests. animate: false, ); } @override Widget build(BuildContext context) { return new charts.TimeSeriesChart( seriesList, animate: animate, // Optionally pass in a [DateTimeFactory] used by the chart. The factory // should create the same type of [DateTime] as the data provided. If none // specified, the default creates local date time. dateTimeFactory: const charts.LocalDateTimeFactory(), ); } /// Create one series with sample hard coded data. static List < charts.Series < TimeSeriesSales, DateTime >> _createSampleData() { final data = [ new TimeSeriesSales(new DateTime(2017, 9, 19), 5), new TimeSeriesSales(new DateTime(2017, 9, 26), 25), new TimeSeriesSales(new DateTime(2017, 10, 3), 100), new TimeSeriesSales(new DateTime(2017, 10, 10), 75), ]; return [ new charts.Series < TimeSeriesSales, DateTime > ( id: 'Sales', colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault, domainFn: (TimeSeriesSales sales, _) => sales.time, measureFn: (TimeSeriesSales sales, _) => sales.sales, data: data, ) ]; } } /// Sample time series data type. class TimeSeriesSales { final DateTime time; final int sales; TimeSeriesSales(this.time, this.sales); }

You need to pass the first argument since it's not optional SimpleTimeSeriesChart(this.seriesList您需要传递第一个参数,因为它不是可选的SimpleTimeSeriesChart(this.seriesList

void main() {
  runApp(SimpleTimeSeriesChart([]));
}

You can read more about Dart parameters here您可以在此处阅读有关 Dart 参数的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM