How to modify parent FloatingActionButton on flutter?

612

Is this what you are asking? If not please share some code which casing the problem

UPDATE

 Scaffold(
      appBar: AppBar(
        title: Text('Test'),
      ),
      body: _screenList[_screenIndex],
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _screenIndex,
          onTap: (index) {
            print(index);
            setState(() {
              _screenIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.inbox),
              title: Text('Screen1'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.search),
              title: Text('Screen2'),
            ),
          ]),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: FloatingActionButton(
        child: Icon(
          Icons.android,
        ),
        onPressed: () {
          _screenIndex == 0
              ? print('hello from screen1')
              : print('hello from screen2');
        },
      ),
    );

OUTPUT

enter image description here

Share:
612
Aylton Almeida
Author by

Aylton Almeida

Software Engineering student

Updated on December 15, 2022

Comments

  • Aylton Almeida
    Aylton Almeida over 1 year

    I am making an app in which I have to pages, routed by a BottomNavigationBar, and each page has its own nested routes. The app contains a main FloatingActionButton centered and docked into the BottomNavigationBar. The problem is that I wanted to control what the FAB does from inside each nested route. The problem is that if I create a FAB inside each nested route the button will not be docked into the BottomNavigationBar. Bellow are some pictures. Anyone can help? Thanks in advance.

    What I have :

    enter image description here

    What I wanted :

    enter image description here

    • delmin
      delmin about 4 years
      Share a code with the button
  • Haroon Ashraf Awan
    Haroon Ashraf Awan about 4 years
    No.He has this bottomNavigation bar as a root and it its built only once and.The nested pages are beneath it and it acts as root most widget.When pages are changed fab remains the same and isnt rebuilt only pages are changed.He wants to handle the onTap functionality of FAB according to the page that's currently opened.
  • LonelyWolf
    LonelyWolf about 4 years
    @HaroonAshrafAwan Ok then hopefully we will get some code where we can reproduce this behaviour. First thing I don't understand why he recreate the FAB on each page. He can easily control functionality from each page on main page. Without a code I can't really help
  • Aylton Almeida
    Aylton Almeida about 4 years
    @LonelyWolf that's exactly what I wanted to know how to do. How could I control the FAB inside the main page from it's child. Since there are some pages where the FAB should be hidden
  • LonelyWolf
    LonelyWolf about 4 years
    @AyltonAlmeida OK check updated code how to control functionality of your fab button in other subpages.