Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TDInput]修复设置contentPadding分割线与内容不对齐 #365

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion tdesign-component/example/lib/page/td_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class _TDInputViewPageState extends State<TDInputViewPage> {
ExampleItem(desc: '长文本样式', builder: _customLongTextStyle),
ExampleItem(desc: '隐藏底部分割线', builder: _hideBottomDivider),
ExampleItem(desc: '自定义高度-使用SizeBox', builder: _customHeight),
ExampleItem(desc: '获取焦点时点击外部区域事件响应-onTapOutside', builder: _onTapOutside)
ExampleItem(desc: '获取焦点时点击外部区域事件响应-onTapOutside', builder: _onTapOutside),
ExampleItem(desc: '设置contentPadding内容与分割线对齐', builder: _contentPadding)
],
);
}
Expand Down Expand Up @@ -927,4 +928,40 @@ class _TDInputViewPageState extends State<TDInputViewPage> {
),
);
}

@Demo(group: 'input')
Widget _contentPadding(BuildContext context) {
var controller = TextEditingController();
return Container(
color: Colors.yellow,
alignment: Alignment.center,
child: Column(
children: [
TDInput(
size: TDInputSize.small,
controller: controller,
backgroundColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
hintText: '请输入文字',
),
TDInput(
type: TDInputType.twoLine,
size: TDInputSize.small,
controller: controller,
backgroundColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 50),
hintText: '请输入文字',
),
TDInput(
type: TDInputType.normalMaxTwoLine,
size: TDInputSize.small,
controller: controller,
backgroundColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 70),
hintText: '请输入文字',
),
],
),
);
}
}
37 changes: 27 additions & 10 deletions tdesign-component/lib/src/components/input/td_input.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -271,6 +269,25 @@ class TDInput extends StatelessWidget {
}
}

double _getBottomDividerMarginLeft() {
switch (type) {
case TDInputType.normal:
case TDInputType.twoLine:
case TDInputType.normalMaxTwoLine:
case TDInputType.cardStyle:
if (contentPadding != null && contentPadding is EdgeInsets) {
return (contentPadding as EdgeInsets).left;
}
return spacer.labelInputSpace ?? 16;
case TDInputType.special:
case TDInputType.longText:
if (contentPadding != null && contentPadding is EdgeInsets) {
return (contentPadding as EdgeInsets).left;
}
return 16;
}
}

Widget buildNormalInput(BuildContext context) {
var cardStyleDecoration = _getCardStylePreDecoration(context);
var hasLeftWidget = leftLabel != null || leftIcon != null || (required ?? false);
Expand Down Expand Up @@ -431,9 +448,9 @@ class TDInput extends StatelessWidget {
if (showBottomDivider)
Visibility(
visible: type != TDInputType.cardStyle,
child: const TDDivider(
child: TDDivider(
margin: EdgeInsets.only(
left: 16,
left: _getBottomDividerMarginLeft(),
),
),
),
Expand Down Expand Up @@ -599,9 +616,9 @@ class TDInput extends StatelessWidget {
],
),
if (showBottomDivider)
const TDDivider(
TDDivider(
margin: EdgeInsets.only(
left: 16,
left: _getBottomDividerMarginLeft(),
),
),
],
Expand Down Expand Up @@ -631,9 +648,9 @@ class TDInput extends StatelessWidget {
fontWeight: FontWeight.w400,
)),
if (showBottomDivider)
const TDDivider(
TDDivider(
margin: EdgeInsets.only(
left: 16,
left: _getBottomDividerMarginLeft(),
),
),
],
Expand Down Expand Up @@ -758,10 +775,10 @@ class TDInput extends StatelessWidget {
),
),
if (showBottomDivider)
const Visibility(
Visibility(
child: TDDivider(
margin: EdgeInsets.only(
left: 16,
left: _getBottomDividerMarginLeft(),
),
),
),
Expand Down
Loading