form_tile.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * @Author: XianKaiQun
  3. * @Date: 2020-08-25 14:53:57
  4. * @LastEditors: XianKaiQun
  5. * @LastEditTime: 2020-09-09 11:27:16
  6. * @Description:
  7. */
  8. import 'package:flutter/material.dart';
  9. import 'package:wisdom_cli/wisdom_cli.dart';
  10. ///表单的结构样式构造
  11. class WFormTile extends StatelessWidget {
  12. const WFormTile({
  13. Key? key,
  14. this.child,
  15. this.leading,
  16. this.direction = Axis.horizontal,
  17. this.required = false,
  18. this.minWidth,
  19. }) : super(key: key);
  20. final Widget? child;
  21. final Widget? leading;
  22. final double? minWidth;
  23. ///布局方向,
  24. ///[Axis.horizontal][leading]在左,
  25. ///[Axis.vertical][leading]在上,
  26. final Axis direction;
  27. ///显示必填的星星
  28. final bool required;
  29. @override
  30. Widget build(BuildContext context) {
  31. Widget _leading = DefaultTextStyle(
  32. style: DefaultTextStyle.of(context).style.copyWith(fontSize: 15.pt),
  33. child: Wisdom.rich(
  34. textAlign: TextAlign.start,
  35. children: [
  36. if (required) ...[
  37. WidgetSpan(
  38. child: SizedBox(
  39. width: 10.pt,
  40. child: Text(
  41. '*',
  42. style: TextStyle(
  43. color: Color(0XFFFF495E),
  44. ),
  45. ),
  46. ),
  47. ),
  48. ],
  49. if (leading != null)
  50. WidgetSpan(
  51. child: leading!,
  52. ),
  53. ],
  54. ),
  55. );
  56. if (direction == Axis.horizontal) {
  57. _leading = ConstrainedBox(
  58. constraints: BoxConstraints(
  59. minWidth: minWidth ?? 85.pt,
  60. ),
  61. child: _leading,
  62. );
  63. }
  64. Widget? _child = child;
  65. if (_child != null) {
  66. _child = DefaultTextStyle(
  67. style: DefaultTextStyle.of(context).style.copyWith(
  68. fontSize: 15.pt,
  69. ),
  70. child: _child,
  71. );
  72. if (direction == Axis.horizontal) {
  73. _child = Expanded(
  74. child: _child,
  75. );
  76. }
  77. }
  78. return ConstrainedBox(
  79. constraints: BoxConstraints(minHeight: 45.pt),
  80. child: direction == Axis.vertical
  81. ? Wisdom.column(
  82. crossAxisAlignment: CrossAxisAlignment.start,
  83. children: [
  84. SizedBox(height: 15.pt),
  85. _leading,
  86. if (_child != null) _child,
  87. SizedBox(height: 10.pt),
  88. ],
  89. )
  90. : Wisdom.row(
  91. // margin: EdgeInsets.only(bottom: 10.pt),
  92. crossAxisAlignment: CrossAxisAlignment.center,
  93. children: [
  94. _leading,
  95. if (_child != null) _child,
  96. ],
  97. ),
  98. );
  99. }
  100. }