dialog_widget.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/core/constants.dart';
  4. import 'package:photos/theme/colors.dart';
  5. import 'package:photos/theme/effects.dart';
  6. import 'package:photos/theme/ente_theme.dart';
  7. import 'package:photos/ui/components/button_widget.dart';
  8. import 'package:photos/utils/separators_util.dart';
  9. Future<dynamic> showDialogWidget({
  10. required BuildContext context,
  11. required String title,
  12. required String body,
  13. required List<ButtonWidget> buttons,
  14. IconData? icon,
  15. }) {
  16. return showDialog(
  17. barrierDismissible: false,
  18. barrierColor: backdropFaintDark,
  19. context: context,
  20. builder: (context) {
  21. final widthOfScreen = MediaQuery.of(context).size.width;
  22. final isMobileSmall = widthOfScreen <= mobileSmallThreshold;
  23. return Padding(
  24. padding: EdgeInsets.symmetric(horizontal: isMobileSmall ? 8 : 0),
  25. child: Dialog(
  26. insetPadding: EdgeInsets.zero,
  27. child: DialogWidget(
  28. title: title,
  29. body: body,
  30. buttons: buttons,
  31. isMobileSmall: isMobileSmall,
  32. icon: icon,
  33. ),
  34. ),
  35. );
  36. },
  37. );
  38. }
  39. class DialogWidget extends StatelessWidget {
  40. final String title;
  41. final String body;
  42. final List<ButtonWidget> buttons;
  43. final IconData? icon;
  44. final bool isMobileSmall;
  45. const DialogWidget({
  46. required this.title,
  47. required this.body,
  48. required this.buttons,
  49. required this.isMobileSmall,
  50. this.icon,
  51. super.key,
  52. });
  53. @override
  54. Widget build(BuildContext context) {
  55. final widthOfScreen = MediaQuery.of(context).size.width;
  56. final colorScheme = getEnteColorScheme(context);
  57. return Container(
  58. width: min(widthOfScreen, 320),
  59. padding: isMobileSmall
  60. ? const EdgeInsets.all(0)
  61. : const EdgeInsets.fromLTRB(6, 8, 6, 6),
  62. decoration: BoxDecoration(
  63. color: colorScheme.backgroundElevated,
  64. boxShadow: shadowFloatLight,
  65. borderRadius: const BorderRadius.all(Radius.circular(8)),
  66. ),
  67. child: Padding(
  68. padding: const EdgeInsets.all(16),
  69. child: Column(
  70. mainAxisSize: MainAxisSize.min,
  71. children: [
  72. ContentContainer(
  73. title: title,
  74. body: body,
  75. icon: icon,
  76. ),
  77. const SizedBox(height: 36),
  78. Actions(buttons),
  79. ],
  80. ),
  81. ),
  82. );
  83. }
  84. }
  85. class ContentContainer extends StatelessWidget {
  86. final String title;
  87. final String body;
  88. final IconData? icon;
  89. const ContentContainer({
  90. required this.title,
  91. required this.body,
  92. this.icon,
  93. super.key,
  94. });
  95. @override
  96. Widget build(BuildContext context) {
  97. final textTheme = getEnteTextTheme(context);
  98. final colorScheme = getEnteColorScheme(context);
  99. return Column(
  100. mainAxisSize: MainAxisSize.min,
  101. crossAxisAlignment: CrossAxisAlignment.stretch,
  102. children: [
  103. icon == null
  104. ? const SizedBox.shrink()
  105. : Row(
  106. children: [
  107. Icon(
  108. icon,
  109. size: 48,
  110. ),
  111. ],
  112. ),
  113. icon == null ? const SizedBox.shrink() : const SizedBox(height: 19),
  114. Text(title, style: textTheme.h3Bold),
  115. const SizedBox(height: 19),
  116. Text(
  117. body,
  118. style: textTheme.body.copyWith(color: colorScheme.textMuted),
  119. ),
  120. ],
  121. );
  122. }
  123. }
  124. class Actions extends StatelessWidget {
  125. final List<ButtonWidget> buttons;
  126. const Actions(this.buttons, {super.key});
  127. @override
  128. Widget build(BuildContext context) {
  129. return Column(
  130. children: addSeparators(
  131. buttons,
  132. const SizedBox(
  133. height: 8,
  134. ),
  135. ),
  136. );
  137. }
  138. }