Флаттер: пребывание внутри оболочки при навигации с помощью панели приложений

#android #flutter #dart

#Android #трепетание #дротик

Вопрос:

У меня есть нижняя панель навигации, которая позволяет мне перемещаться между страницами, сохраняя при этом нижнюю панель навигации на месте (используя постоянный пакет нижней панели навигации).

Я также хочу иметь дополнительную навигационную кнопку, которая отправляла бы меня на другую страницу, не указанную на нижней панели навигации, но все разные способы, которые я пробовал, подталкивали меня к другой странице, которая не находится внутри оболочки.

Как я могу перейти на другую страницу из панели приложений (страница не указана на нижней панели навигации), не теряя панель навигации?

Привязка кода оболочки

 class Wrapper extends StatefulWidget {
  final BuildContext menuScreenContext;
  Wrapper({Key key, this.menuScreenContext}) : super(key: key);

  @override
  _WrapperState createState() => _WrapperState();
}

class _WrapperState extends State<Wrapper> {
  final AuthService _auth = AuthService();
  PersistentTabController _controller;
  bool _hideNavBar;
  @override
  void initState() {
    super.initState();
    _controller = PersistentTabController(initialIndex: 0);
    _hideNavBar = false;
  }


  List<Widget> _buildScreens() {
    return [

      HomePage(
        hideStatus:_hideNavBar,
      ),
      Page1(),
      Page2(),
      Page3(),
      Page4(
        hideStatus:_hideNavBar,
      ),

    ];
  }

  List<PersistentBottomNavBarItem> _navBarsItems() {
    return [
      PersistentBottomNavBarItem(
        icon: Icon(Icons.home),
        title: "Home",
        activeColor: Colors.blue,
        inactiveColor: Colors.grey,

      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.search),
        title: ("Search"),
        activeColor: Colors.teal,
        inactiveColor: Colors.grey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.add),
        title: ("Add"),
        activeColor: Colors.deepOrange,
        inactiveColor: Colors.grey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.settings),
        title: ("Settings"),
        activeColor: Colors.indigo,
        inactiveColor: Colors.grey,
      ),
      PersistentBottomNavBarItem(
        icon: Icon(Icons.settings),
        title: ("Settings"),
        activeColor: Colors.indigo,
        inactiveColor: Colors.grey,
      ),
    ];
  }


  @override
  Widget build(BuildContext context)
  {
    final user = Provider.of<NUser>(context);
    if(user==null){
      return Authenticate();}
    else {
      return Scaffold
        (
        drawer: Drawer(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>
              [

                TextButton
                  (child:Text('hey'), onPressed: ()
                    {
                      pushNewScreenWithRouteSettings(
                          context,
                          settings: RouteSettings(name:'/home'),
                          screen: HomePage());
                    }

                  ),
                ElevatedButton.icon(
                  onPressed: () async {await _auth.signOut();},
                  icon: Icon(Icons.person),
                  label: Text('Logout'),
                ),
              ],
            ),
          ),
        ),
        appBar: AppBar(

          actions: [
            IconButton(iconSize: 150,icon: Image.asset("assets/BUTTON.png", color: Colors.black,height: 1000,width: 1000,), onPressed: ()
            {
              Navigator.push(context, MaterialPageRoute(builder: (context) => Profile()));
            }),
            ButtonTheme(
              minWidth: 100.0,
              height: 100.0,
              child: TextButton(
                onPressed: () {},
                child: Text("     4444    "),
              ),
            ),
          ],
        ),

        body: PersistentTabView.custom
          (
          context,
          controller: _controller,
          screens: _buildScreens(),
          confineInSafeArea: true,
          itemCount: 5,
          handleAndroidBackButtonPress: true,
          resizeToAvoidBottomInset: false,
          stateManagement: true,
          hideNavigationBar: _hideNavBar,
          screenTransitionAnimation: ScreenTransitionAnimation(
            animateTabTransition: true,
            curve: Curves.ease,
            duration: Duration(milliseconds: 200),
          ),
          customWidget: CustomNavBarWidget
            (
            items: _navBarsItems(),
            onItemSelected: (index) {
              setState(() {
                _controller.index = index; // THIS IS CRITICAL!! Don't miss it!
              });
            },
            selectedIndex: _controller.index,
          ),
        ),

      );
    }
  }
}

class Profile extends StatefulWidget {
  Profile({Key key}): super(key: key);

  @override
  _ProfileState createState() => _ProfileState();
}

class _ProfileState extends State<Profile> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:Text('sample'),
      ),
    );
  }
}
 

Я попытался создать класс для страницы в оболочке, но безуспешно. Другие страницы представляют собой отдельные файлы. Я пытаюсь перемещаться с помощью кнопки на панели приложений

Комментарии:

1. пожалуйста, приложите код, который вы уже пробовали

2. РЕДАКТИРОВАТЬ : добавлен код