Flutter : Unimplemented handling of missing static target

这个问题应该是分不同的情况,但是现在网上没什么资料

我碰到的问题:在页面写了一个公共带状态的view(StatefulWidget)出现的 , 但是这个问题只出现在了ios端,安卓完全正常(说好的两端一致呢)

解决方法:

1、了解StatefulWidget里构造函数key的作用;

2、了解何时使用GlobalKey;

下面贴代码秒懂:

//view部分
class MyView extends StatefulWidget {
  const MyView({Key key}) : super(key: key);
  @override
  MyViewState createState() => MyViewState();
}

//调用部分

final GlobalKey key = GlobalKey();
MyView(
  key: key,
)

注意:

一个控件使用一个key,不同控件创建不用key ,以免出现下边的问题:

flutter: The following assertion was thrown building RawGestureDetector(state:
flutter: RawGestureDetectorState#3137f(gestures: [tap])):
flutter: Multiple widgets used the same GlobalKey.
flutter: The key [LabeledGlobalKey#6e8a3] was used by multiple widgets. The parents of those
flutter: widgets were:
flutter: - Listener(listeners: [down], behavior: deferToChild, renderObject: RenderPointerListener#cc6e5
flutter: relayoutBoundary=up12 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE)
flutter: - Listener(listeners: [down], behavior: deferToChild, renderObject: RenderPointerListener#54fb3
flutter: NEEDS-LAYOUT NEEDS-PAINT)
flutter: A GlobalKey can only be specified on one widget at a time in the widget tree.

你可能感兴趣的:(flutter)