Skip to content

Commit

Permalink
优化 TDFormItem type 枚举值 API
Browse files Browse the repository at this point in the history
添加 TDRate 进入表单组件
  • Loading branch information
SimonWuZY committed Oct 22, 2024
1 parent c2e918a commit a332743
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
4 changes: 4 additions & 0 deletions tdesign-component/example/lib/page/td_form_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ class _TDFormPageState extends State<TDFormPage> {

/// 为 TDStepper 预留其他设置
),
TDFormItem(
label: '自我评价',
type: TDFormItemType.rate,
),
TDFormItem(
label: '个人简介',
type: TDFormItemType.textarea,
Expand Down
46 changes: 40 additions & 6 deletions tdesign-component/lib/src/components/form/td_form_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ enum TDFormItemType {
dateTimePicker,
cascader,
stepper,
textarea
rate,
textarea,
}

class _TDFormItemState extends State<TDFormItem> {
Expand Down Expand Up @@ -278,6 +279,14 @@ class _TDFormItemState extends State<TDFormItem> {
),
),
);
case TDFormItemType.rate:
return TDCell(
title: widget.label,
noteWidget: TDRate(
value: 3,
allowHalf: true,
disabled: FormState,
));
case TDFormItemType.textarea:
return TDTextarea(
backgroundColor: Colors.red,
Expand All @@ -296,8 +305,10 @@ class _TDFormItemState extends State<TDFormItem> {
switch (widget.type) {
case TDFormItemType.input:
return TDInput(
spacer: TDInputSpacer(iconLabelSpace: 0),
type: TDInputType.twoLine,
inputDecoration: InputDecoration(
contentPadding: EdgeInsets.only(left: LabelWidth),
hintText: widget.help,
border: InputBorder.none,
),
Expand All @@ -306,7 +317,7 @@ class _TDFormItemState extends State<TDFormItem> {
backgroundColor: Colors.white,

/// 竖直态的 TDInput 没用 additionInfo?
additionInfo: widget.additionInfo,
// additionInfo: widget.additionInfo,
readOnly: FormState,
);
case TDFormItemType.password:
Expand All @@ -315,7 +326,7 @@ class _TDFormItemState extends State<TDFormItem> {
TDInput(
inputDecoration: InputDecoration(
hintText: widget.help,
// contentPadding: EdgeInsets.only(left: LabelWidth),
contentPadding: EdgeInsets.only(left: LabelWidth),
border: InputBorder.none,
),
type: TDInputType.twoLine,
Expand Down Expand Up @@ -417,15 +428,14 @@ class _TDFormItemState extends State<TDFormItem> {
child: _buildSelectRow(context, _selected_1, '选择地区'),
);
case TDFormItemType.stepper:
final theme = TDTheme.of(context);
return Container(
decoration: BoxDecoration(
color: theme.whiteColor1,
color: TDTheme.of(context).whiteColor1,
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // 使内容左对齐
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TDText(
widget.label,
Expand All @@ -440,6 +450,30 @@ class _TDFormItemState extends State<TDFormItem> {
),
),
);
case TDFormItemType.rate:
return Container(
width: double.infinity, // 设置宽度为无限,横向占满父容器
decoration: BoxDecoration(
color: TDTheme.of(context).whiteColor1,
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TDText(
widget.label,
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
TDRate(
value: 3,
allowHalf: true,
disabled: FormState,
),
],
),
));
case TDFormItemType.textarea:
return TDTextarea(
backgroundColor: Colors.red,
Expand Down

0 comments on commit a332743

Please sign in to comment.