mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 09:16:19 +01:00
Retain list person bloc state
This commit is contained in:
parent
2fd3f7feff
commit
129f72e7fe
2 changed files with 28 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:kiwi/kiwi.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/entity/person.dart';
|
import 'package:nc_photos/entity/person.dart';
|
||||||
|
@ -70,6 +71,22 @@ class ListPersonBlocFailure extends ListPersonBlocState {
|
||||||
class ListPersonBloc extends Bloc<ListPersonBlocEvent, ListPersonBlocState> {
|
class ListPersonBloc extends Bloc<ListPersonBlocEvent, ListPersonBlocState> {
|
||||||
ListPersonBloc() : super(ListPersonBlocInit());
|
ListPersonBloc() : super(ListPersonBlocInit());
|
||||||
|
|
||||||
|
static ListPersonBloc of(Account account) {
|
||||||
|
final id =
|
||||||
|
"${account.scheme}://${account.username}@${account.address}?${account.roots.join('&')}";
|
||||||
|
try {
|
||||||
|
_log.fine("[of] Resolving bloc for '$id'");
|
||||||
|
return KiwiContainer().resolve<ListPersonBloc>("ListPersonBloc($id)");
|
||||||
|
} catch (_) {
|
||||||
|
// no created instance for this account, make a new one
|
||||||
|
_log.info("[of] New bloc instance for account: $account");
|
||||||
|
final bloc = ListPersonBloc();
|
||||||
|
KiwiContainer().registerInstance<ListPersonBloc>(bloc,
|
||||||
|
name: "ListPersonBloc($id)");
|
||||||
|
return bloc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
mapEventToState(ListPersonBlocEvent event) async* {
|
mapEventToState(ListPersonBlocEvent event) async* {
|
||||||
_log.info("[mapEventToState] $event");
|
_log.info("[mapEventToState] $event");
|
||||||
|
|
|
@ -78,7 +78,16 @@ class _PeopleBrowserState extends State<PeopleBrowser> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _initBloc() {
|
void _initBloc() {
|
||||||
|
if (_bloc.state is ListPersonBlocInit) {
|
||||||
_log.info("[_initBloc] Initialize bloc");
|
_log.info("[_initBloc] Initialize bloc");
|
||||||
|
} else {
|
||||||
|
// process the current state
|
||||||
|
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||||
|
setState(() {
|
||||||
|
_onStateChange(context, _bloc.state);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
_reqQuery();
|
_reqQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,14 +221,13 @@ class _PeopleBrowserState extends State<PeopleBrowser> {
|
||||||
onTap: () => _onItemTap(e),
|
onTap: () => _onItemTap(e),
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
// _items = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _reqQuery() {
|
void _reqQuery() {
|
||||||
_bloc.add(ListPersonBlocQuery(widget.account));
|
_bloc.add(ListPersonBlocQuery(widget.account));
|
||||||
}
|
}
|
||||||
|
|
||||||
final _bloc = ListPersonBloc();
|
late final _bloc = ListPersonBloc.of(widget.account);
|
||||||
|
|
||||||
var _items = <_ListItem>[];
|
var _items = <_ListItem>[];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue