-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Closed
Copy link
Labels
c: API breakBackwards-incompatible API changesBackwards-incompatible API changesframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
Steps to Reproduce
- Use the code Template found here -> https://flutter.io/docs/cookbook/design/tabs
class TabBarDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
title: Text('Tabs Demo'),
),
body: TabBarView(
children: [
Page1(),
Page2(),
Page3(),
],
),
),
),
);
}
}-
Create 3 stateful widget with
AutomaticKeepAliveClientMixinset to True andsuper.build(context)under build before the return statement. -
Log the
initState()function for each page.
e.g
class Page1 extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _Page1State();
}
class _Page1State extends State<Page1> with AutomaticKeepAliveClientMixin{
@override
void initState() {
super.initState();
print("Page 1 init");
}
@override
Widget build(BuildContext context) {
super.build(context);
return Text("Page 1");
}
@override
bool get wantKeepAlive => true;
}- When moving from tab 1->2->3 or reverse, it only calls initState() on each Page once as intended.
When moving from tab 1 -> 3, it calls initState on tab 1 and 2 again.
When moving from tab 3 -> 1, it initStates again for tab 2 and 3.
AutomaticKeepAliveClientMixin doesn't seem to work when moving across tabs that are not next to each other.
Logs
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v1.0.0, on Mac OS X 10.14 18A391, locale en-SG)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.30.1)
[✓] Connected device (1 available)
• No issues found!
guoChopper, jsnoriegam, Harteg, burkard, gtupak and 15 more
Metadata
Metadata
Assignees
Labels
c: API breakBackwards-incompatible API changesBackwards-incompatible API changesframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.