Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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 颤振错误-找不到材质祖先的特定小部件为:_Flutter_Dart_Flutter Layout_Iconbutton - Fatal编程技术网

Flutter 颤振错误-找不到材质祖先的特定小部件为:

Flutter 颤振错误-找不到材质祖先的特定小部件为:,flutter,dart,flutter-layout,iconbutton,Flutter,Dart,Flutter Layout,Iconbutton,我正在使用Align小部件将图标按钮放置在屏幕的底部中央 但是,我遇到以下错误,无法解决: 找不到材质祖先的特定小部件是: 图标按钮 我的代码: return Stack( children: <Widget>[ Container( child: GoogleMap( initialCameraPosition: CameraPosition(target: LatLng(1,1), zoom: 15), on

我正在使用
Align
小部件将图标按钮放置在屏幕的底部中央

但是,我遇到以下错误,无法解决:

找不到材质祖先的特定小部件是:
图标按钮

我的代码:

return Stack(
  children: <Widget>[
    Container(
      child: GoogleMap(
        initialCameraPosition:
        CameraPosition(target: LatLng(1,1), zoom: 15),
        onMapCreated: (map) {
          mapReady;
        },),
    ),
    Align(
      alignment:Alignment.bottomCenter,
      child: IconButton(
          icon: Icon(Icons.next_week), onPressed: (){}),
    )
  ],
返回堆栈(
儿童:[
容器(
孩子:谷歌地图(
初始摄像机位置:
摄影机位置(目标:LatLng(1,1),缩放:15),
onMapCreated:(映射){
mapredy;
},),
),
对齐(
对齐:对齐.bottomCenter,
孩子:我的钮扣(
图标:图标(图标。下周),按下:({}),
)
],
如果我用一个文本小部件来替换IconButton小部件,它会工作得很好


您能解释一下为什么它不起作用,为什么IconButton需要一个材质祖先吗?

因为根据IconButton()的文档

图标按钮是打印在Material小部件上的一张图片,它会做出反应 通过填充颜色(墨水)来触摸

[……]

要求其祖先之一是材质小部件

IconButton使用最有可能的主题数据以及MaterialApp通常提供的其他内容

有什么原因不使用MaterialApp作为祖先吗?

如果使用Scaffold包装堆栈(或通常的父堆栈),您将不会得到此错误

在这种情况下,如果使用Material小部件包装IconButton,我相信它会解决问题:

  Align(
    alignment: Alignment.bottomCenter,
    child: Material(
        child: IconButton(icon: Icon(Icons.next_week), onPressed: () {})),
  )