dialogs.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import 'package:flowy_infra/strings.dart';
  2. import 'package:flowy_infra/text_style.dart';
  3. import 'package:flowy_infra/theme.dart';
  4. import 'package:flowy_infra_ui/style_widget/text.dart';
  5. import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
  6. import 'package:flowy_infra_ui/widget/buttons/secondary_button.dart';
  7. import 'package:flowy_infra_ui/widget/spacing.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:provider/provider.dart';
  10. import 'package:app_flowy/startup/tasks/application_task.dart';
  11. import 'package:flowy_infra/size.dart';
  12. import 'package:flowy_infra_ui/style_widget/text_input.dart';
  13. import 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  14. import 'package:textstyle_extensions/textstyle_extensions.dart';
  15. export 'package:flowy_infra_ui/widget/dialog/styled_dialogs.dart';
  16. class RenameDialog extends StatefulWidget {
  17. final String name;
  18. final String title;
  19. final void Function()? cancel;
  20. final void Function(String) confirm;
  21. const RenameDialog({
  22. required this.title,
  23. required this.name,
  24. required this.confirm,
  25. this.cancel,
  26. Key? key,
  27. }) : super(key: key);
  28. @override
  29. State<RenameDialog> createState() => _CreateRenameDialog();
  30. }
  31. class _CreateRenameDialog extends State<RenameDialog> {
  32. String newViewName = "";
  33. @override
  34. void initState() {
  35. newViewName = widget.name;
  36. super.initState();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. final theme = context.watch<AppTheme>();
  41. return StyledDialog(
  42. child: Column(
  43. crossAxisAlignment: CrossAxisAlignment.start,
  44. children: <Widget>[
  45. ...[
  46. FlowyText.medium(widget.title, color: theme.shader4),
  47. VSpace(Insets.sm * 1.5),
  48. ],
  49. FlowyFormTextInput(
  50. hintText: widget.name,
  51. onChanged: (text) {
  52. newViewName = text;
  53. },
  54. ),
  55. SizedBox(height: Insets.l),
  56. SizedBox(
  57. height: 40,
  58. child: OkCancelButton(
  59. onOkPressed: () {
  60. widget.confirm(newViewName);
  61. },
  62. onCancelPressed: () {
  63. if (widget.cancel != null) {
  64. widget.cancel!();
  65. }
  66. },
  67. ),
  68. )
  69. ],
  70. ),
  71. );
  72. }
  73. }
  74. class OkCancelDialog extends StatelessWidget {
  75. final VoidCallback? onOkPressed;
  76. final VoidCallback? onCancelPressed;
  77. final String? okTitle;
  78. final String? cancelTitle;
  79. final String? title;
  80. final String message;
  81. final double? maxWidth;
  82. const OkCancelDialog(
  83. {Key? key,
  84. this.onOkPressed,
  85. this.onCancelPressed,
  86. this.okTitle,
  87. this.cancelTitle,
  88. this.title,
  89. required this.message,
  90. this.maxWidth})
  91. : super(key: key);
  92. @override
  93. Widget build(BuildContext context) {
  94. final theme = context.watch<AppTheme>();
  95. return StyledDialog(
  96. maxWidth: maxWidth ?? 500,
  97. child: Column(
  98. crossAxisAlignment: CrossAxisAlignment.start,
  99. children: <Widget>[
  100. if (title != null) ...[
  101. Text(title!.toUpperCase(), style: TextStyles.T1.textColor(theme.shader1)),
  102. VSpace(Insets.sm * 1.5),
  103. Container(color: theme.bg1, height: 1),
  104. VSpace(Insets.m * 1.5),
  105. ],
  106. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  107. SizedBox(height: Insets.l),
  108. OkCancelButton(
  109. onOkPressed: onOkPressed,
  110. onCancelPressed: onCancelPressed,
  111. okTitle: okTitle?.toUpperCase(),
  112. cancelTitle: cancelTitle?.toUpperCase(),
  113. )
  114. ],
  115. ),
  116. );
  117. }
  118. }
  119. class OkCancelButton extends StatelessWidget {
  120. final VoidCallback? onOkPressed;
  121. final VoidCallback? onCancelPressed;
  122. final String? okTitle;
  123. final String? cancelTitle;
  124. final double? minHeight;
  125. const OkCancelButton(
  126. {Key? key, this.onOkPressed, this.onCancelPressed, this.okTitle, this.cancelTitle, this.minHeight})
  127. : super(key: key);
  128. @override
  129. Widget build(BuildContext context) {
  130. return Row(
  131. mainAxisAlignment: MainAxisAlignment.end,
  132. children: <Widget>[
  133. if (onCancelPressed != null)
  134. SecondaryTextButton(
  135. cancelTitle ?? S.BTN_CANCEL,
  136. onPressed: () {
  137. onCancelPressed!();
  138. AppGlobals.nav.pop();
  139. },
  140. bigMode: true,
  141. ),
  142. HSpace(Insets.m),
  143. if (onOkPressed != null)
  144. PrimaryTextButton(
  145. okTitle ?? S.BTN_OK,
  146. onPressed: () {
  147. onOkPressed!();
  148. AppGlobals.nav.pop();
  149. },
  150. bigMode: true,
  151. ),
  152. ],
  153. );
  154. }
  155. }