参数类型 'List<Series<dynamic, dynamic>>' 不能分配给参数类型 'List<Series<dynamic, String>&g
Posted
技术标签:
【中文标题】参数类型 \'List<Series<dynamic, dynamic>>\' 不能分配给参数类型 \'List<Series<dynamic, String>>【英文标题】:The argument type 'List<Series<dynamic, dynamic>>' can't be assigned to the parameter type 'List<Series<dynamic, String>>参数类型 'List<Series<dynamic, dynamic>>' 不能分配给参数类型 'List<Series<dynamic, String>> 【发布时间】:2021-10-18 22:51:59 【问题描述】:我对这个颤动的简单图表代码有疑问。在我尝试运行代码时显示此错误。请任何人都可以帮助我......
不能将参数类型'List
>'分配给参数类型'List >
这是代码示例:
//Bar chart example
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
class SimpleBarChart extends StatelessWidget
final List<charts.Series> seriesList;
final bool animate;
SimpleBarChart(this.seriesList, this.animate = false);
/// Creates a [BarChart] with sample data and no transition.
factory SimpleBarChart.withSampleData()
return new SimpleBarChart(
_createSampleData(),
// Disable animations for image tests.
animate: false,
);
@override
Widget build(BuildContext context)
return new charts.BarChart(
seriesList,
animate: animate,
);
/// Create one series with sample hard coded data.
static List<charts.Series<OrdinalSales, String>> _createSampleData()
final data = [
new OrdinalSales('Today', 55),
new OrdinalSales('Yesterday', 25),
new OrdinalSales('2 days', 100),
new OrdinalSales('24 June', 75),
new OrdinalSales('23 June', 75),
new OrdinalSales('23 June', 75),
new OrdinalSales('22 June', 75),
];
return [
new charts.Series<OrdinalSales, String>(
id: 'Sales',
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
domainFn: (OrdinalSales sales, _) => sales.year,
measureFn: (OrdinalSales sales, _) => sales.sales,
data: data,
)
];
/// Sample ordinal data type.
class OrdinalSales
final String year;
final int sales;
OrdinalSales(this.year, this.sales);
Launching lib\main.dart on Chrome in debug mode... Waiting for connection from debug service on Chrome... lib/widgets/barChart.dart:24:7: Error: The argument type 'List<Series<dynamic, dynamic>>' can't be assigned to the parameter type 'List<Series<dynamic, String>>'.
- 'List' is from 'dart:core'.
- 'Series' is from 'package:charts_common/src/data/series.dart' ('/C:/flutter/.pub-cache/hosted/pub.dartlang.org/charts_common-0.11.0/lib/src/data/series.dart').
seriesList,
^ Failed to compile application.
【问题讨论】:
【参考方案1】:从以下位置更改您的 seriesList
变量类型:
final List<charts.Series> seriesList;
收件人:
final List<charts.Series<dynamic, String>> seriesList;
这会很好用。
【讨论】:
以上是关于参数类型 'List<Series<dynamic, dynamic>>' 不能分配给参数类型 'List<Series<dynamic, String>&g的主要内容,如果未能解决你的问题,请参考以下文章
无法连接“<class 'numpy.ndarray'>”类型的对象;只有 Series 和 DataFrame obj 是有效的
使用泛型类型"System.Collections.Generic.List<T>"需要"1"类型参数
Flutter 参数类型 'List<dynamic>' 不能分配给参数类型 'List<Widget>'
Powershell 参数列表传递,如 -a <args list> -d <args list>