Skip to content

Commit

Permalink
Fix submenu position bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
bosskmk committed Oct 14, 2022
1 parent 89d0338 commit bce752d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.1] - 2022. 10. 15

* Fix submenu position bug.

## [2.0.0] - 2022. 10. 13

* Add hover-open mode.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## PlutoMenuBar for flutter - v2.0.0
## PlutoMenuBar for flutter - v2.0.1

PlutoMenuBar is a horizontal menu bar for flutter.

Expand Down Expand Up @@ -264,6 +264,7 @@ enum _RadioItems {
> develop packages that make it easy to develop admin pages or CMS with Flutter.
* [PlutoGrid](https://github.com/bosskmk/pluto_grid)
* [PlutoMenuBar](https://github.com/bosskmk/pluto_menu_bar)
* [PlutoLayout](https://github.com/bosskmk/pluto_layout)

<br>

Expand Down
79 changes: 41 additions & 38 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,44 +187,47 @@ class PlutoMenuBarDemo extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(height: 30),
const Text('Hover-open Menu', style: TextStyle(fontSize: 30)),
const SizedBox(height: 30),
PlutoMenuBar(
mode: PlutoMenuBarMode.hover,
menus: getMenus(context),
),
const SizedBox(height: 30),
PlutoMenuBar(
mode: PlutoMenuBarMode.hover,
backgroundColor: Colors.deepOrange,
activatedColor: Colors.white,
indicatorColor: Colors.deepOrange,
textStyle: const TextStyle(color: Colors.white),
menuIconColor: Colors.white,
moreIconColor: Colors.white,
menus: getMenus(context),
),
const SizedBox(height: 30),
const Text('Tap-open Menu', style: TextStyle(fontSize: 30)),
const SizedBox(height: 30),
PlutoMenuBar(
mode: PlutoMenuBarMode.tap,
menus: getMenus(context),
),
const SizedBox(height: 30),
PlutoMenuBar(
backgroundColor: Colors.deepOrange,
activatedColor: Colors.white,
indicatorColor: Colors.deepOrange,
textStyle: const TextStyle(color: Colors.white),
menuIconColor: Colors.white,
moreIconColor: Colors.white,
menus: getMenus(context),
),
],
return SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 30),
const Text('Hover-open Menu', style: TextStyle(fontSize: 30)),
const Text('Works normally in an environment with a mouse.'),
const SizedBox(height: 30),
PlutoMenuBar(
mode: PlutoMenuBarMode.hover,
menus: getMenus(context),
),
const SizedBox(height: 30),
PlutoMenuBar(
mode: PlutoMenuBarMode.hover,
backgroundColor: Colors.deepOrange,
activatedColor: Colors.white,
indicatorColor: Colors.deepOrange,
textStyle: const TextStyle(color: Colors.white),
menuIconColor: Colors.white,
moreIconColor: Colors.white,
menus: getMenus(context),
),
const SizedBox(height: 30),
const Text('Tap-open Menu', style: TextStyle(fontSize: 30)),
const SizedBox(height: 30),
PlutoMenuBar(
mode: PlutoMenuBarMode.tap,
menus: getMenus(context),
),
const SizedBox(height: 30),
PlutoMenuBar(
backgroundColor: Colors.deepOrange,
activatedColor: Colors.white,
indicatorColor: Colors.deepOrange,
textStyle: const TextStyle(color: Colors.white),
menuIconColor: Colors.white,
moreIconColor: Colors.white,
menus: getMenus(context),
),
],
),
);
}
}
Expand Down
13 changes: 9 additions & 4 deletions lib/src/menu_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class _MenuWidgetState extends State<_MenuWidget> {
) {
if (_disposed) return;
if (_popups.containsKey(menu._key.toString())) return;
if (!menu._hasContext) return;

final RenderBox overlay =
Overlay.of(context)!.context.findRenderObject() as RenderBox;
Expand Down Expand Up @@ -189,7 +190,12 @@ class _MenuWidgetState extends State<_MenuWidget> {

menuItemWidget = TextButton(
onPressed: item.onTap,
style: TextButton.styleFrom(textStyle: widget.textStyle),
style: TextButton.styleFrom(
textStyle: widget.textStyle,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
child: Padding(padding: padding, child: menuItemWidget),
);

Expand Down Expand Up @@ -257,9 +263,8 @@ class _MenuWidgetState extends State<_MenuWidget> {
BuildContext context,
List<PlutoMenuItem> menuItems,
) {
if (_disposed) {
return;
}
if (_disposed) return;
if (!menu._hasContext) return;

final items = [...menuItems];

Expand Down
2 changes: 2 additions & 0 deletions lib/src/pluto_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class PlutoMenuItem {

bool _isBack = false;

bool get _hasContext => _key.currentContext != null;

Offset get _position {
if (_key.currentContext == null) return Offset.zero;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pluto_menu_bar
description: A menu bar for flutter. You can add as many submenus as you want, and you can change the default style.
version: 2.0.0
version: 2.0.1
homepage: https://pluto.weblaze.dev
repository: https://github.com/bosskmk/pluto_menu_bar

Expand Down

0 comments on commit bce752d

Please sign in to comment.