From 48fa4f4f4b94c4ca2747c680dfe0c91691fdc821 Mon Sep 17 00:00:00 2001 From: hkaikai <617760820@qq.com> Date: Tue, 17 Dec 2024 11:03:00 +0800 Subject: [PATCH] =?UTF-8?q?TDDropdownMenu=20=E6=96=B0=E5=A2=9E=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=A3=85=E9=A5=B0=E5=99=A8=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=9Adecoration=EF=BC=8C=E5=8F=AF=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=8F=9C=E5=8D=95=E9=A2=9C=E8=89=B2=E5=92=8C=E8=BE=B9?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dropdown_menu/td_dropdown_menu.dart | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_menu.dart b/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_menu.dart index 037cb4ba8..8348228f5 100644 --- a/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_menu.dart +++ b/tdesign-component/lib/src/components/dropdown_menu/td_dropdown_menu.dart @@ -2,12 +2,12 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import './td_dropdown_item.dart'; import '../../theme/td_colors.dart'; import '../../theme/td_fonts.dart'; import '../../theme/td_theme.dart'; import '../icon/td_icons.dart'; import '../text/td_text.dart'; +import './td_dropdown_item.dart'; import 'td_dropdown_popup.dart'; /// 菜单展开方向 @@ -46,6 +46,7 @@ class TDDropdownMenu extends StatefulWidget { this.width, this.height = 48, this.tabBarAlign = MainAxisAlignment.center, + this.decoration, }) : super(key: key); /// 下拉菜单构建器,优先级高于[items] @@ -79,7 +80,7 @@ class TDDropdownMenu extends StatefulWidget { final ValueChanged? onMenuClosed; /// 是否开启滚动列表 - final bool isScrollable; + final bool? isScrollable; /// menu的宽度 final double? width; @@ -90,6 +91,9 @@ class TDDropdownMenu extends StatefulWidget { /// [TDDropdownItem.label]和[arrowIcon]/[TDDropdownItem.arrowIcon]的对齐方式 final MainAxisAlignment? tabBarAlign; + /// 下拉菜单的装饰器 + final Decoration? decoration; + @override _TDDropdownMenuState createState() => _TDDropdownMenuState(); } @@ -125,44 +129,44 @@ class _TDDropdownMenuState extends State with TickerProviderStat @override Widget build(BuildContext context) { - Widget tabBar = Row( - children: List.generate( - _items?.length ?? 0, - (index) { - return Expanded( - flex: _items![index].tabBarFlex ?? 1, - child: _tabBarContent(index), - ); - }, - ), - ); - if (widget.isScrollable) { - tabBar = SingleChildScrollView( - scrollDirection: Axis.horizontal, - physics: const BouncingScrollPhysics(), - child: Row( - children: List.generate( - _items?.length ?? 0, - (index) => SizedBox( - width: _items![index].tabBarWidth, - child: _tabBarContent(index), + var tabBar = widget.isScrollable == true + ? SingleChildScrollView( + scrollDirection: Axis.horizontal, + physics: const BouncingScrollPhysics(), + child: Row( + children: List.generate( + _items?.length ?? 0, + (index) => SizedBox( + width: _items![index].tabBarWidth, + child: _tabBarContent(index), + ), + ), ), - ), - ), - ); - } + ) + : Row( + children: List.generate( + _items?.length ?? 0, + (index) { + return Expanded( + flex: _items![index].tabBarFlex ?? 1, + child: _tabBarContent(index), + ); + }, + ), + ); return Container( height: widget.height, width: widget.width ?? double.infinity, - decoration: BoxDecoration( - color: TDTheme.of(context).whiteColor1, - border: Border( - bottom: BorderSide( - color: TDTheme.of(context).grayColor3, - width: 1, + decoration: widget.decoration ?? + BoxDecoration( + color: TDTheme.of(context).whiteColor1, + border: Border( + bottom: BorderSide( + color: TDTheme.of(context).grayColor3, + width: 1, + ), + ), ), - ), - ), child: tabBar, ); }