在Flutter中,导航到新的小部件,同时保持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).
这是我完成导航的方式:
Here's how I'm accomplishing the navigation:
Navigator.pushNamed(context,LocationDetails.routeName);
我不希望AppBar或TabBar具有过渡效果(即,我不希望它们随Widget一起滑动).
I don't want a transition effect for the AppBar or TabBar (ie I don't want them to slide with the Widget).
提前谢谢!
推荐答案
最好的方法是在按下ListView中的单元格时将布尔值设置为true或false.然后在您的WidgetBuild下编写一个 bool == true
的三元运算符?视图1:视图2.示例
The best way to proceed is to set a bool to be either true or false when a cell in your ListView is pressed. Then under your WidgetBuild write a ternary operator that is bool == true
? View 1 : View 2. Examples
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}
}),
),
),
);
}
这篇关于在Flutter中,导航到新的小部件,同时保持AppBar和Bottom TabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!