123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- * @Author: XianKaiQun
- * @Date: 2020-08-25 14:53:57
- * @LastEditors: XianKaiQun
- * @LastEditTime: 2020-09-09 11:27:16
- * @Description:
- */
- import 'package:flutter/material.dart';
- import 'package:wisdom_cli/wisdom_cli.dart';
- ///表单的结构样式构造
- class WFormTile extends StatelessWidget {
- const WFormTile({
- Key? key,
- this.child,
- this.leading,
- this.direction = Axis.horizontal,
- this.required = false,
- this.minWidth,
- }) : super(key: key);
- final Widget? child;
- final Widget? leading;
- final double? minWidth;
- ///布局方向,
- ///[Axis.horizontal][leading]在左,
- ///[Axis.vertical][leading]在上,
- final Axis direction;
- ///显示必填的星星
- final bool required;
- @override
- Widget build(BuildContext context) {
- Widget _leading = DefaultTextStyle(
- style: DefaultTextStyle.of(context).style.copyWith(fontSize: 15.pt),
- child: Wisdom.rich(
- textAlign: TextAlign.start,
- children: [
- if (required) ...[
- WidgetSpan(
- child: SizedBox(
- width: 10.pt,
- child: Text(
- '*',
- style: TextStyle(
- color: Color(0XFFFF495E),
- ),
- ),
- ),
- ),
- ],
- if (leading != null)
- WidgetSpan(
- child: leading!,
- ),
- ],
- ),
- );
- if (direction == Axis.horizontal) {
- _leading = ConstrainedBox(
- constraints: BoxConstraints(
- minWidth: minWidth ?? 85.pt,
- ),
- child: _leading,
- );
- }
- Widget? _child = child;
- if (_child != null) {
- _child = DefaultTextStyle(
- style: DefaultTextStyle.of(context).style.copyWith(
- fontSize: 15.pt,
- ),
- child: _child,
- );
- if (direction == Axis.horizontal) {
- _child = Expanded(
- child: _child,
- );
- }
- }
- return ConstrainedBox(
- constraints: BoxConstraints(minHeight: 45.pt),
- child: direction == Axis.vertical
- ? Wisdom.column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(height: 15.pt),
- _leading,
- if (_child != null) _child,
- SizedBox(height: 10.pt),
- ],
- )
- : Wisdom.row(
- // margin: EdgeInsets.only(bottom: 10.pt),
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- _leading,
- if (_child != null) _child,
- ],
- ),
- );
- }
- }
|