【发布时间】:2020-10-13 02:24:37
【问题描述】:
我有这个带有中心停靠浮动图标的底部导航栏,底部栏存在,我可以浏览底部栏中的标签元素,但我需要显示固定到每个屏幕的底部栏,无论我打开什么屏幕我都需要显示底部导航栏
1.如果我转到主屏幕并且我要单击主页中的一个项目并重定向下一页,我如何查看子页面中的底部栏,然后底部导航栏应该显示重定向的页面
底部导航
class BottomViewScreenState extends State<BottomViewScreen> {
TabController tabController;
static int _selectedTab = 0;
final List<Widget> _children = [
new HomeScreen(),
new OfferScreen(),
new HelpScreen(),
new ProfileScreen(),
new CartViewScreen(),
];
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
theme: ThemeData(
primaryColor: Color(0xffFF5555),
),
home: Scaffold(
body: _children[_selectedTab], // new
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
onPressed: () {
// new CartViewScreen();
//onTabTapped(4);
// CartViewScreen();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CartViewScreen(),
),
);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Icons.add_shopping_cart),
Text(
"CART",
style: TextStyle(fontSize: 8.0),
),
],
),
backgroundColor: Colors.indigo[900],
foregroundColor: Colors.white,
elevation: 2.0,
),
bottomNavigationBar: BottomAppBar(
clipBehavior: Clip.antiAlias,
notchMargin: 10.0,
shape: CircularNotchedRectangle(),
child: SizedBox(
height: 80,
child: Theme(
data: Theme.of(context).copyWith(
// sets the background color of the `BottomNavigationBar`
canvasColor: Colors.white,
// sets the active color of the `BottomNavigationBar` if `Brightness` is light
primaryColor: Colors.amberAccent,
textTheme: Theme.of(context)
.textTheme
.copyWith(caption: new TextStyle(color: Colors.grey))),
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: onTabTapped,
currentIndex: _selectedTab,
fixedColor: Colors.amberAccent,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(
'HOME',
style: TextStyle(fontSize: 10.0),
),
activeIcon: Column(
children: <Widget>[
Icon(Icons.local_offer),
],
),
),
BottomNavigationBarItem(
icon: SvgPicture.asset(
"assets/images/ic_bottom_offer.svg",
height: 25,
color: Colors.grey,
),
title: Text('OFFERS', style: TextStyle(fontSize: 10.0))),
BottomNavigationBarItem(
icon: Icon(Icons.info_outline),
title: Text('HELP', style: TextStyle(fontSize: 10.0))),
BottomNavigationBarItem(
icon: Icon(Icons.people),
title: Text('PROFILE', style: TextStyle(fontSize: 10.0))),
],
),
),
),
),
),
);
}
void onTabTapped(int index) {
setState(() {
_selectedTab = index;
});
}
}
主要
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
title: "App",
home: new SplashScreen(),
routes: {
"/homescreen": (_) => new BottomViewScreen(),
"/login":(_) => new LoginScreen(),
},
);
}
}
【问题讨论】:
-
您可以使用页面视图来包含您想要导航的小部件
-
你能用一些代码解释一下吗? @黑暗
标签: flutter dart flutter-layout