dialogs.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 TextFieldDialog extends StatefulWidget {
  17. final String value;
  18. final String title;
  19. final void Function()? cancel;
  20. final void Function(String) confirm;
  21. const TextFieldDialog({
  22. required this.title,
  23. required this.value,
  24. required this.confirm,
  25. this.cancel,
  26. Key? key,
  27. }) : super(key: key);
  28. @override
  29. State<TextFieldDialog> createState() => _CreateTextFieldDialog();
  30. }
  31. class _CreateTextFieldDialog extends State<TextFieldDialog> {
  32. String newValue = "";
  33. @override
  34. void initState() {
  35. newValue = widget.value;
  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.value,
  51. autoFocus: true,
  52. onChanged: (text) {
  53. newValue = text;
  54. },
  55. ),
  56. SizedBox(height: Insets.l),
  57. SizedBox(
  58. height: 40,
  59. child: OkCancelButton(
  60. onOkPressed: () {
  61. widget.confirm(newValue);
  62. },
  63. onCancelPressed: () {
  64. if (widget.cancel != null) {
  65. widget.cancel!();
  66. }
  67. },
  68. ),
  69. )
  70. ],
  71. ),
  72. );
  73. }
  74. }
  75. class OkCancelDialog extends StatelessWidget {
  76. final VoidCallback? onOkPressed;
  77. final VoidCallback? onCancelPressed;
  78. final String? okTitle;
  79. final String? cancelTitle;
  80. final String? title;
  81. final String message;
  82. final double? maxWidth;
  83. const OkCancelDialog(
  84. {Key? key,
  85. this.onOkPressed,
  86. this.onCancelPressed,
  87. this.okTitle,
  88. this.cancelTitle,
  89. this.title,
  90. required this.message,
  91. this.maxWidth})
  92. : super(key: key);
  93. @override
  94. Widget build(BuildContext context) {
  95. final theme = context.watch<AppTheme>();
  96. return StyledDialog(
  97. maxWidth: maxWidth ?? 500,
  98. child: Column(
  99. crossAxisAlignment: CrossAxisAlignment.start,
  100. children: <Widget>[
  101. if (title != null) ...[
  102. Text(title!.toUpperCase(), style: TextStyles.T1.textColor(theme.shader1)),
  103. VSpace(Insets.sm * 1.5),
  104. Container(color: theme.bg1, height: 1),
  105. VSpace(Insets.m * 1.5),
  106. ],
  107. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  108. SizedBox(height: Insets.l),
  109. OkCancelButton(
  110. onOkPressed: onOkPressed,
  111. onCancelPressed: onCancelPressed,
  112. okTitle: okTitle?.toUpperCase(),
  113. cancelTitle: cancelTitle?.toUpperCase(),
  114. )
  115. ],
  116. ),
  117. );
  118. }
  119. }
  120. class OkCancelButton extends StatelessWidget {
  121. final VoidCallback? onOkPressed;
  122. final VoidCallback? onCancelPressed;
  123. final String? okTitle;
  124. final String? cancelTitle;
  125. final double? minHeight;
  126. const OkCancelButton(
  127. {Key? key, this.onOkPressed, this.onCancelPressed, this.okTitle, this.cancelTitle, this.minHeight})
  128. : super(key: key);
  129. @override
  130. Widget build(BuildContext context) {
  131. return Row(
  132. mainAxisAlignment: MainAxisAlignment.end,
  133. children: <Widget>[
  134. if (onCancelPressed != null)
  135. SecondaryTextButton(
  136. cancelTitle ?? S.BTN_CANCEL,
  137. onPressed: () {
  138. onCancelPressed!();
  139. AppGlobals.nav.pop();
  140. },
  141. bigMode: true,
  142. ),
  143. HSpace(Insets.m),
  144. if (onOkPressed != null)
  145. PrimaryTextButton(
  146. okTitle ?? S.BTN_OK,
  147. onPressed: () {
  148. onOkPressed!();
  149. AppGlobals.nav.pop();
  150. },
  151. bigMode: true,
  152. ),
  153. ],
  154. );
  155. }
  156. }