Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 正在检查回调!=空结果为“0”;类型列表<;配对<;字符串>>;)=&燃气轮机;Null不是类型的子类型(列表<;对<;动态>;)=>;“无效”;_Flutter - Fatal编程技术网

Flutter 正在检查回调!=空结果为“0”;类型列表<;配对<;字符串>>;)=&燃气轮机;Null不是类型的子类型(列表<;对<;动态>;)=>;“无效”;

Flutter 正在检查回调!=空结果为“0”;类型列表<;配对<;字符串>>;)=&燃气轮机;Null不是类型的子类型(列表<;对<;动态>;)=>;“无效”;,flutter,Flutter,我的自定义小部件在使用GestureDetector点击时使用回调 问题是,单击此小部件时,出现以下错误: The following _TypeError was thrown while handling a gesture: type '(List<Pair<String>>) => Null' is not a subtype of type '(List<Pair<dynamic>>) => void' 处理手势时引发了以下

我的自定义小部件在使用GestureDetector点击时使用回调

问题是,单击此小部件时,出现以下错误:

The following _TypeError was thrown while handling a gesture:
type '(List<Pair<String>>) => Null' is not a subtype of type '(List<Pair<dynamic>>) => void'
处理手势时引发了以下类型错误:
类型“(列表)=>Null”不是类型“(列表)=>void”的子类型
到目前为止(据我所知),我已经确保使用正确的类型,但似乎在某些地方没有检测到该类型,但是这很容易混淆,因为在回调上执行null检查时会发生此类型检查错误

  if (widget.onSelected != null) {   < ---- this line specifically is where the error occurs
    var list = entries.where((element) => element.value).map<Pair<T>>((e) => e.key).toList();
    widget.onSelected(list);
  } else {
    print("null");
  }
if(widget.onSelected!=null){<----这一行就是发生错误的地方
var list=entries.where((element)=>element.value.map((e)=>e.key.toList();
widget.onSelected(列表);
}否则{
打印(“空”);
}
代码的其余部分
UIDialogChipSelector多个

类对{
最终T值;
最终字符串标签;
对(this.value,this.label);
}
类UIDialogChipSelector多扩展状态窗口小部件{
最后清单项目;
最终小部件标签;
最终小工具化身;
最终名单初始;
最终选定的价值;
最终颜色为stateoncolor;
最终颜色为onStateOffColor;
UiDialogChipSelectorMulti(
{键,
这个项目,,
这个标签,
这个,阿凡达,
这次选举,
这个,首字母,
this.onStateOnColor=Colors.blue,
this.onStateOffColor=Colors.grey})
:super(key:key);
@凌驾
_UIDialogChipSelector多状态createState()=>
_UIDialogChipSelector多状态();
}
类_UIDialogChipSelector多状态扩展状态{
映射_selected={};
@凌驾
小部件构建(构建上下文){
小部件构建芯片(e对){
...
返回手势检测器(
onTap:(){
var entries=_selected.entries;
设置状态(){
如果(_selected.containsKey(e)){
_选定的[e]=!\u选定的[e];
}否则{
_所选[e]=真;
}
});
打印(“单击${e.label}=${{u selected[e]}”);
|->|如果(widget.onSelected!=null){<----------------------------行被命中,则抛出错误。
var list=entries.where((element)=>element.value.map((e)=>e.key.toList();
widget.onSelected(列表);
}否则{
打印(“空”);
}
},
子:容器(
填充:仅限常量边集(左:4,右:4),
孩子:芯片(
标签:_buildChipLabel(),
化身:_buildChipAvatar(),
形状:StadiumBorder(
边线(
颜色:颜色。黑色。不透明度(0.6),
宽度:2,
)),
背景颜色:颜色。黑色。不透明度(0.3),
),
),
);
}
}
...
}
详细日志输出

I/flutter (20935): Clicked Young Adults = true

======== Exception caught by gesture ===============================================================
The following _TypeError was thrown while handling a gesture:
type '(List<Pair<String>>) => Null' is not a subtype of type '(List<Pair<dynamic>>) => void'

When the exception was thrown, this was the stack: 
#0      _UiDialogChipSelectorMultiState.build._buildChip.<anonymous closure> (package:myawesomeapp/ui/components/ui_dialog_chip_selector_multi.dart:79:22)
#1      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#2      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11)
#3      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
#4      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:230:7)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#8457e
  debugOwner: GestureDetector
  state: possible
  won arena
  finalPosition: Offset(127.6, 387.6)
  finalLocalPosition: Offset(63.6, 21.9)
  button: 1
  sent tap down
I/flatter(20935):点击的年轻人=真
=======手势捕捉到异常===============================================================
处理手势时引发了以下类型错误:
类型“(列表)=>Null”不是类型“(列表)=>void”的子类型
引发异常时,这是堆栈:
#0\u UIDialogChipSelector Multistate.build.\u buildChip。(软件包:myawesomeapp/ui/components/ui\u dialog\u chip\u selector\u multi.dart:79:22)
#1个GestureRecognizer.invokeCallback(包:flatter/src/signatures/recognizer.dart:182:24)
#2 TapGestureRecognitor.handleTapUp(包:颤振/src/手势/tap.dart:607:11)
#3 BaseTapgestureRecognitor.\u检查(包:颤振/src/手势/tap.dart:296:5)
#4 BaseTapgestureRecognitor.handlePrimaryPointer(包:颤振/src/手势/tap.dart:230:7)
...
处理程序:“onTap”
识别器:TapGestureRecognizer#8457e
debugOwner:GestureDetector
国家:可能
赢得竞技场
最终位置:偏移量(127.6387.6)
财务状况:抵销(63.6,21.9)
按钮:1
发送轻敲

您还需要将泛型添加到
状态。
所以

class\u对话框芯片选择器或多状态扩展状态
class\u对话框芯片选择器或多状态扩展状态
错误是因为无法从
小部件
属性推断泛型的类型,因为它只有一个
UiDialogChipSelectorMulti
类型,而
小部件。onSelected
函数需要从
小部件
获取的泛型类型


从这里看到了这个解决方案(目前)我唯一的“解决方案”是删除任何泛型的痕迹。您能显示所选的
\u的类型吗?在我看来,错误特别发生在typecast上:
var list=entries.where((element)=>element.value.map((e)=>e.key.toList()
@VictorEronmosele更新了,我在那里也定义了我的类型,不知怎的跳过了它而没有发布。你是对的,错误来自
如果(widget.onSelected!=null){
。我添加了答案。嗯,真不敢相信我错过了,谢谢!
I/flutter (20935): Clicked Young Adults = true

======== Exception caught by gesture ===============================================================
The following _TypeError was thrown while handling a gesture:
type '(List<Pair<String>>) => Null' is not a subtype of type '(List<Pair<dynamic>>) => void'

When the exception was thrown, this was the stack: 
#0      _UiDialogChipSelectorMultiState.build._buildChip.<anonymous closure> (package:myawesomeapp/ui/components/ui_dialog_chip_selector_multi.dart:79:22)
#1      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#2      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:607:11)
#3      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
#4      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:230:7)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#8457e
  debugOwner: GestureDetector
  state: possible
  won arena
  finalPosition: Offset(127.6, 387.6)
  finalLocalPosition: Offset(63.6, 21.9)
  button: 1
  sent tap down