Skip to content

Commit

Permalink
fix: state bug
Browse files Browse the repository at this point in the history
  • Loading branch information
suconghou committed Apr 20, 2022
1 parent 4e0ac8f commit ee73ec1
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions lib/ui/pages/CListVideos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _VideosListState extends State<VideosList> {
List videoList = [];
bool loading = false;
String nextPageToken = "";

late Future loadData;
bool nomore = false;

Widget a = Container(
Expand All @@ -60,7 +60,7 @@ class _VideosListState extends State<VideosList> {
@override
void initState() {
super.initState();
_pullToRefresh();
loadData = _pullToRefresh();
_controller.addListener(_scrollListener);
}

Expand All @@ -81,21 +81,41 @@ class _VideosListState extends State<VideosList> {
@override
Widget build(BuildContext context) {
final bottom = nomore ? a : b;

return videoList.isEmpty
? const Center(child: CircularProgressIndicator())
: RefreshIndicator(
onRefresh: _pullToRefresh,
child: ListView(
controller: _controller,
children: [
VideoGridWidget(
videoList,
controller: ScrollController(),
return FutureBuilder(
future: loadData,
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (!snapshot.hasError) {
return RefreshIndicator(
onRefresh: _pullToRefresh,
child: ListView(
controller: _controller,
children: [
VideoGridWidget(
videoList,
controller: ScrollController(),
),
bottom,
],
));
} else {
return Center(
child: TextButton(
child: const Text("加载失败,点击重试"),
onPressed: () => {
setState(() {
loadData = _pullToRefresh();
})
},
),
bottom,
],
));
);
}
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
});
}

Future _pullToRefresh() async {
Expand Down

0 comments on commit ee73ec1

Please sign in to comment.