mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Add pull to refresh to people browser
This commit is contained in:
parent
a4018cd3f3
commit
368026fab8
4 changed files with 53 additions and 23 deletions
|
@ -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),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue