fluttercandies / flutter_smart_dialog

An elegant Flutter Dialog solution | 一种更优雅的 Flutter Dialog 解决方案
MIT License
1.14k stars 142 forks source link

The provided entry used for `below` must be present in the Overlay. #32

Closed MrDgbot closed 2 years ago

MrDgbot commented 2 years ago

初始化了,在initState里面添加监听中showToast报错,

image
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 402 pos 7: 'below == null || (below._overlay == this && _entries.contains(below) && (newEntries?.contains(below) ?? true))': The provided entry used for `below` must be present in the Overlay. E/flutter (27604): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61) E/flutter (27604): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5) E/flutter (27604): #2 OverlayState._debugVerifyInsertPosition (package:flutter/src/widgets/overlay.dart:402:7) E/flutter (27604): #3 OverlayState.insert (package:flutter/src/widgets/overlay.dart:355:12) E/flutter (27604): #4 CustomDialog._handleDialogStack (package:flutter_smart_dialog/src/custom/custom_dialog.dart:198:45) E/flutter (27604): #5 CustomDialog._handleMustOperate (package:flutter_smart_dialog/src/custom/custom_dialog.dart:143:5) E/flutter (27604): #6 CustomDialog.show (package:flutter_smart_dialog/src/custom/custom_dialog.dart:51:10) E/flutter (27604): #7 DialogProxy.show (package:flutter_smart_dialog/src/helper/dialog_proxy.dart:80:19) E/flutter (27604): #8 SmartDialog.show (package:flutter_smart_dialog/src/smart_dialog.dart:181:33) E/flutter (27604): #9 _ShakePageState._shakeEvent (package:flutter_shake/pages/shake.dart:85:23) E/flutter (27604): #10 _ShakePageState.initState. (package:flutter_shake/pages/shake.dart:173:47) E/flutter (27604): #11 _ShakePageState.initState. (package:flutter_shake/pages/shake.dart:173:11) E/flutter (27604): #12 _rootRunUnary (dart:async/zone.dart:1434:47) E/flutter (27604): #13 _CustomZone.runUnary (dart:async/zone.dart:1335:19) E/flutter (27604): #14 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) E/flutter (27604): #15 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) E/flutter (27604): #16 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7) E/flutter (27604): #17 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11) E/flutter (27604): #18 _MapStream._handleData (dart:async/stream_pipe.dart:218:10) E/flutter (27604): #19 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13) E/flutter (27604): #20 _rootRunUnary (dart:async/zone.dart:1434:47) E/flutter (27604): #21 _CustomZone.runUnary (dart:async/zone.dart:1335:19) E/flutter (27604): #22 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7) E/flutter (27604): #23 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) E/flutter (27604): #24 _DelayedData.perform (dart:async/stream_impl.dart:591:14) E/flutter (27604): #25 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11) E/flutter (27604): #26 _PendingEvents.schedule. (dart:async/stream_impl.dart:663:7) E/flutter (27604): #27 _rootRun (dart:async/zone.dart:1418:47) E/flutter (27604): #28 _CustomZone.run (dart:async/zone.dart:1328:19) E/flutter (27604): #29 _CustomZone.runGuarded (dart:async/zone.dart:1236:7) E/flutter (27604): #30 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1276:23) E/flutter (27604): #31 _rootRun (dart:async/zone.dart:1426:13) E/flutter (27604): #32 _CustomZone.run (dart:async/zone.dart:1328:19) E/flutter (27604): #33 _CustomZone.runGuarded (dart:async/zone.dart:1236:7) E/flutter (27604): #34 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1276:23) E/flutter (27604): #35 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) E/flutter (27604): #36 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5) E/flutter (27604):
xdd666t commented 2 years ago
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
    //页面渲染完成
});
MrDgbot commented 2 years ago
  • initState里面做界面操作,必须要等当前页面渲染完成
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
    //页面渲染完成
});

将监听放入后 同样存在此问题 代码如下

Future _shakeEvent( BuildContext context, AccelerometerEvent event) async { if (_isInCurrentPage) { // 加速传感器触发值 int value = 10; if (event.x.abs() > value || event.y.abs() > value || event.z.abs() > value) { if (!_isShow) { // 震动 // Vibration.vibrate(amplitude: 128); _isShow = true; SmartDialog.show( widget: CupertinoAlertDialog( title: const Text("恭喜找到了了"), content: Column( children: [ const ListTile( leading: FlutterLogo(size: 60), title: Text("李四"), subtitle: Text("位置 班级"), ), const Divider(), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Expanded( flex: 7, child: TextField( controller: _messageController, decoration: const InputDecoration( labelText: '点我发送消息', hintText: '请输入想说的话吧', ), ), ), Expanded( flex: 3, child: ElevatedButton( child: const Text('发送'), onPressed: () => _sendButtonPressed(context), ), ), ], ) ], ), ), ).then((value) => _isShow = false); } } } } @override void initState() { _messageController.addListener(messageListener); WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { _streamSubscriptions.add(accelerometerEvents.listen( (AccelerometerEvent event) async => _shakeEvent(context, event))); }); super.initState(); }
xdd666t commented 2 years ago

你传个能复现问题的最简demo吧

GiddyNaya commented 2 years ago

I get the error after after focusing on a textfield before calling SmartDialog.show. The fix for me was to open a popmenu and close immediately before calling SmartDialog.show:

  // The below block fixes an overlay bug that
  // occurs when a textfield is focused before SmartDialog.show is triggered:
  // In other to fix the issue, I open up a popup menu and close immediately
  // before calling SmartDialog.show:
  showMenu(
    context: context,
    color: transparentColor,
    position: RelativeRect.fromLTRB(100, 100, 100, 100),
    items: [
      PopupMenuItem<String>(child: const SizedBox(), value: 'Nothing'),
    ],
  );
  finish(context); // Close popup menu
  SmartDialog.show(
    backDismiss: false,
    clickBgDismissTemp: false,
    isLoadingTemp: false,
    alignmentTemp: Alignment.centerRight,
    tag: tag,
    widget: Column(...