简体   繁体   English

在Flutter中,导航到新的Widget,同时保持AppBar和Bottom TabBar

[英]In Flutter, navigate to new Widget while maintaining AppBar and Bottom TabBar

I have a bottom tabbar in my app for navigation. 我的应用中有一个底部标签栏用于导航。 I have a listview in one tab that when clicked will take me to the details view of that item. 我在一个标签中有一个列表视图,点击后会将我带到该项目的详细信息视图。 However, I'd like to maintain the tabbar and appbar (maybe changing the title of the AppBar, etc). 但是,我想维护tabbar和appbar(可能更改AppBar的标题等)。

Here's how I'm accomplishing the navigation: 以下是我完成导航的方法:

Navigator.pushNamed(context, LocationDetails.routeName);

I don't want a transition effect for the AppBar or TabBar (ie I don't want them to slide with the Widget). 我不想要AppBar或TabBar的过渡效果(即我不希望它们与Widget一起滑动)。

Thanks in advance! 提前致谢!

The best way to proceed is to set a bool to be either true or false when a cell in your ListView is pressed. 最好的方法是在按下ListView中的单元格时将bool设置为true或false。 Then under your WidgetBuild write a ternary operator that is bool == true ? 然后在你的WidgetBuild下编写一个bool == true的三元运算符? View 1 : View 2. Examples 视图1:视图2.示例

bool viewState == true;

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text(widget.title),
      backgroundColor: Colors.black87,
    ),
    body: viewState == true ? Container(
        child: new RaisedButton(onpressed:
         (){setState ((){viewState == false}); // Changed code
      ),
    ) : new ListView(
      child: new Center( // Changed code
        child: new ListTile(onpressed: (){ 
        setState((){viewState == true}
        }), 
      ),
    ),
  ); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM