bottom_modal.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * @Author : WuWei
  3. * @LastEditors : WuWei
  4. * @Date : 2022-11-02 10:26:39
  5. * @LastEditTime : 2023-10-26 19:18:54
  6. * @Description : Do not edit
  7. */
  8. import 'package:flutter/material.dart';
  9. import 'package:wisdom_cli/src/assets.gen.dart';
  10. import 'package:wisdom_cli/wisdom_cli.dart';
  11. ///弹出层构造Widget
  12. class WBottomModal extends StatelessWidget {
  13. WBottomModal({
  14. Key? key,
  15. this.plain = true,
  16. this.bodyConstraints = const BoxConstraints(
  17. maxHeight: 500,
  18. minHeight: 400,
  19. ),
  20. this.confirmText = '确定',
  21. this.cancelText = '取消',
  22. this.title,
  23. this.onConfirm,
  24. this.onCancel,
  25. this.body,
  26. }) : super(key: key);
  27. final bool plain;
  28. final BoxConstraints bodyConstraints;
  29. final String? confirmText;
  30. final String? cancelText;
  31. final Widget? title;
  32. final void Function(BuildContext)? onConfirm;
  33. final void Function(BuildContext)? onCancel;
  34. final Widget? body;
  35. @override
  36. Widget build(BuildContext context) {
  37. final colorScheme = WTheme.of(context).colorScheme;
  38. return Container(
  39. decoration: BoxDecoration(
  40. color: Colors.white,
  41. borderRadius: BorderRadius.only(
  42. topLeft: Radius.circular(20.pt),
  43. topRight: Radius.circular(20.pt),
  44. ),
  45. ),
  46. child: SafeArea(
  47. child: Column(
  48. mainAxisSize: MainAxisSize.min,
  49. crossAxisAlignment: CrossAxisAlignment.stretch,
  50. children: <Widget>[
  51. Wisdom.row(
  52. minHeight: 54.pt,
  53. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  54. children: <Widget>[
  55. if (onCancel != null) ...[
  56. Wisdom(
  57. width: 100.pt,
  58. alignment: Alignment.centerLeft,
  59. child: !plain
  60. ? TextButton(
  61. style: TextButton.styleFrom(
  62. foregroundColor: Theme.of(context).hintColor,
  63. ),
  64. child: WisText(cancelText ?? ''),
  65. // textColor:
  66. onPressed: () => onCancel!(context),
  67. ).asPaddingOnly(right: 20.pt)
  68. : null,
  69. ),
  70. ] else ...[
  71. SizedBox(
  72. width: 100.pt,
  73. ),
  74. ],
  75. DefaultTextStyle(
  76. maxLines: 1,
  77. // textAlign: onCancel != null ? TextAlign.center : TextAlign.left,
  78. textAlign: TextAlign.center,
  79. style: DefaultTextStyle.of(context).style.copyWith(
  80. fontWeight: FontWeight.bold,
  81. fontSize: 16.pt,
  82. ),
  83. child: Wisdom(
  84. padding: EdgeInsets.symmetric(horizontal: 15.pt),
  85. child: title,
  86. ).asExpanded(),
  87. ),
  88. Wisdom(
  89. width: 100.pt,
  90. alignment: Alignment.centerRight,
  91. child: !plain
  92. ? TextButton(
  93. child: WisText(
  94. confirmText ?? '',
  95. color: colorScheme.primary,
  96. ),
  97. onPressed: onConfirm != null
  98. ? () => onConfirm!(context)
  99. : null,
  100. ).asPaddingOnly(left: 20.pt)
  101. : Wisdom(
  102. onTap: () => {
  103. Navigator.pop(context),
  104. onCancel != null ? () => onCancel!(context) : null,
  105. },
  106. padding: EdgeInsets.only(right: 15.pt),
  107. child: Image(
  108. image: AssetList.$guanbi_png_image,
  109. height: 14.pt,
  110. width: 14.pt,
  111. ),
  112. ),
  113. ),
  114. ],
  115. ),
  116. Container(
  117. height: MediaQuery.of(context).size.height * 0.62,
  118. child: body,
  119. ),
  120. ],
  121. ),
  122. ),
  123. );
  124. }
  125. }