0

My app has a permanent view (home) witch has an appbar + drawer + bottom navigation bar when I click on bottom navigation bar items it replaces the body content of home with one of the pages (page1, page2, page3, page4)

It's all working well but now I have a button in page2 that loads subPage and as result I only have the content of subPage without the permanent view of home so no appbar or drawer or bottom navigation bar

Haw can I do to make the button target the body part of my permanent view

Here is a simplified code: Home.dart is a stateful widget...

int _currentIndex = 0;

  List<Widget> _pages = [
    Page1(),
    Page2(),
    Page3(),
    Page4(),
  ];


  Route _onRoute(RouteSettings settings) {
    final str = settings.name.split("/")[1];
    final index = int.parse(str, onError: (s) => 0);

    return new MaterialPageRoute(
        builder: (BuildContext context) => new Page1(index: index));
  }

  @override
  Widget build(BuildContext context) {

Column(
      children: <Widget>[
        new Expanded(
          child: new MaterialApp(
            onGenerateRoute: _onRoute,
            home: new Scaffold(
              body: _pages[_currentIndex],
              appBar: new AppBar(

              drawer: Drawer()
                bottomNavigationBar: BottomNavigationBar(
                type: BottomNavigationBarType.fixed,
                currentIndex: _currentIndex,
                onTap: (int index) {
                  setState(() {
                    _currentIndex = index;
                  });
                },

                items: [...]

page3.dart: a stateless widget that return a container of listview

.
.
.
      onTap: () {
        Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => Subpage()));
      },

what should I do or put in the ontap to target the body of home

mehdouch
  • 423
  • 1
  • 8
  • 20
  • 1
    Navigator.push will push new page into the view, so you'll need to recreate appbar, drawer and all in the new page. To achieve your desired behavior, I can think of other approaches. Easiest would be to replace page2 from _pages using `_pages.removeAt(1)` and then `_pages.insertAt(1,newPage())`, instead of pushing route. Another approach would be to create `Home()` widget that takes body as parameter and pushing it into router with new `Subpage()` as parameter. Hope this is helpful. – Kshitij Dhakal Dec 27 '19 at 16:01
  • 1
    Thank you for your response, it worked perfectly – mehdouch Dec 28 '19 at 00:06
  • sorry I couldn't help you more. I saw you asking other questions, I was busy. – Kshitij Dhakal Dec 28 '19 at 00:41
  • It's ok I figured it out – mehdouch Jan 05 '20 at 20:51

0 Answers0