首页 > 解决方案 > 如何在内容维度发生变化时停止滚动视图的滚动模拟?

问题描述

我准备了一个带有水平滚动容器的简单应用程序。当我在滚动位置到达该maxScrollExtend位置后更改可滚动容器的内容尺寸时应用滚动模拟。

我向 Flutter 社区询问了这个问题。他们告诉这是滚动的预期行为。但是,我需要限制滚动模拟。

请任何人告诉我如何限制滚动模拟或如何在没有模拟行为的情况下自定义滚动的解决方法。

复制过程:

  1. 运行以下简单示例。
  2. 在水平方向完全滚动并到达终点。
  3. 点击浮动按钮可在运行时更改大小。

代码片段:

class ScrollingSimulationDemo extends StatefulWidget {
  NestedDemo({Key? key}) : super(key: key);

  @override
  _ScrollingSimulationDemoState createState() => _ScrollingSimulationDemoState();
}

class _ScrollingSimulationDemoState extends State<ScrollingSimulationDemo> {
  double width = 500;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Container(
          color: Colors.lightBlue[100],
          height: 350,
          width: width,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          width = 250.0;
          setState(() {});
        },
      ),
    );
  }
}

要检查此行为的 GitHub 问题,请参阅以下链接, https://github.com/flutter/flutter/issues/86711

标签: flutterdartflutter-layoutflutter-animation

解决方案


推荐阅读