action_sheet_widget.dart 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
  4. import 'package:photos/core/constants.dart';
  5. import 'package:photos/theme/colors.dart';
  6. import 'package:photos/theme/effects.dart';
  7. import 'package:photos/theme/ente_theme.dart';
  8. import 'package:photos/ui/components/button_widget.dart';
  9. import 'package:photos/utils/separators_util.dart';
  10. enum ActionSheetType {
  11. defaultActionSheet,
  12. iconOnly,
  13. }
  14. ///Returns null if dismissed
  15. Future<ButtonAction?> showActionSheet({
  16. required BuildContext context,
  17. required List<ButtonWidget> buttons,
  18. required ActionSheetType actionSheetType,
  19. bool enableDrag = true,
  20. bool isDismissible = true,
  21. bool isCheckIconGreen = false,
  22. String? title,
  23. String? body,
  24. }) {
  25. return showMaterialModalBottomSheet(
  26. backgroundColor: Colors.transparent,
  27. barrierColor: backdropFaintDark,
  28. useRootNavigator: true,
  29. context: context,
  30. isDismissible: isDismissible,
  31. enableDrag: enableDrag,
  32. builder: (_) {
  33. return ActionSheetWidget(
  34. title: title,
  35. body: body,
  36. actionButtons: buttons,
  37. actionSheetType: actionSheetType,
  38. isCheckIconGreen: isCheckIconGreen,
  39. );
  40. },
  41. );
  42. }
  43. class ActionSheetWidget extends StatelessWidget {
  44. final String? title;
  45. final String? body;
  46. final List<ButtonWidget> actionButtons;
  47. final ActionSheetType actionSheetType;
  48. final bool isCheckIconGreen;
  49. const ActionSheetWidget({
  50. required this.actionButtons,
  51. required this.actionSheetType,
  52. required this.isCheckIconGreen,
  53. this.title,
  54. this.body,
  55. super.key,
  56. });
  57. @override
  58. Widget build(BuildContext context) {
  59. final isTitleAndBodyNull = title == null && body == null;
  60. final blur = MediaQuery.of(context).platformBrightness == Brightness.light
  61. ? blurMuted
  62. : blurBase;
  63. final extraWidth = MediaQuery.of(context).size.width - restrictedMaxWidth;
  64. final double? horizontalPadding = extraWidth > 0 ? extraWidth / 2 : null;
  65. return Padding(
  66. padding: EdgeInsets.fromLTRB(
  67. horizontalPadding ?? 12,
  68. 12,
  69. horizontalPadding ?? 12,
  70. 32,
  71. ),
  72. child: Container(
  73. decoration: BoxDecoration(boxShadow: shadowMenuLight),
  74. child: ClipRRect(
  75. borderRadius: const BorderRadius.all(Radius.circular(8)),
  76. child: BackdropFilter(
  77. filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
  78. child: Container(
  79. color: backdropMutedDark,
  80. child: Padding(
  81. padding: EdgeInsets.fromLTRB(
  82. 24,
  83. 24,
  84. 24,
  85. isTitleAndBodyNull ? 24 : 28,
  86. ),
  87. child: Column(
  88. mainAxisSize: MainAxisSize.min,
  89. children: [
  90. isTitleAndBodyNull
  91. ? const SizedBox.shrink()
  92. : Padding(
  93. padding: const EdgeInsets.only(bottom: 36),
  94. child: ContentContainerWidget(
  95. title: title,
  96. body: body,
  97. actionSheetType: actionSheetType,
  98. isCheckIconGreen: isCheckIconGreen,
  99. ),
  100. ),
  101. ActionButtons(
  102. actionButtons,
  103. ),
  104. ],
  105. ),
  106. ),
  107. ),
  108. ),
  109. ),
  110. ),
  111. );
  112. }
  113. }
  114. class ContentContainerWidget extends StatelessWidget {
  115. final String? title;
  116. final String? body;
  117. final ActionSheetType actionSheetType;
  118. final bool isCheckIconGreen;
  119. const ContentContainerWidget({
  120. required this.actionSheetType,
  121. required this.isCheckIconGreen,
  122. this.title,
  123. this.body,
  124. super.key,
  125. });
  126. @override
  127. Widget build(BuildContext context) {
  128. final textTheme = getEnteTextTheme(context);
  129. return Column(
  130. mainAxisSize: MainAxisSize.min,
  131. //todo: set cross axis to center when icon should be shown in place of body
  132. crossAxisAlignment: actionSheetType == ActionSheetType.defaultActionSheet
  133. ? CrossAxisAlignment.stretch
  134. : CrossAxisAlignment.center,
  135. children: [
  136. title == null
  137. ? const SizedBox.shrink()
  138. : Text(
  139. title!,
  140. style: textTheme.h3Bold
  141. .copyWith(color: textBaseDark), //constant color
  142. ),
  143. title == null || body == null
  144. ? const SizedBox.shrink()
  145. : const SizedBox(height: 19),
  146. actionSheetType == ActionSheetType.defaultActionSheet
  147. ? body == null
  148. ? const SizedBox.shrink()
  149. : Text(
  150. body!,
  151. style: textTheme.body
  152. .copyWith(color: textMutedDark), //constant color
  153. )
  154. : Icon(
  155. Icons.check_outlined,
  156. size: 48,
  157. color: isCheckIconGreen
  158. ? getEnteColorScheme(context).primary700
  159. : strokeBaseDark,
  160. )
  161. ],
  162. );
  163. }
  164. }
  165. class ActionButtons extends StatelessWidget {
  166. final List<Widget> actionButtons;
  167. const ActionButtons(this.actionButtons, {super.key});
  168. @override
  169. Widget build(BuildContext context) {
  170. final actionButtonsWithSeparators = actionButtons;
  171. return Column(
  172. children:
  173. //Separator height is 8pts in figma. -2pts here as the action
  174. //buttons are 2pts extra in height in code compared to figma because
  175. //of the border(1pt top + 1pt bottom) of action buttons.
  176. addSeparators(actionButtonsWithSeparators, const SizedBox(height: 6)),
  177. );
  178. }
  179. }