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 不能在颤振中使用FAB_Flutter - Fatal编程技术网

Flutter 不能在颤振中使用FAB

Flutter 不能在颤振中使用FAB,flutter,Flutter,我得到一个名为parmaterfloatingActionButton的错误,该错误未定义 这是我的main.dart的代码: Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( appBar: AppBar( title: Text('appname'), ),

我得到一个名为parmater
floatingActionButton
的错误,该错误未定义

这是我的
main.dart的代码

Widget build(BuildContext context) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      appBar: AppBar(
        title: Text('appname'),
      ),
      body: PageView(
        physics: NeverScrollableScrollPhysics(),
        onPageChanged: (index) {
          indexcontroller.add(index);
        },
        controller: pageController,
        children: <Widget>[
          Center(
            child: GoogleMap(
              mapType: MapType.hybrid,
              initialCameraPosition: _kGooglePlex,
              onMapCreated: (GoogleMapController controller) {
                _controller.complete(controller);
              },
              myLocationEnabled: true,
            ),
            floatingActionButton: FloatingActionButton.extended(
              onPressed: _currentLocation,
              label: Text('My Home!'),
              icon: Icon(Icons.location_on),
            ),
          ),
          Center(
            child: Text('tab2'),
          ),
          Center(
            child: Text('tab3'),
          ),
          Center(
            child: Text('tab4'),
          ),
        ],
      ),
    ),
  );
}
小部件构建(构建上下文){
返回材料PP(
debugShowCheckedModeBanner:false,
家:脚手架(
appBar:appBar(
标题:文本('appname'),
),
正文:页面视图(
物理学:NeverscrollableScroll物理学(),
onPageChanged:(索引){
添加(索引);
},
控制器:页面控制器,
儿童:[
居中(
孩子:谷歌地图(
mapType:mapType.hybrid,
initialCameraPosition:_kGooglePlex,
onMapCreated:(谷歌地图控制器){
_控制器。完成(控制器);
},
myLocationEnabled:对,
),
floatingActionButton:floatingActionButton.extended(
onPressed:\u当前位置,
标签:Text('My Home!'),
图标:图标(图标位置打开),
),
),
居中(
子项:文本('tab2'),
),
居中(
子项:文本('tab3'),
),
居中(
子项:文本('tab4'),
),
],
),
),
);
}

尝试将
浮动操作按钮
放在
框架的
主体
之外。现在它直接在
主体内部

问题 您正在尝试将
FloatingActionButton
添加为
PageView
的参数。但是FAB的直接父代应该是
Scaffold

解决方案 您应该将晶圆厂添加为
floatingActionButton
中的
Scaffold

return MaterialApp(
  debugShowCheckedModeBanner: false,
  home: Scaffold(
    appBar: AppBar(
      
    ),

    body: PageView(
      
    ),
    
    // HERE ADD FAB
    floatingActionButton: FloatingActionButton.extended(
      onPressed: _currentLocation,
      label: Text('My Home!'),
      icon: Icon(Icons.location_on),
    ),
  ),
);