【发布时间】:2019-07-06 15:48:28
【问题描述】:
我想创建一个带有底部导航栏的脚手架,以及一个始终显示当前页面标题的应用栏。当我更改底栏选项时,内容会发生明显变化。到目前为止,经典的 NavigationBar 结构一切正常。但是当内容页面的顶部应该有标签时,问题就开始了。我在父母 Scaffold 中创建了我的 appbar。无论如何要向父小部件 appBar 添加标签?
我的 AppBar + BottomNavBar 页面:
class MainPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MainPageState();
}
}
class _MainPageState extends State<MainPage> {
int _currentPageIndex;
List<Widget> _pages = List();
Widget _getCurrentPage() => _pages[_currentPageIndex];
@override
void initState() {
setState(() {
_currentPageIndex = 0;
_pages.add(BlocProvider(bloc: AgendaBloc(), child: AgendaPage()));
_pages.add(SpeakersPage());
_pages.add(MenuPage());
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar( title: 'Agenda'),
body: _getCurrentPage(),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentPageIndex,
onTap: (index){
setState(() {
_currentPageIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.content_paste),
title: Text('Agenda'),
),
BottomNavigationBarItem(
icon: Icon(Icons.group),
title: Text('Speakers'),
),
BottomNavigationBarItem(
icon: Icon(Icons.menu),
title: Text('Menu'),
),
],
),
);
}
}
现在假设我希望我的 AgendaPage 小部件在视图顶部显示选项卡。有没有什么简单的方法可以做到这一点?
【问题讨论】:
-
同时使用标签和底部导航听起来像笨拙的 UI。这样做的目的是什么?
-
我将编辑并添加屏幕截图以获取更多上下文。
-
我正在努力实现这一点,您是否可以放置您的代码解决方案?
-
我现在无法访问此代码。你基本上是在 Alexanders 的回答中做的,“_getCurrentPage()”方法返回你的小部件,它应该被包裹在另一个 Scaffold 中。但是这次这个 Scaffold 可以包含以标准方式制作的选项卡,可以在任何教程中找到。如果您仍然遇到问题,请随时询问。
标签: dart flutter cross-platform flutter-layout