所以一开始我有一个简单的bottomNavBar来改变页面。我想做的是在中间添加一个FAB栏。
- 原始底部导航栏 *
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: 0,
backgroundColor: Color(0xFF0066EE),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white,
items: const [
BottomNavigationBarItem(label: 'Home', icon: Icon(Icons.home)),
BottomNavigationBarItem(label: 'Diary', icon: Icon(Icons.book)),
BottomNavigationBarItem(
label: 'Plans', icon: Icon(Icons.spoke_rounded)),
BottomNavigationBarItem(label: 'More', icon: Icon(Icons.more)),
],
onTap: (index) {
if (index == 1) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
final foodItemsModel =
Provider.of<FoodItemsModel>(context, listen: false);
return MealPlanPage(mealList: foodItemsModel.foodItems);
},
),
);
} else if (index == 2) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return PlanPage();
},
),
);
}
},
),
- 所需的底部导航栏 *
我尝试包含FAB栏,包括将现有的bottomNavBar Package 在bottomAppBar中,然后添加floatingActionButton,原因是我假设这是由BottomAppBar的高度大于bottomNavBar引起的。
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: 0,
backgroundColor: Color(0xFF0066EE),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white,
items: const [
BottomNavigationBarItem(label: 'Home', icon: Icon(Icons.home)),
BottomNavigationBarItem(label: 'Diary', icon: Icon(Icons.book)),
BottomNavigationBarItem(
label: 'Plans', icon: Icon(Icons.spoke_rounded)),
BottomNavigationBarItem(label: 'More', icon: Icon(Icons.more)),
],
onTap: (index) {
if (index == 1) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
final foodItemsModel =
Provider.of<FoodItemsModel>(context, listen: false);
return MealPlanPage(mealList: foodItemsModel.foodItems);
},
),
);
} else if (index == 2) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return PlanPage();
},
),
);
}
},
),
),
我尝试设置bottomAppBar的高度以匹配bottomNavBar的高度,但结果仍然是一团糟,FAB按钮放置不当。
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
color: Color(0xFF0066EE),
elevation: 0,
shape: CircularNotchedRectangle(),
child: SizedBox(
height: kBottomNavigationBarHeight,
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: 0,
backgroundColor: Color(0xFF0066EE),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white,
items: const [
BottomNavigationBarItem(label: 'Home', icon: Icon(Icons.home)),
BottomNavigationBarItem(label: 'Diary', icon: Icon(Icons.book)),
BottomNavigationBarItem(
label: 'Plans', icon: Icon(Icons.spoke_rounded)),
BottomNavigationBarItem(label: 'More', icon: Icon(Icons.more)),
],
onTap: (index) {
if (index == 1) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
final foodItemsModel =
Provider.of<FoodItemsModel>(context, listen: false);
return MealPlanPage(mealList: foodItemsModel.foodItems);
},
),
);
} else if (index == 2) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return PlanPage();
},
),
);
}
},
),
),
),
2条答案
按热度按时间agxfikkp1#
在android中没有问题。我认为你使用的是ios。当你有
SafeArea
时,如果你把bottom
属性设置为false
,就会发生这种情况。或者,如果您没有
SafeArea
,请尝试将BottomAppBar的notchMargin属性设置为0。例如:pxiryf3j2#
检查您的主
MaterialApp
或Parent Widget
,如果有任何margin
或Padding
集,因为否则您的代码应该工作.工作代码:
输出: