Skip to content

Commit

Permalink
fix issue best-flutter#3 列表项添加点击跳转到其他页面之后回来, 下拉菜单就不会弹出了
Browse files Browse the repository at this point in the history
原因: 跳转到其他页面的时候会重复调用 didChangeDependencies , 导致添加多个 listener , 回到页面之后点击时会重复触发点击事件, 开启 => 关闭
  • Loading branch information
LiJianGe committed Sep 12, 2018
1 parent 4599c2c commit 8f5f20e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/drapdown_common.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

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

@override
void didChangeDependencies() {
if (widget.controller == null) {
controller = DefaultDropdownMenuController.of(context);
} else {
controller = widget.controller;
}
if (controller == null) {
if (widget.controller == null) {
controller = DefaultDropdownMenuController.of(context);
} else {
controller = widget.controller;
}

if (controller != null) {
controller.addListener(_onController);
if (controller != null) {
controller.addListener(_onController);
}
}
super.didChangeDependencies();
}
Expand Down

0 comments on commit 8f5f20e

Please sign in to comment.