1

I got error named parmater floatingActionButton is not defined.

This my code of 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'),
          ),
        ],
      ),
    ),
  );
}

2 Answers 2

3

Problem

You are trying to add FloatingActionButton as parameter of PageView. But direct parent of the FAB should be Scaffold.

Solution

You should add your FAB as floatingActionButton in 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),
    ),
  ),
);
0
0

Try putting your FloatingActionButton outside of the body in the Scaffold. Right now it's directly inside the body.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.