ente/lib/ui/components/action_sheet_widget.dart

222 lines
6.9 KiB
Dart
Raw Normal View History

import 'dart:ui';
import 'package:flutter/material.dart';
2022-12-08 09:36:02 +00:00
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
2022-12-12 12:29:02 +00:00
import 'package:photos/core/constants.dart';
import "package:photos/models/search/button_result.dart";
2022-12-08 09:36:02 +00:00
import 'package:photos/theme/colors.dart';
import 'package:photos/theme/effects.dart';
import 'package:photos/theme/ente_theme.dart';
import 'package:photos/ui/components/buttons/button_widget.dart';
2022-12-09 03:45:06 +00:00
import 'package:photos/utils/separators_util.dart';
enum ActionSheetType {
defaultActionSheet,
iconOnly,
}
///Returns null if dismissed
Future<ButtonResult?> showActionSheet({
2022-12-08 09:36:02 +00:00
required BuildContext context,
required List<ButtonWidget> buttons,
2023-01-06 08:30:35 +00:00
ActionSheetType actionSheetType = ActionSheetType.defaultActionSheet,
bool enableDrag = true,
bool isDismissible = true,
bool isCheckIconGreen = false,
2022-12-08 09:36:02 +00:00
String? title,
Widget? bodyWidget,
2022-12-08 09:36:02 +00:00
String? body,
String? bodyHighlight,
2022-12-08 09:36:02 +00:00
}) {
return showMaterialModalBottomSheet(
2022-12-08 09:36:02 +00:00
backgroundColor: Colors.transparent,
2022-12-17 05:18:33 +00:00
barrierColor: backdropFaintDark,
2022-12-08 09:36:02 +00:00
useRootNavigator: true,
context: context,
isDismissible: isDismissible,
enableDrag: enableDrag,
2022-12-08 09:36:02 +00:00
builder: (_) {
return ActionSheetWidget(
title: title,
bodyWidget: bodyWidget,
2022-12-08 09:36:02 +00:00
body: body,
bodyHighlight: bodyHighlight,
2022-12-08 09:36:02 +00:00
actionButtons: buttons,
actionSheetType: actionSheetType,
isCheckIconGreen: isCheckIconGreen,
2022-12-08 09:36:02 +00:00
);
},
);
}
class ActionSheetWidget extends StatelessWidget {
final String? title;
final Widget? bodyWidget;
final String? body;
final String? bodyHighlight;
final List<ButtonWidget> actionButtons;
final ActionSheetType actionSheetType;
final bool isCheckIconGreen;
2022-12-08 09:36:02 +00:00
const ActionSheetWidget({
required this.actionButtons,
required this.actionSheetType,
required this.isCheckIconGreen,
2022-12-08 09:36:02 +00:00
this.title,
this.bodyWidget,
2022-12-08 09:36:02 +00:00
this.body,
this.bodyHighlight,
2022-12-08 09:36:02 +00:00
super.key,
});
@override
Widget build(BuildContext context) {
final isTitleAndBodyNull =
title == null && bodyWidget == null && body == null;
2022-12-08 09:36:02 +00:00
final blur = MediaQuery.of(context).platformBrightness == Brightness.light
? blurMuted
: blurBase;
2022-12-12 12:29:02 +00:00
final extraWidth = MediaQuery.of(context).size.width - restrictedMaxWidth;
final double? horizontalPadding = extraWidth > 0 ? extraWidth / 2 : null;
return Padding(
2022-12-12 12:29:02 +00:00
padding: EdgeInsets.fromLTRB(
horizontalPadding ?? 12,
12,
horizontalPadding ?? 12,
32,
),
2022-12-08 09:36:02 +00:00
child: Container(
decoration: BoxDecoration(boxShadow: shadowMenuLight),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(8)),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
child: Container(
2022-12-17 05:18:33 +00:00
color: backdropMutedDark,
2022-12-08 09:36:02 +00:00
child: Padding(
padding: EdgeInsets.fromLTRB(
24,
24,
24,
isTitleAndBodyNull ? 24 : 28,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
isTitleAndBodyNull
? const SizedBox.shrink()
: Padding(
2023-01-30 09:48:24 +00:00
padding: const EdgeInsets.only(bottom: 36),
2022-12-08 09:36:02 +00:00
child: ContentContainerWidget(
title: title,
2023-01-26 05:23:50 +00:00
bodyWidget: bodyWidget,
2022-12-08 09:36:02 +00:00
body: body,
bodyHighlight: bodyHighlight,
actionSheetType: actionSheetType,
isCheckIconGreen: isCheckIconGreen,
2022-12-08 09:36:02 +00:00
),
),
ActionButtons(
actionButtons,
),
],
),
),
),
),
),
),
);
}
}
class ContentContainerWidget extends StatelessWidget {
final String? title;
final Widget? bodyWidget;
final String? body;
final String? bodyHighlight;
final ActionSheetType actionSheetType;
final bool isCheckIconGreen;
const ContentContainerWidget({
required this.actionSheetType,
required this.isCheckIconGreen,
this.title,
this.bodyWidget,
this.body,
this.bodyHighlight,
super.key,
});
@override
Widget build(BuildContext context) {
final textTheme = getEnteTextTheme(context);
final bool bodyMissing = body == null && bodyWidget == null;
2023-01-26 05:23:50 +00:00
debugPrint("body missing $bodyMissing");
return Column(
mainAxisSize: MainAxisSize.min,
2022-12-08 11:33:46 +00:00
//todo: set cross axis to center when icon should be shown in place of body
crossAxisAlignment: actionSheetType == ActionSheetType.defaultActionSheet
? CrossAxisAlignment.stretch
: CrossAxisAlignment.center,
children: [
title == null
? const SizedBox.shrink()
: Text(
title!,
style: textTheme.largeBold
2022-12-08 11:33:46 +00:00
.copyWith(color: textBaseDark), //constant color
),
title == null || bodyMissing
? const SizedBox.shrink()
: const SizedBox(height: 19),
actionSheetType == ActionSheetType.defaultActionSheet
? bodyMissing
? const SizedBox.shrink()
: (bodyWidget != null
? bodyWidget!
: Text(
body!,
style: textTheme.body
.copyWith(color: textMutedDark), //constant color
))
: Icon(
Icons.check_outlined,
size: 48,
color: isCheckIconGreen
? getEnteColorScheme(context).primary700
: strokeBaseDark,
),
actionSheetType == ActionSheetType.defaultActionSheet &&
bodyHighlight != null
? Padding(
padding: const EdgeInsets.only(top: 19.0),
child: Text(
bodyHighlight!,
style: textTheme.body
.copyWith(color: textBaseDark), //constant color
),
)
: const SizedBox.shrink(),
],
);
}
}
class ActionButtons extends StatelessWidget {
final List<Widget> actionButtons;
const ActionButtons(this.actionButtons, {super.key});
@override
Widget build(BuildContext context) {
final actionButtonsWithSeparators = actionButtons;
return Column(
children:
2022-12-08 11:33:46 +00:00
//Separator height is 8pts in figma. -2pts here as the action
//buttons are 2pts extra in height in code compared to figma because
//of the border(1pt top + 1pt bottom) of action buttons.
addSeparators(actionButtonsWithSeparators, const SizedBox(height: 6)),
);
}
}