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 @override
build(BuildContext context) { build(BuildContext context) {
return BlocBuilder<ListShareeBloc, ListShareeBlocState>( return BlocListener<ListShareeBloc, ListShareeBlocState>(
bloc: _shareeBloc, bloc: _shareeBloc,
builder: (_, shareeState) => listener: (context, shareeState) =>
BlocBuilder<ListShareBloc, ListShareBlocState>( _onListShareeBlocStateChanged(context, shareeState),
bloc: _shareBloc, child: BlocBuilder<ListShareeBloc, ListShareeBlocState>(
builder: (context, shareState) => bloc: _shareeBloc,
_buildContent(context, shareeState, shareState), 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( void _onShareePressed(
BuildContext context, Sharee sharee, Share? share) async { BuildContext context, Sharee sharee, Share? share) async {
final shareRepo = ShareRepo(ShareRemoteDataSource()); final shareRepo = ShareRepo(ShareRemoteDataSource());