【发布时间】:2022-01-18 08:34:39
【问题描述】:
我正在尝试在 Flutter 中使用 BottomNavigationBar。它运作良好。没有错误。但是当我按下底部导航栏上的按钮时,没有任何反应。还要注意控制台底部导航栏没有评论。
import 'package:copy_ems/screen/more_screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../my_profile.dart';
class BottomNavBar extends StatefulWidget {
const BottomNavBar({Key? key}) : super(key: key);
@override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
Widget child = Container();
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
switch(_currentIndex) {
case 0:
child = const MoreScreen();
break;
case 1:
child = const MoreScreen();
break;
case 2:
child = const MyProfile();
break;
case 3:
child = const MoreScreen();
break;
}
return BottomNavigationBar(
currentIndex: _currentIndex,
backgroundColor: Colors.white,
selectedItemColor: Colors.green,
unselectedItemColor: Colors.black87.withOpacity(.60),
selectedFontSize: 14,
unselectedFontSize: 14,
onTap: (value) {
setState(() => _currentIndex = value,
);
},
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.archive_rounded),
label: 'My Feed',
),
BottomNavigationBarItem(
icon: Icon(Icons.card_travel),
label: 'Leave',
),
BottomNavigationBarItem(
icon: Icon(Icons.add_task),
label: 'Tasks',
),
BottomNavigationBarItem(
icon: Icon(Icons.more_horiz),
label: 'More',
),
],
);
}
}
这段代码有什么问题。谁能帮帮我?
【问题讨论】:
-
从哪里调用底部导航栏?你得到什么错误?
-
你的身体在哪里?
-
使用 Scaffold 类属性我称之为,比如 bottomNavigationBar: const BottomNavBar(),
标签: flutter dart navbar navigationbar flutter-bottomnavigation