问题描述
我的应用中有一个显示通知列表的 UI! 我添加了 pull to refresh,它再次从 api 获取通知列表。
我现在要做的是,显示通知列表,当用户触发刷新时,我还想显示列表,以及显示加载状态
顶部的LinearProgressIndicator()
在加载时显示,但加载并重新出现时下面的列表消失
class NotificationsRepo {
final HttpApi httpApi;
NotificationsRepo({required this.httpApi});
Future<List<Notify>> getAll() async {
// Get from api and return values
} on MyException catch (_) {
rethrow;
}
}
}
final notificationsRepoPod = Provider<NotificationsRepo>((ref) {
return NotificationsRepo(httpApi: ref.watch(httpProvider));
});
我有这样的提供者
final notificationsPod = FutureProvider.autodispose<List<Notify>>((ref) {
return ref.read(notificationsRepoPod).getAll();
});
在用户界面中,这就是我所做的。
return Scaffold(
appBar: AppBar(),body: Refreshindicator(
onRefresh: () => context.refresh(notificationsPod),child: Column(
children: [
watch(notificationsPod).maybeWhen(
loading: () => const LinearProgressIndicator(),orElse: () => const SizedBox(),),watch(notificationsPod).maybeWhen(
data: (notifs) => Expanded(
child: ListView.separated(
itemBuilder: (_,i) => NotificationItem(notify: notifs[i]),separatorBuilder: (_,__) => const Divider(height: 0),itemCount: notifs.length,],);
如何让list显示有数据,以及loading状态下的loading显示?
使用上面的当前代码,这就是发生的事情
加载时:
当它有数据时
请问解决此问题的最佳 Riverpod 方法是什么?如果之前有数据,则显示列表,并在加载时显示加载
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)