From 2ca1997739e1cc55db8e7acd01596d98a7dcc2af Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Fri, 27 Aug 2021 10:26:40 +0800 Subject: [PATCH] adapt as option tile --- lib/list_tile/as_option_tile.dart | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/list_tile/as_option_tile.dart b/lib/list_tile/as_option_tile.dart index 5b00f68..b742d45 100644 --- a/lib/list_tile/as_option_tile.dart +++ b/lib/list_tile/as_option_tile.dart @@ -1,7 +1,8 @@ +import 'package:ansu_ui/divider/as_divider.dart'; +import 'package:ansu_ui/extension/list_extension.dart'; +import 'package:ansu_ui/styles/as_colors.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:ansu_ui/styles/as_colors.dart'; -import 'package:ansu_ui/divider/as_divider.dart'; ///菜单按钮Tile class ASOptionTile extends StatelessWidget { @@ -27,6 +28,7 @@ class ASOptionTile extends StatelessWidget { {Key? key, required this.item, this.padding, this.leading}) : items = [], super(key: key); + int get length => items!.length; @override @@ -38,15 +40,16 @@ class ASOptionTile extends StatelessWidget { alignment: Alignment.centerLeft, child: this.leading is String ? Padding( - padding:EdgeInsets.symmetric(vertical: 14.w,horizontal: 10.w), - child: Text( + padding: EdgeInsets.symmetric( + vertical: 14.w, horizontal: 10.w), + child: Text( this.leading, style: TextStyle( color: kTextColor, fontSize: 16.sp, fontWeight: FontWeight.bold), ), - ) + ) : this.leading, ), ); @@ -62,15 +65,13 @@ class ASOptionTile extends StatelessWidget { child: item ?? Column( crossAxisAlignment: CrossAxisAlignment.start, - children: List.generate(length * 2 - 1, (index) { - final displayIndex = index ~/ 2; - if (index.isEven) - return items![displayIndex]; - else - return this.padding == null - ? ASDivider(indent: 10.w, endIndent: 10.w) - : ASDivider(); - }), + children: items!.sepWidget( + separate: this.padding == null + ? ASDivider( + indent: 10.w, + endIndent: 10.w, + ) + : ASDivider()), ), )); }