diff --git a/packages/flutter/lib/src/foundation/print.dart b/packages/flutter/lib/src/foundation/print.dart index 5b15e4eb94..bf95e35efc 100644 --- a/packages/flutter/lib/src/foundation/print.dart +++ b/packages/flutter/lib/src/foundation/print.dart @@ -41,10 +41,11 @@ void debugPrintSynchronously(String message, { int wrapWidth }) { /// Implementation of [debugPrint] that throttles messages. This avoids dropping /// messages on platforms that rate-limit their logging (for example, Android). void debugPrintThrottled(String message, { int wrapWidth }) { + final List messageLines = message?.split('\n') ?? ['null']; if (wrapWidth != null) { - _debugPrintBuffer.addAll(message.split('\n').expand((String line) => debugWordWrap(line, wrapWidth))); + _debugPrintBuffer.addAll(messageLines.expand((String line) => debugWordWrap(line, wrapWidth))); } else { - _debugPrintBuffer.addAll(message.split('\n')); + _debugPrintBuffer.addAll(messageLines); } if (!_debugPrintScheduled) _debugPrintTask(); @@ -87,6 +88,7 @@ Future get debugPrintDone => _debugPrintCompleter?.future ?? Future. final RegExp _indentPattern = RegExp('^ *(?:[-+*] |[0-9]+[.):] )?'); enum _WordWrapParseMode { inSpace, inWord, atBreak } + /// Wraps the given string at the given width. /// /// Wrapping occurs at space characters (U+0020). Lines that start with an diff --git a/packages/flutter/test/foundation/print_test.dart b/packages/flutter/test/foundation/print_test.dart index 5813448296..94de4680f1 100644 --- a/packages/flutter/test/foundation/print_test.dart +++ b/packages/flutter/test/foundation/print_test.dart @@ -57,4 +57,16 @@ void main() { expect(log.length, 2); }); }); + + test('debugPrint can print null', () { + expect( + captureOutput(() { debugPrintThrottled(null); }), + equals(['null']), + ); + + expect( + captureOutput(() { debugPrintThrottled(null, wrapWidth: 80); }), + equals(['null']), + ); + }); }