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

Add DropdownMenu width and custom background enable. #45

Open
wants to merge 1 commit into
base: master
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
29 changes: 19 additions & 10 deletions example/lib/gzx_dropdown_menu_test_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class _GZXDropDownMenuTestPageState extends State<GZXDropDownMenuTestPage> {
print(_dropdownMenuChange);
});
},
// margin: EdgeInsets.symmetric(horizontal: 16),
// 下拉菜单,高度自定义,你想显示什么就显示什么,完全由你决定,你只需要在选择后调用_dropdownMenuController.hide();即可
menus: [
GZXDropdownMenuBuilder(
Expand Down Expand Up @@ -351,16 +352,24 @@ class _GZXDropDownMenuTestPageState extends State<GZXDropDownMenuTestPage> {
}

_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);
},
),
);
}

Expand Down
28 changes: 17 additions & 11 deletions lib/src/gzx_dropdown_menu.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'dart:ui' as ui;

import 'gzx_dropdown_menu_controller.dart';

Expand All @@ -24,6 +25,7 @@ class GZXDropDownMenu extends StatefulWidget {
final List<GZXDropdownMenuBuilder> menus;
final int animationMilliseconds;
final Color maskColor;
final EdgeInsets margin;

/// Called when dropdown menu start showing or hiding.
final DropdownMenuChange? dropdownMenuChanging;
Expand All @@ -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
Expand All @@ -61,10 +64,12 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu>

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(
Expand Down Expand Up @@ -171,10 +176,9 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu>
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 {
Expand All @@ -191,19 +195,21 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu>
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: <Widget>[
_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(),
],
));
}
Expand Down