Navigator.of(context).pushReplacement

时间:2019-07-07 19:17:21

标签: android flutter dart

下午好,我在尝试调用Navigator.of(上下文).pushReplacement时遇到麻烦,我返回了以下错误:

2019-07-07 16:18:17.821 26413-26474/com.zotinfo.diskhamburguerapp E/zygote64: The String#value field is not present on Android versions >= 6.0
2019-07-07 16:18:18.495 26413-26442/com.zotinfo.diskhamburguerapp E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
    At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.

    #0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3257:9)
    #1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3266:6)
    #2      Element.ancestorStateOfType (package:flutter/src/widgets/framework.dart:3314:12)
    #3      Navigator.of (package:flutter/src/widgets/navigator.dart:1446:19)
    #4      Navigator.pushReplacement (package:flutter/src/widgets/navigator.dart:1125:22)
    #5      _ConfereCadastroState.build.<anonymous closure> (package:diskhamburguerapp/widgets/confere_cadastro.dart:61:21)
    #6      _rootRunUnary (dart:async/zone.dart:1132:38)
    #7      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    #8      _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    #9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
    #10     _DelayedData.perform (dart:async/stream_impl.dart:591:14)
    #11     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
    #12     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
    #13     _rootRun (dart:async/zone.dart:1120:38)
    #14     _CustomZone.run (dart:async/zone.dart:1021:19)
    #15     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
    #16     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
    #17     _rootRun (dart:async/zone.dart:1124:13)
    #18     _CustomZone.run (dart:async/zone.dart:1021:19)
    #19     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
    #20     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
    #21     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
    #22     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

这是我的Navigator调用代码

@override
  Widget build(BuildContext context) {

    _loginBloc.outState.listen((state){
      switch(state){
        case UserState.SUCCESS:
          Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeScreen()));
          break;
        case UserState.FAIL:
          Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => NewLoginScreen()));
          break;
        case UserState.NOT_ADMIN:
          break;
        case UserState.LOADING:
        case UserState.IDLE:
          Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => CadastroScreen()));
          break;
      }
    });

    return Scaffold(
      //key: _scaffoldKey,
      backgroundColor: Theme.of(context).primaryColor,
      body: StreamBuilder<UserState>(
          stream: _loginBloc.outState,
          initialData: UserState.LOADING,
          builder: (context, snapshot) {

此错误不会使应用崩溃,也不会发生任何事情,它可以调用路线的屏幕,显示一切正常,但是我担心这是一个错误,它可能会损害其他手机上应用的运行。

我在所有情况下都进行了搜索,包括google,stackoverflow,但是没有任何可能的技巧可以解决此问题,如果遇到过此问题的人有解决方案,我将非常感激。

0 个答案:

没有答案