小编use*_*978的帖子

Flutter Pageview 在方向变化时丢失索引

最近也有类似的问题,不过已经在 GitHub 上解决并关闭了。由于我是新手,我可能会在这里遗漏一些东西。方向更改后,页面索引恢复为零,但选定的 BottomNavigationBarItem 保持原样。这里正在显示页面“ONE”,但在旋转设备之前选择了选项卡“FOUR” 截屏


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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pageview Orientation Bug',
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _page = 0;
  PageController _controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: OrientationBuilder(
        builder: (context,orientation) {
          return orientation == Orientation.portrait …
Run Code Online (Sandbox Code Playgroud)

device-orientation flutter flutter-layout flutter-pageview

2
推荐指数
1
解决办法
1439
查看次数