diff --git a/lib/rx_command.dart b/lib/rx_command.dart index 4e7b939..b3df666 100644 --- a/lib/rx_command.dart +++ b/lib/rx_command.dart @@ -115,7 +115,7 @@ class CommandError { /// where [TParam] is the type of data that is passed when calling [execute] and /// [TResult] denotes the return type of the handler function. To signal that /// a handler doesn't take a parameter or returns no value use the type `void` -abstract class RxCommand extends StreamView { +abstract class RxCommand extends StreamView { bool _isRunning = false; bool _canExecute = true; bool _executionLocked = false; @@ -533,13 +533,13 @@ abstract class RxCommand extends StreamView { loggingHandler; /// This property is a utility which allows us to chain RxCommands together. - Future get next => - Rx.merge([this, this.thrownExceptions.cast()]) + Future get next => + Rx.merge([this, this.thrownExceptions.cast()]) .take(1) .last; late Subject> _commandResultsSubject; - final Subject _resultsSubject; + final Subject _resultsSubject; final BehaviorSubject _isExecutingSubject = BehaviorSubject(); final BehaviorSubject _canExecuteSubject = BehaviorSubject(); final PublishSubject> _thrownExceptionsSubject = @@ -657,7 +657,9 @@ class RxCommandSync extends RxCommand { result = null; } lastResult = result; - _resultsSubject.add(result); + if (result != null || null is TResult) { + _resultsSubject.add(result as TResult); + } commandResult = CommandResult(param, result, null, false); _commandResultsSubject.add(commandResult); diff --git a/test/rx_command_test.dart b/test/rx_command_test.dart index 32a00fd..a65494f 100644 --- a/test/rx_command_test.dart +++ b/test/rx_command_test.dart @@ -667,6 +667,19 @@ void main() { command2.execute("Non-nullable string"); }); + + test("Nullability test for next'able", () async { + final cmd = RxCommand.createAsyncNoParam(() async { + await Future.delayed(Duration(milliseconds: 1000)); + return 42; + }, initialLastResult: 0); + + cmd.execute(); + final result = await cmd.next is int; + + expect(result, true); + }); + // No idea why it's not posible to catch the exception with expect(command.results, emitsError(isException)); /* test('RxCommand.createFromStreamWithException throw exeption = true', ()