我在编写基本布局时遇到了一些问题,即,我发现当我选择两个索引之外的卡片时,控制台中会显示一个通知,在给定小部件开头的函数的每个选项卡中,我写道,而不是刷新一个选项卡,即选定的选项卡,而是刷新相邻的选项卡,最后刷新目标选项卡。我将使用下面的代码发布照片,让我知道出了什么问题!:)
class HomePage extends StatefulWidget {
HomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_HomeScreen createState() => _HomeScreen();
}
class _HomeScreen extends State<HomePage> with TickerProviderStateMixin {
TabController controllerInMain;
@override
void initState() {
super.initState();
controllerInMain = TabController(length: 5, vsync: this, initialIndex: 2);
controllerInMain.addListener(() {
_handleTabSelection();
});
}
void _handleTabSelection() {
setState(() {});
}
@override
void dispose() {
controllerInMain.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Managly",
style: TextStyle(color: Colors.black),
),
),
resizeToAvoidBottomPadding: false,
body: SafeArea(
child: TabBarView(
children: <Widget>[
MenuTab(),
OrdersTab(),
StatisticsTab(),
EmployeeTab(),
TableTab(),
],
controller: controllerInMain,
),
),
bottomNavigationBar: TabBar(
controller: controllerInMain,
indicatorColor: Theme.of(context).primaryColor,
tabs: <Tab>[
Tab(
icon: Icon(
Icons.restaurant_menu,
color: Colors.amber,
),
),
Tab(
icon: Icon(
Icons.receipt_long,
color: Colors.amber,
),
),
Tab(
icon: Icon(
Icons.insights,
color: Colors.amber,
),
),
Tab(
icon: Icon(
Icons.group,
color: Colors.amber,
),
),
Tab(
icon: Icon(
Icons.weekend,
color: Colors.amber,
),
),
],
),
);
}
}