【发布时间】:2020-04-04 08:51:59
【问题描述】:
在我的应用程序中,我有一个 PageView,每个页面都包含一本书的一页。 自然,所有的页面都比视口大,所以我在每个页面内都使用了 SingleChildScrollView,这样我就可以滚动页面的内容。 问题是当我到达页面底部时,我无法滚动到 PageView 的下一页(它试图继续滚动页面本身而不是页面视图)。 有没有办法让我的应用在到达页面垂直边框时滚动页面? (顶部和底部边框。)
这是我的代码
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:penguinovel/core/source/chapter.dart';
class ChapterPage extends StatelessWidget {
final List<Chapter> chapters;
final int initialIndex;
ChapterPage(this.chapters, this.initialIndex);
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(title: Text(this.chapters[this.initialIndex].name, style: TextStyle(color: Colors.white),), backgroundColor: Colors.black,),
body: PageView.builder(
controller: PageController(initialPage: this.initialIndex),
scrollDirection: Axis.vertical,
itemCount: this.chapters.length,
itemBuilder: (BuildContext context, int index) => buildChapter(this.chapters[index]),
)
);
}
Widget buildChapter(Chapter chapter) {
return FutureBuilder<String>(future: chapter.getContent(), builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if(snapshot.hasData){
return SingleChildScrollView(child: Html(data: snapshot.data));
} else if (snapshot.hasError) {
return Center(child: Text(snapshot.error.toString()));
} else {
return Center(child: CircularProgressIndicator());
}
});
}
}
提前致谢:)
【问题讨论】:
-
为什么不用
ListView而不是PageView? -
这可能是我缺乏理解,但我不想提前加载其他页面,只有在滚动到它们时才加载它们。编辑:经过测试,我可以确认使用 ListView.build 生成所有页面,我不希望这样