我收到未定义名为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'),
),
],
),
),
);
}
答案 0 :(得分:1)
您正在尝试将FloatingActionButton
添加为PageView
的参数。但是FAB的直接父级应为Scaffold
。
您应该在floatingActionButton
中将FAB添加为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),
),
),
);
答案 1 :(得分:0)
尝试将FloatingActionButton
放在body
的{{1}}之外。现在,它直接位于Scaffold
内部。