Refactoring: extract bottom app bar in viewer

This commit is contained in:
Ming Ming 2021-07-31 23:38:01 +08:00
parent ce2aefebb0
commit 80a64b35bc
2 changed files with 79 additions and 53 deletions

View file

@ -25,6 +25,7 @@ import 'package:nc_photos/use_case/remove.dart';
import 'package:nc_photos/widget/animated_visibility.dart'; import 'package:nc_photos/widget/animated_visibility.dart';
import 'package:nc_photos/widget/image_viewer.dart'; import 'package:nc_photos/widget/image_viewer.dart';
import 'package:nc_photos/widget/video_viewer.dart'; import 'package:nc_photos/widget/video_viewer.dart';
import 'package:nc_photos/widget/viewer_bottom_app_bar.dart';
import 'package:nc_photos/widget/viewer_detail_pane.dart'; import 'package:nc_photos/widget/viewer_detail_pane.dart';
class ViewerArguments { class ViewerArguments {
@ -286,59 +287,10 @@ class _ViewerState extends State<Viewer> {
duration: !_isDetailPaneActive duration: !_isDetailPaneActive
? k.animationDurationNormal ? k.animationDurationNormal
: const Duration(milliseconds: 1), : const Duration(milliseconds: 1),
child: Container( child: ViewerBottomAppBar(
height: kToolbarHeight, onSharePressed: () => _onSharePressed(context),
alignment: Alignment.center, onDownloadPressed: () => _onDownloadPressed(context),
decoration: BoxDecoration( onDeletePressed: () => _onDeletePressed(context),
gradient: LinearGradient(
begin: const Alignment(0, -1),
end: const Alignment(0, 1),
colors: [
Color.fromARGB(0, 0, 0, 0),
Color.fromARGB(192, 0, 0, 0),
],
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
if (platform_k.isAndroid)
Expanded(
flex: 1,
child: IconButton(
icon: Icon(
Icons.share_outlined,
color: Colors.white.withOpacity(.87),
),
tooltip: L10n.of(context).shareTooltip,
onPressed: () => _onSharePressed(context),
),
),
Expanded(
flex: 1,
child: IconButton(
icon: Icon(
Icons.download_outlined,
color: Colors.white.withOpacity(.87),
),
tooltip: L10n.of(context).downloadTooltip,
onPressed: () => _onDownloadPressed(context),
),
),
Expanded(
flex: 1,
child: IconButton(
icon: Icon(
Icons.delete_outlined,
color: Colors.white.withOpacity(.87),
),
tooltip: L10n.of(context).deleteTooltip,
onPressed: () => _onDeletePressed(context),
),
),
],
),
), ),
), ),
), ),

View file

@ -0,0 +1,74 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/platform/k.dart' as platform_k;
class ViewerBottomAppBar extends StatelessWidget {
ViewerBottomAppBar({
this.onSharePressed,
this.onDownloadPressed,
this.onDeletePressed,
});
@override
build(BuildContext context) {
return Container(
height: kToolbarHeight,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: const Alignment(0, -1),
end: const Alignment(0, 1),
colors: [
Color.fromARGB(0, 0, 0, 0),
Color.fromARGB(192, 0, 0, 0),
],
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
if (platform_k.isAndroid)
Expanded(
flex: 1,
child: IconButton(
icon: Icon(
Icons.share_outlined,
color: Colors.white.withOpacity(.87),
),
tooltip: L10n.of(context).shareTooltip,
onPressed: onSharePressed,
),
),
Expanded(
flex: 1,
child: IconButton(
icon: Icon(
Icons.download_outlined,
color: Colors.white.withOpacity(.87),
),
tooltip: L10n.of(context).downloadTooltip,
onPressed: onDownloadPressed,
),
),
Expanded(
flex: 1,
child: IconButton(
icon: Icon(
Icons.delete_outlined,
color: Colors.white.withOpacity(.87),
),
tooltip: L10n.of(context).deleteTooltip,
onPressed: onDeletePressed,
),
),
],
),
);
}
final VoidCallback? onSharePressed;
final VoidCallback? onDownloadPressed;
final VoidCallback? onDeletePressed;
}