Skip to content

Commit 8f5f20e

Browse files
author
LiJianGe
committed
fix issue best-flutter#3 列表项添加点击跳转到其他页面之后回来, 下拉菜单就不会弹出了
原因: 跳转到其他页面的时候会重复调用 didChangeDependencies , 导致添加多个 listener , 回到页面之后点击时会重复触发点击事件, 开启 => 关闭
1 parent 4599c2c commit 8f5f20e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/drapdown_common.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import 'package:flutter/widgets.dart';
21
import 'package:flutter/foundation.dart';
2+
import 'package:flutter/widgets.dart';
33

44
enum DropdownEvent {
55
// the menu will hide
@@ -158,14 +158,16 @@ abstract class DropdownState<T extends DropdownWidget> extends State<T> {
158158

159159
@override
160160
void didChangeDependencies() {
161-
if (widget.controller == null) {
162-
controller = DefaultDropdownMenuController.of(context);
163-
} else {
164-
controller = widget.controller;
165-
}
161+
if (controller == null) {
162+
if (widget.controller == null) {
163+
controller = DefaultDropdownMenuController.of(context);
164+
} else {
165+
controller = widget.controller;
166+
}
166167

167-
if (controller != null) {
168-
controller.addListener(_onController);
168+
if (controller != null) {
169+
controller.addListener(_onController);
170+
}
169171
}
170172
super.didChangeDependencies();
171173
}

0 commit comments

Comments
 (0)