From d93e78253626698087bfacc590fccd5e3bbf81f5 Mon Sep 17 00:00:00 2001 From: hkaikai <617760820@qq.com> Date: Thu, 9 Jan 2025 12:06:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E6=83=85=E5=86=B5=E4=B8=8B=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E5=8C=BA=E5=9F=9F=E6=97=A0=E5=8F=8D=E5=BA=94?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9BTDCellStyle=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=9E=84=E9=80=A0=E6=96=B9=E6=B3=95=E6=8F=90=E4=BE=9Bcontext?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=A0=B7=E5=BC=8F=EF=BC=9B=E5=AE=8C=E5=96=84?= =?UTF-8?q?demo=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F=E7=94=A8?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/lib/page/td_cell_page.dart | 38 ++++++++++++++----- .../lib/src/components/cell/td_cell.dart | 1 + .../src/components/cell/td_cell_style.dart | 14 ++++++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/tdesign-component/example/lib/page/td_cell_page.dart b/tdesign-component/example/lib/page/td_cell_page.dart index b6c3ad52a..4fd7096b5 100644 --- a/tdesign-component/example/lib/page/td_cell_page.dart +++ b/tdesign-component/example/lib/page/td_cell_page.dart @@ -60,15 +60,26 @@ class TDCellPage extends StatelessWidget { @Demo(group: 'cell') Widget _buildSimple(BuildContext context) { - return const TDCellGroup( + // 可统一修改样式 + var style = TDCellStyle(context: context); + return TDCellGroup( + style: style, cells: [ - TDCell(arrow: true, title: '单行标题'), - TDCell(arrow: true, title: '单行标题', required: true), - TDCell(arrow: true, title: '单行标题', noteWidget: TDBadge(TDBadgeType.message, count: '8')), - TDCell(arrow: false, title: '单行标题', rightIconWidget: TDSwitch(isOn: true)), - TDCell(arrow: true, title: '单行标题', note: '辅助信息'), - TDCell(arrow: true, title: '单行标题', leftIcon: TDIcons.lock_on), - TDCell(arrow: false, title: '单行标题'), + // 可单独修改样式 + TDCell(arrow: true, title: '单行标题', style: TDCellStyle.cellStyle(context)), + TDCell( + arrow: true, + title: '单行标题', + required: true, + onClick: (cell) { + print('单行标题'); + }, + ), + const TDCell(arrow: true, title: '单行标题', noteWidget: TDBadge(TDBadgeType.message, count: '8')), + const TDCell(arrow: false, title: '单行标题', rightIconWidget: TDSwitch(isOn: true)), + const TDCell(arrow: true, title: '单行标题', note: '辅助信息'), + const TDCell(arrow: true, title: '单行标题', leftIcon: TDIcons.lock_on), + const TDCell(arrow: false, title: '单行标题'), ], ); } @@ -118,12 +129,19 @@ Widget _buildCard(BuildContext context) { @Demo(group: 'cell') Widget _buildPadding(BuildContext context) { - var style = TDCellStyle.cellStyle(context); + var style = TDCellStyle(context: context); style.padding = const EdgeInsets.all(30); return TDCellGroup( theme: TDCellGroupTheme.cardTheme, cells: [ - TDCell(arrow: true, title: 'padding-all-30', style: style,), + TDCell( + arrow: true, + title: 'padding-all-30', + style: style, + onClick: (cell) { + print('padding-all-30'); + }, + ), ], ); } diff --git a/tdesign-component/lib/src/components/cell/td_cell.dart b/tdesign-component/lib/src/components/cell/td_cell.dart index 916a2bd01..ebb692499 100644 --- a/tdesign-component/lib/src/components/cell/td_cell.dart +++ b/tdesign-component/lib/src/components/cell/td_cell.dart @@ -122,6 +122,7 @@ class _TDCellState extends State { var style = widget.style ?? TDCellInherited.of(context)?.style ?? TDCellStyle.cellStyle(context); var crossAxisAlignment = _getAlign(); return GestureDetector( + behavior: HitTestBehavior.opaque, onTap: () { if (widget.onClick != null && !(widget.disabled ?? false)) { widget.onClick!(widget); diff --git a/tdesign-component/lib/src/components/cell/td_cell_style.dart b/tdesign-component/lib/src/components/cell/td_cell_style.dart index 94919cc2e..85b1ab8ed 100644 --- a/tdesign-component/lib/src/components/cell/td_cell_style.dart +++ b/tdesign-component/lib/src/components/cell/td_cell_style.dart @@ -5,6 +5,7 @@ import '../../../tdesign_flutter.dart'; /// 单元格组件样式 class TDCellStyle { TDCellStyle({ + this.context, this.leftIconColor, this.rightIconColor, this.titleStyle, @@ -21,7 +22,14 @@ class TDCellStyle { this.cardBorderRadius, this.cardPadding, this.titlePadding, - }); + }) { + if (context != null) { + defaultStyle(context!); + } + } + + /// 传递context,会生成默认样式 + BuildContext? context; /// 左侧图标颜色 Color? leftIconColor; @@ -73,6 +81,10 @@ class TDCellStyle { /// 生成单元格默认样式 TDCellStyle.cellStyle(BuildContext context) { + defaultStyle(context); + } + + defaultStyle(BuildContext context) { backgroundColor = Colors.white; clickBackgroundColor = TDTheme.of(context).grayColor1; leftIconColor = TDTheme.of(context).brandColor7;