Improve error handling

This commit is contained in:
Ming Ming 2021-08-22 03:28:44 +08:00
parent ea8d351187
commit e165c618fe

View file

@ -39,13 +39,18 @@ class _ShareAlbumDialogState extends State<ShareAlbumDialog> {
@override
build(BuildContext context) {
return BlocBuilder<ListShareeBloc, ListShareeBlocState>(
return BlocListener<ListShareeBloc, ListShareeBlocState>(
bloc: _shareeBloc,
builder: (_, shareeState) =>
BlocBuilder<ListShareBloc, ListShareBlocState>(
bloc: _shareBloc,
builder: (context, shareState) =>
_buildContent(context, shareeState, shareState),
listener: (context, shareeState) =>
_onListShareeBlocStateChanged(context, shareeState),
child: BlocBuilder<ListShareeBloc, ListShareeBlocState>(
bloc: _shareeBloc,
builder: (_, shareeState) =>
BlocBuilder<ListShareBloc, ListShareBlocState>(
bloc: _shareBloc,
builder: (context, shareState) =>
_buildContent(context, shareeState, shareState),
),
),
);
}
@ -122,6 +127,16 @@ class _ShareAlbumDialogState extends State<ShareAlbumDialog> {
);
}
void _onListShareeBlocStateChanged(
BuildContext context, ListShareeBlocState state) {
if (state is ListShareeBlocFailure) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(exception_util.toUserString(state.exception, context)),
duration: k.snackBarDurationNormal,
));
}
}
void _onShareePressed(
BuildContext context, Sharee sharee, Share? share) async {
final shareRepo = ShareRepo(ShareRemoteDataSource());