import 'package:event/event.dart'; import 'package:flutter/material.dart'; import 'package:pikapika/basic/Entities.dart'; import 'package:pikapika/basic/config/ShadowCategoriesEvent.dart'; import 'package:pikapika/screens/components/ComicList.dart'; import 'package:pikapika/screens/components/FitButton.dart'; import 'ContentBuilder.dart'; class ComicListBuilder extends StatefulWidget { final Future> Function() takeList; const ComicListBuilder(this.takeList, {Key? key}) : super(key: key); @override State createState() => _ComicListBuilderState(); } class _ComicListBuilderState extends State { late Future> _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(() {}); } Future _reload() async { setState(() { _future = widget.takeList(); _key = UniqueKey(); }); } @override Widget build(BuildContext context) { return ContentBuilder( key: _key, future: _future, onRefresh: _reload, successBuilder: (BuildContext context, AsyncSnapshot> snapshot) { return RefreshIndicator( onRefresh: _reload, child: ComicList( snapshot.data!, appendWidget: FitButton( onPressed: _reload, text: '刷新', ), ), ); }, ); } }