Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(With pull request) reaction<Sth?>() errors: type 'Null' is not a subtype of type 'T' of 'value' reaction=Instance of 'ReactionImpl' #640

Closed
fzyzcjy opened this issue Mar 10, 2021 · 0 comments

Comments

@fzyzcjy
Copy link
Collaborator

fzyzcjy commented Mar 10, 2021

Hi thanks for the lib! We have error when executing the following minimum reproducible sample:

void oops() {
  // mainContext.config = ReactiveConfig(disableErrorBoundaries: true);

  mainContext.onReactionError((e, reaction) {
    print('onReactionError error.type=${e.runtimeType} error=$e reaction=$reaction');
    if (e is MobXCaughtException) {
      debugPrint(
          'e.exception.runtimeType=${e.exception.runtimeType} e.exception=${e.exception} e.stackTrace=${e.stackTrace}');
    }
  });

  print('hi 0');
  reaction<int?>(
    (Reaction r) {
      print('hi 1');
      return null;
      // return 42; // if this then ok
    },
    (int? val) {
      print('hi 2');
    },
    fireImmediately: true,
  );
  print('hi 3');
}

The full code:

import 'package:flutter/material.dart';
import 'package:mobx/mobx.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    oops();
  }

  Widget build(BuildContext context) {
    return Container();
  }
}

// and copy `oops()` here

The error:

Performing hot restart...
Syncing files to device iPhone 11...
Restarted application in 438ms.
flutter: hi 0
flutter: hi 1
flutter: onReactionError error.type=MobXCaughtException error=MobXCaughtException: type 'Null' is not a subtype of type 'T' of 'value' reaction=Instance of 'ReactionImpl'
flutter: e.exception.runtimeType=_TypeError e.exception=type 'Null' is not a subtype of type 'T' of 'value' e.stackTrace=#0      _TypeError._throwNew (dart:core-patch/errors_patch.dart:98:34)
flutter: #1      Function._apply (dart:core-patch/function_patch.dart:11:30)
flutter: #2      Function.apply (dart:core-patch/function_patch.dart:34:12)
flutter: #3      Action.call (package:mobx/src/core/action.dart:53:25)
flutter: #4      createReaction.reactionRunner (package:mobx/src/core/reaction_helper.dart:108:19)
flutter: #5      createReaction.<anonymous closure> (package:mobx/src/core/reaction_helper.dart:120:21)
flutter: #6      ReactionImpl._run (package:mobx/src/core/reaction.dart:117:22)
flutter: #7      ReactiveContext._runReactionsInternal (package:mobx/src/core/context.dart:345:18)
flutter: #8      ReactiveContext.runReactions (package:mobx/src/core/context.dart:319:5)
flutter: #9      ReactionImpl.schedule (package:mobx/src/core/reaction.dart:157:9)
flutter: #10     createReaction (package:mobx/src/core/reaction_helper.dart:139:7)
flutter: #11     reaction (package:mobx/src/api/reaction.dart:54:5)
flutter: #12     oops (package:bug/main.dart:35:3)
flutter: #13     _MyAppState.initState (package:bug/main.dart:15:5)
flutter: #14     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4632:57)
flutter: #15     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4469:5)
flutter: #16     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
flutter: #17     Element.updateChild (package:flutter/src/widgets/framework.dart:3306:18)
flutter: #18     RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1182:16)
flutter: #19     RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1153:5)
flutter: #20     RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1095:18)
flutter: #21     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2647:19)
flutter: #22     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1094:13)
flutter: #23     WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:934:7)
flutter: #24     WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:915:7)
flutter: #25     _rootRun (dart:async/zone.dart:1346:47)
flutter: #26     _CustomZone.run (dart:async/zone.dart:1258:19)
flutter: #27     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
flutter: #28     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
flutter: #29     _rootRun (dart:async/zone.dart:1354:13)
flutter: #30     _CustomZone.run (dart:async/zone.dart:1258:19)
flutter: #31     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1186:23)
flutter: #32     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
flutter: #33     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
flutter: #34     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
flutter: #35     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
flutter:
flutter: hi 3
fzyzcjy added a commit to fzyzcjy/mobx.dart that referenced this issue Mar 10, 2021
@fzyzcjy fzyzcjy changed the title (with simple reproducible sample) type 'Null' is not a subtype of type 'T' of 'value' reaction=Instance of 'ReactionImpl' (With pull request) type 'Null' is not a subtype of type 'T' of 'value' reaction=Instance of 'ReactionImpl' Mar 10, 2021
@fzyzcjy fzyzcjy changed the title (With pull request) type 'Null' is not a subtype of type 'T' of 'value' reaction=Instance of 'ReactionImpl' (With pull request) reaction<Sth?>() errors: type 'Null' is not a subtype of type 'T' of 'value' reaction=Instance of 'ReactionImpl' Mar 10, 2021
pavanpodila pushed a commit that referenced this issue Mar 11, 2021
…n() (#638)

* Fixbug when key is null for ObservableMap

* Update observable_map.dart

* fixbug #640
@fzyzcjy fzyzcjy closed this as completed Mar 15, 2021
jeffcas181 added a commit to jeffcas181/mobx-codegen-dart that referenced this issue Aug 31, 2022
…n() (#638)

* Fixbug when key is null for ObservableMap

* Update observable_map.dart

* fixbug mobxjs/mobx.dart#640
joshpeterson30489 added a commit to joshpeterson30489/mobx-dart-codegen-flutter that referenced this issue Sep 30, 2022
…n() (#638)

* Fixbug when key is null for ObservableMap

* Update observable_map.dart

* fixbug mobxjs/mobx.dart#640
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant