diff --git a/lib/widget/dialog_scaffold.dart b/lib/widget/dialog_scaffold.dart new file mode 100644 index 00000000..cb27a676 --- /dev/null +++ b/lib/widget/dialog_scaffold.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +/// A Scaffold that can be used with dialogs +/// +/// Scaffold is needed for [SnackBar] to show correctly on top of a dialog +class DialogScaffold extends StatelessWidget { + const DialogScaffold({ + Key? key, + required this.body, + this.canPop = true, + }) : super(key: key); + + @override + build(BuildContext context) { + return GestureDetector( + onTap: () { + if (canPop) { + Navigator.of(context).pop(); + } + }, + child: WillPopScope( + onWillPop: () => Future.value(canPop), + child: Scaffold( + backgroundColor: Colors.transparent, + body: GestureDetector( + onTap: () {}, + child: body, + ), + ), + ), + ); + } + + final Widget body; + final bool canPop; +} diff --git a/lib/widget/share_album_dialog.dart b/lib/widget/share_album_dialog.dart index f46c7fdf..fad18474 100644 --- a/lib/widget/share_album_dialog.dart +++ b/lib/widget/share_album_dialog.dart @@ -23,6 +23,7 @@ import 'package:nc_photos/theme.dart'; import 'package:nc_photos/use_case/share_album_with_user.dart'; import 'package:nc_photos/use_case/unshare_album_with_user.dart'; import 'package:nc_photos/widget/album_share_outlier_browser.dart'; +import 'package:nc_photos/widget/dialog_scaffold.dart'; class ShareAlbumDialog extends StatefulWidget { ShareAlbumDialog({ @@ -54,25 +55,14 @@ class _ShareAlbumDialogState extends State { @override build(BuildContext context) { - final canPop = _processingSharee.isEmpty; return AppTheme( - child: GestureDetector( - onTap: () { - if (canPop) { - Navigator.of(context).pop(); - } - }, - child: WillPopScope( - onWillPop: () => Future.value(canPop), - child: Scaffold( - backgroundColor: Colors.transparent, - body: BlocListener( - bloc: _shareeBloc, - listener: _onShareeStateChange, - child: Builder( - builder: _buildContent, - ), - ), + child: DialogScaffold( + canPop: _processingSharee.isEmpty, + body: BlocListener( + bloc: _shareeBloc, + listener: _onShareeStateChange, + child: Builder( + builder: _buildContent, ), ), ), @@ -80,15 +70,12 @@ class _ShareAlbumDialogState extends State { } Widget _buildContent(BuildContext context) { - return GestureDetector( - onTap: () {}, - child: SimpleDialog( - title: Text(L10n.global().shareAlbumDialogTitle), - children: [ - ..._items.map((i) => _buildItem(context, i)), - _buildCreateShareItem(context), - ], - ), + return SimpleDialog( + title: Text(L10n.global().shareAlbumDialogTitle), + children: [ + ..._items.map((i) => _buildItem(context, i)), + _buildCreateShareItem(context), + ], ); }