Add pull to refresh to people browser

This commit is contained in:
Ming Ming 2023-12-13 23:05:40 +08:00
parent a4018cd3f3
commit 368026fab8
4 changed files with 53 additions and 23 deletions

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:collection/collection.dart';
import 'package:copy_with/copy_with.dart';
import 'package:flutter/material.dart';
@ -95,30 +97,37 @@ class _WrappedPeopleBrowserState extends State<_WrappedPeopleBrowser>
child: Scaffold(
body: Stack(
children: [
CustomScrollView(
slivers: [
const _AppBar(),
SliverToBoxAdapter(
child: _BlocBuilder(
buildWhen: (previous, current) =>
previous.isLoading != current.isLoading,
builder: (context, state) => state.isLoading
? const LinearProgressIndicator()
: const SizedBox(height: 4),
RefreshIndicator(
onRefresh: () async {
_bloc.add(const _Reload());
await _bloc.stream.first;
},
child: CustomScrollView(
slivers: [
const _AppBar(),
SliverToBoxAdapter(
child: _BlocBuilder(
buildWhen: (previous, current) =>
previous.isLoading != current.isLoading,
builder: (context, state) => state.isLoading
? const LinearProgressIndicator()
: const SizedBox(height: 4),
),
),
),
_ContentList(
onTap: (_, item) {
Navigator.pushNamed(
context,
CollectionBrowser.routeName,
arguments: CollectionBrowserArguments(
CollectionBuilder.byPerson(_bloc.account, item.person),
),
);
},
),
],
_ContentList(
onTap: (_, item) {
Navigator.pushNamed(
context,
CollectionBrowser.routeName,
arguments: CollectionBrowserArguments(
CollectionBuilder.byPerson(
_bloc.account, item.person),
),
);
},
),
],
),
),
],
),

View file

@ -88,6 +88,13 @@ extension _$_LoadPersonsToString on _LoadPersons {
}
}
extension _$_ReloadToString on _Reload {
String _$toString() {
// ignore: unnecessary_string_interpolations
return "_Reload {}";
}
}
extension _$_TransformItemsToString on _TransformItems {
String _$toString() {
// ignore: unnecessary_string_interpolations

View file

@ -7,6 +7,7 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
required this.personsController,
}) : super(_State.init()) {
on<_LoadPersons>(_onLoad);
on<_Reload>(_onReload);
on<_TransformItems>(_onTransformItems);
}
@ -31,6 +32,11 @@ class _Bloc extends Bloc<_Event, _State> with BlocLogger {
);
}
void _onReload(_Reload ev, Emitter<_State> emit) {
_log.info(ev);
unawaited(personsController.reload());
}
Future<void> _onTransformItems(
_TransformItems ev, Emitter<_State> emit) async {
_log.info("[_onTransformItems] $ev");

View file

@ -37,6 +37,14 @@ class _LoadPersons implements _Event {
String toString() => _$toString();
}
@toString
class _Reload implements _Event {
const _Reload();
@override
String toString() => _$toString();
}
/// Transform the [Person] list (e.g., filtering, sorting, etc)
@toString
class _TransformItems implements _Event {