diff --git a/example/lib/gzx_dropdown_menu_test_page.dart b/example/lib/gzx_dropdown_menu_test_page.dart index 50d7ae9..a654443 100644 --- a/example/lib/gzx_dropdown_menu_test_page.dart +++ b/example/lib/gzx_dropdown_menu_test_page.dart @@ -205,6 +205,7 @@ class _GZXDropDownMenuTestPageState extends State { print(_dropdownMenuChange); }); }, + // margin: EdgeInsets.symmetric(horizontal: 16), // 下拉菜单,高度自定义,你想显示什么就显示什么,完全由你决定,你只需要在选择后调用_dropdownMenuController.hide();即可 menus: [ GZXDropdownMenuBuilder( @@ -351,16 +352,24 @@ class _GZXDropDownMenuTestPageState extends State { } _buildConditionListWidget(items, void itemOnTap(SortCondition sortCondition)) { - return ListView.separated( - shrinkWrap: true, - scrollDirection: Axis.vertical, - itemCount: items.length, - // item 的个数 - separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0), - // 添加分割线 - itemBuilder: (BuildContext context, int index) { - return gestureDetector(items, index, itemOnTap, context); - }, + return Container( + // color: Colors.white, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only(bottomLeft: Radius.circular(6), bottomRight: Radius.circular(6)), + border: Border.all(width: 0, color: Colors.white), + ), + child: ListView.separated( + shrinkWrap: true, + scrollDirection: Axis.vertical, + itemCount: items.length, + // item 的个数 + separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0), + // 添加分割线 + itemBuilder: (BuildContext context, int index) { + return gestureDetector(items, index, itemOnTap, context); + }, + ), ); } diff --git a/lib/src/gzx_dropdown_menu.dart b/lib/src/gzx_dropdown_menu.dart index 267f242..2dbe2e1 100644 --- a/lib/src/gzx_dropdown_menu.dart +++ b/lib/src/gzx_dropdown_menu.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'dart:ui' as ui; import 'gzx_dropdown_menu_controller.dart'; @@ -24,6 +25,7 @@ class GZXDropDownMenu extends StatefulWidget { final List menus; final int animationMilliseconds; final Color maskColor; + final EdgeInsets margin; /// Called when dropdown menu start showing or hiding. final DropdownMenuChange? dropdownMenuChanging; @@ -41,6 +43,7 @@ class GZXDropDownMenu extends StatefulWidget { this.maskColor = const Color.fromRGBO(0, 0, 0, 0.5), this.dropdownMenuChanging, this.dropdownMenuChanged, + this.margin = EdgeInsets.zero, }) : super(key: key); @override @@ -61,10 +64,12 @@ class _GZXDropDownMenuState extends State int? _currentMenuIndex; + late MediaQueryData _mediaQueryData; + @override void initState() { - // TODO: implement initState super.initState(); + _mediaQueryData = MediaQueryData.fromWindow(ui.window); widget.controller.addListener(_onController); _controller = new AnimationController( @@ -171,10 +176,9 @@ class _GZXDropDownMenuState extends State widget.controller.hide(); }, child: Container( - width: double.infinity, - height: MediaQuery.of(context).size.height, + width: _mediaQueryData.size.width - widget.margin.left - widget.margin.right, + height: _mediaQueryData.size.height, color: widget.maskColor.withOpacity(_maskColorOpacity), -// color: widget.maskColor, ), ); } else { @@ -191,19 +195,21 @@ class _GZXDropDownMenuState extends State return Container(); } + double left = widget.margin.left; + double top = widget.margin.top; + double right = widget.margin.right; + return Positioned( - top: widget.controller.dropDownMenuTop, - left: 0, - right: 0, - child: Column( + left: left, + top: widget.controller.dropDownMenuTop ?? 0 + top, + child: Stack( children: [ + _mask(), Container( - color: Colors.white, - width: double.infinity, + width: _mediaQueryData.size.width - left - right, height: _animation == null ? 0 : _animation!.value, child: widget.menus[menuIndex].dropDownWidget, ), - _mask(), ], )); }