Skip to content

Commit

Permalink
fix width when MenuButton on Expanded widget
Browse files Browse the repository at this point in the history
  • Loading branch information
huextrat committed Jun 16, 2020
1 parent c20f750 commit dbe86ff
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.1 - 2020-06-16

Fix width when MenuButton is on Expanded widget

## 1.2.0+1 - 2020-06-16

MenuButton now display the decoration color everywhere
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A popup menu button widget with handsome design and easy to use.

## Installations

Add `menu_button: ^1.2.0+1` in your `pubspec.yaml` dependencies. And import it:
Add `menu_button: ^1.2.1` in your `pubspec.yaml` dependencies. And import it:

```dart
import 'package:menu_button/menu_button.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.0+1"
version: "1.2.1"
meta:
dependency: transitive
description:
Expand Down
12 changes: 10 additions & 2 deletions lib/menu_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class _MenuButtonState<T> extends State<MenuButton<T>> {
Size labelTextSize;
bool toggledMenu = false;
Widget button;
double buttonWidth;

void _updateLabelTextSize() {
if (widget.label != null) {
Expand Down Expand Up @@ -192,6 +193,7 @@ class _MenuButtonState<T> extends State<MenuButton<T>> {
.toList();
final RenderBox button = context.findRenderObject();
final RenderBox overlay = Overlay.of(context).context.findRenderObject();
buttonWidth = button.size.width;
final RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints(
button.localToGlobal(
Expand Down Expand Up @@ -261,6 +263,7 @@ class _MenuButtonState<T> extends State<MenuButton<T>> {
popupHeight: popupHeight,
crossTheEdge: crossTheEdge,
edgeMargin: edgeMargin,
buttonWidth: buttonWidth
),
);
}
Expand All @@ -276,6 +279,7 @@ class _MenuRoute<T> extends PopupRoute<T> {
final double popupHeight;
final bool crossTheEdge;
final double edgeMargin;
final double buttonWidth;

_MenuRoute({
final this.position,
Expand All @@ -288,6 +292,7 @@ class _MenuRoute<T> extends PopupRoute<T> {
final this.popupHeight,
final this.crossTheEdge,
final this.edgeMargin,
final this.buttonWidth,
});

@override
Expand Down Expand Up @@ -333,6 +338,7 @@ class _MenuRoute<T> extends PopupRoute<T> {
popupHeight: popupHeight,
crossTheEdge: crossTheEdge,
edgeMargin: edgeMargin,
buttonWidth: buttonWidth,
),
);
},
Expand Down Expand Up @@ -371,13 +377,15 @@ class _Menu<T> extends StatefulWidget {
this.popupHeight,
this.edgeMargin,
this.crossTheEdge,
@required this.buttonWidth,
}) : super(key: key);

final _MenuRoute<T> route;
final ScrollPhysics scrollPhysics;
final double popupHeight;
final bool crossTheEdge;
final double edgeMargin;
final double buttonWidth;

@override
__MenuState<T> createState() => __MenuState<T>();
Expand Down Expand Up @@ -431,7 +439,7 @@ class __MenuState<T> extends State<_Menu<T>> {
opacity: opacity.evaluate(widget.route.animation),
child: Container(
key: key,
width: width,
width: width ?? widget.buttonWidth,
height: widget.popupHeight,
decoration: BoxDecoration(
color: widget.route.decoration.color,
Expand All @@ -454,7 +462,7 @@ class __MenuState<T> extends State<_Menu<T>> {
child: IntrinsicWidth(
child: SingleChildScrollView(
physics:
widget.scrollPhysics ?? NeverScrollableScrollPhysics(),
widget.scrollPhysics ?? NeverScrollableScrollPhysics(),
child: ListBody(children: [
_MenuButtonToggledChild(child: widget.route.toggledChild),
Align(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: menu_button
description: A menu button widget to select an item in a dropdown list easily customizable
homepage: https://github.com/huextrat/menu_button
version: 1.2.0+1
version: 1.2.1

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down

0 comments on commit dbe86ff

Please sign in to comment.