pikapika/lib/screens/components/ComicListBuilder.dart

67 lines
1.7 KiB
Dart
Raw Normal View History

import 'package:event/event.dart';
2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/Entities.dart';
2021-11-24 13:22:22 +00:00
import 'package:pikapika/basic/config/ShadowCategoriesEvent.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/screens/components/ComicList.dart';
import 'package:pikapika/screens/components/FitButton.dart';
2021-09-29 23:57:09 +00:00
import 'ContentBuilder.dart';
class ComicListBuilder extends StatefulWidget {
2022-07-12 07:28:47 +00:00
final Future<List<ComicSimple>> Function() takeList;
2021-09-29 23:57:09 +00:00
2022-07-12 07:28:47 +00:00
const ComicListBuilder(this.takeList, {Key? key}) : super(key: key);
2021-09-29 23:57:09 +00:00
@override
State<StatefulWidget> createState() => _ComicListBuilderState();
}
class _ComicListBuilderState extends State<ComicListBuilder> {
2022-07-12 07:28:47 +00:00
late Future<List<ComicSimple>> _future = widget.takeList();
late Key _key = UniqueKey();
@override
void initState() {
shadowCategoriesEvent.subscribe(_onShadowChange);
super.initState();
}
@override
void dispose() {
shadowCategoriesEvent.unsubscribe(_onShadowChange);
super.dispose();
}
void _onShadowChange(EventArgs? args) {
setState(() {});
}
2022-07-12 07:28:47 +00:00
Future _reload() async {
setState(() {
_future = widget.takeList();
_key = UniqueKey();
});
}
2021-09-29 23:57:09 +00:00
@override
Widget build(BuildContext context) {
return ContentBuilder(
2022-07-12 07:28:47 +00:00
key: _key,
future: _future,
onRefresh: _reload,
2021-09-29 23:57:09 +00:00
successBuilder:
(BuildContext context, AsyncSnapshot<List<ComicSimple>> snapshot) {
return RefreshIndicator(
2022-07-12 07:28:47 +00:00
onRefresh: _reload,
2021-09-29 23:57:09 +00:00
child: ComicList(
snapshot.data!,
appendWidget: FitButton(
2022-07-12 07:28:47 +00:00
onPressed: _reload,
2021-09-29 23:57:09 +00:00
text: '刷新',
),
),
);
},
);
}
}