У меня есть эшафот, в нем у меня есть TabBar
, TabBarView
и TextField
.
. TabBar
имеет 3 вкладки (например, вкладки A, B и C),TabBarView
имеет 3 вида, и это TextField
находится на последней вкладке (вкладка C).
Все работает, но всякий раз, когда я фокусируюсь на TextField
, чтобы напечатать что-то, TabBar
меняется с вкладки C на вкладку A. Очень раздражаетЭтого не должно быть.TabBarView
остается без изменений.
Я создал контроллер в initState
.как это:
@override
void initState() {
super.initState();
widget._tabBarController =
new TabController(length: 3, vsync: this);
}
Есть идеи, почему это происходит?
Код:
class AtendimentoOrtoWidget extends StatefulWidget {
TabController _tabBarController;
@override
_AtendimentoOrtoWidgetState createState() => _AtendimentoOrtoWidgetState();
}
class _AtendimentoOrtoWidgetState extends State<AtendimentoOrtoWidget>
with SingleTickerProviderStateMixin {
@override
void initState() {
super.initState();
widget._tabBarController =
new TabController(length: 3, vsync: this);
}
@override
Widget build(BuildContext context) {
return SafeArea(
top: false,
child: new DefaultTabController(
length: 3,
child: new Scaffold(
resizeToAvoidBottomPadding: false,
appBar: new AppBar(
toolbarOpacity: 0.5,
automaticallyImplyLeading: true,
backgroundColor: Colors.white,
elevation: 2.0,
title: new TabBar(
controller: widget._tabBarController,
unselectedLabelColor: Colors.black,
indicatorColor: Colors.black,
labelColor: Colors.black,
// indicatorWeight: 0.0,
isScrollable: true,
labelStyle: new TextStyle(
fontSize: 16.0,
fontFamily: 'Caecilia',
fontWeight: FontWeight.w700),
tabs: <Widget>[
new Tab(
text: "TAB A",
),
new Tab(
text: "TAB B",
),
new Tab(
text: "TAB C",
)
],
),
),
backgroundColor: Colors.white,
body: new TabBarView(
controller: widget._tabBarController,
children: <Widget>[
new Container(),
new Container(),
new TextField()
],
))));
}
}