Skip to content

PageView resize from zero-size viewport will lose state #88956

@xu-baolin

Description

@xu-baolin

Simple Code

import 'package:flutter/material.dart';

void main() {
  runApp(A());
}

class A extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AState();
  }

}

class _AState extends State<A> {
  double size = 100.0;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: () {
              setState(() {
                if (size == 100) {
                  size = 0;
                } else {
                  size = 100;
                }
              });
            },
          ),
          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: SizedBox(
            width: size,
            height: size,
            child: TabBarView(
              children: [
                Icon(Icons.directions_car),
                Icon(Icons.directions_transit),
                Icon(Icons.directions_bike),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Repro Step

1, switch tab to second or third tab
2, click the floatingActionButton to change the size to zero
3, click it again and TabBarView lose state (switch to the first page)

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: state restorationRestorationManager and related APIsf: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.found in release: 2.2Found to occur in 2.2found in release: 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions