- 我的问题总结
目标
我的目标是展示一个长页面的轮播。所以我使用带有滚动视图的 PageView。PageView 水平滚动。滚动视图(子视图)垂直滚动。
预期成绩
水平滑动和垂直滚动平滑。
实际结果
如果我水平滑动到下一页,我无法立即垂直滚动它。我需要等待 1 秒钟。似乎用户必须等待动画完成才能与新的当前页面进行交互。
到目前为止我尝试了什么:
- 我尝试了手势识别器来传递拖动事件,但我没有让它工作。
- 我尝试了不同的小部件来替换 PageView 但效果相同。
- 我用 wantKeepAlive = true 尝试了 AutomaticKeepAliveClientMixin
- 我试过 PageView.physics = AlwaysScrollableScrollPhysics()
这是重现问题所需的最少代码
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: carousel(),
);
}
Widget carousel() {
return PageView(
children: <Widget>[
page(Colors.pinkAccent),
page(Colors.blueAccent),
page(Colors.orangeAccent)
],
);
}
Widget page(Color color) {
return Container(
decoration: BoxDecoration(
color: color,
),
child: SingleChildScrollView(
child: Column(
children: pageContent()),
));
}
List<Widget> pageContent() {
return <Widget>[
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
Row(children: <Widget>[Text("Hop", textScaleFactor: 5,)]),
];
}
}