dialogs.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. textStyle: const TextStyle(fontSize: 24, fontWeight: FontWeight.w400),
  52. autoFocus: true,
  53. onChanged: (text) {
  54. newValue = text;
  55. },
  56. ),
  57. const VSpace(10),
  58. OkCancelButton(
  59. onOkPressed: () {
  60. widget.confirm(newValue);
  61. },
  62. onCancelPressed: () {
  63. if (widget.cancel != null) {
  64. widget.cancel!();
  65. }
  66. },
  67. )
  68. ],
  69. ),
  70. );
  71. }
  72. }
  73. class OkCancelDialog extends StatelessWidget {
  74. final VoidCallback? onOkPressed;
  75. final VoidCallback? onCancelPressed;
  76. final String? okTitle;
  77. final String? cancelTitle;
  78. final String? title;
  79. final String message;
  80. final double? maxWidth;
  81. const OkCancelDialog(
  82. {Key? key,
  83. this.onOkPressed,
  84. this.onCancelPressed,
  85. this.okTitle,
  86. this.cancelTitle,
  87. this.title,
  88. required this.message,
  89. this.maxWidth})
  90. : super(key: key);
  91. @override
  92. Widget build(BuildContext context) {
  93. final theme = context.watch<AppTheme>();
  94. return StyledDialog(
  95. maxWidth: maxWidth ?? 500,
  96. child: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: <Widget>[
  99. if (title != null) ...[
  100. Text(title!.toUpperCase(), style: TextStyles.T1.textColor(theme.shader1)),
  101. VSpace(Insets.sm * 1.5),
  102. Container(color: theme.bg1, height: 1),
  103. VSpace(Insets.m * 1.5),
  104. ],
  105. Text(message, style: TextStyles.Body1.textHeight(1.5)),
  106. SizedBox(height: Insets.l),
  107. OkCancelButton(
  108. onOkPressed: onOkPressed,
  109. onCancelPressed: onCancelPressed,
  110. okTitle: okTitle?.toUpperCase(),
  111. cancelTitle: cancelTitle?.toUpperCase(),
  112. )
  113. ],
  114. ),
  115. );
  116. }
  117. }
  118. class OkCancelButton extends StatelessWidget {
  119. final VoidCallback? onOkPressed;
  120. final VoidCallback? onCancelPressed;
  121. final String? okTitle;
  122. final String? cancelTitle;
  123. final double? minHeight;
  124. const OkCancelButton(
  125. {Key? key, this.onOkPressed, this.onCancelPressed, this.okTitle, this.cancelTitle, this.minHeight})
  126. : super(key: key);
  127. @override
  128. Widget build(BuildContext context) {
  129. return SizedBox(
  130. height: 48,
  131. child: 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. }
  157. }