From ba3a5202bad804b551865ef5cd6fcb6bbe3d4622 Mon Sep 17 00:00:00 2001 From: John Ryan Date: Thu, 8 Sep 2022 15:24:14 -0700 Subject: [PATCH] [go_router] Don't clear listeners when logging is disabled (#2533) --- packages/go_router/CHANGELOG.md | 4 ++++ packages/go_router/lib/src/logging.dart | 1 - packages/go_router/pubspec.yaml | 2 +- packages/go_router/test/logging_test.dart | 16 +++------------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index ef1978e05276..7ff717ed4513 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.4.1 + +- Fix an issue where disabling logging clears the root logger's listeners + ## 4.4.0 - Adds `buildPageWithState` to `GoRouteData`. diff --git a/packages/go_router/lib/src/logging.dart b/packages/go_router/lib/src/logging.dart index c66d075fcc1b..ccbb09b7f87d 100644 --- a/packages/go_router/lib/src/logging.dart +++ b/packages/go_router/lib/src/logging.dart @@ -16,7 +16,6 @@ StreamSubscription? _subscription; void setLogging({bool enabled = false}) { _subscription?.cancel(); if (!enabled) { - log.clearListeners(); return; } diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index f93db6b1a675..36f314565799 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 4.4.0 +version: 4.4.1 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 diff --git a/packages/go_router/test/logging_test.dart b/packages/go_router/test/logging_test.dart index 527366015f5c..d6e278610fba 100644 --- a/packages/go_router/test/logging_test.dart +++ b/packages/go_router/test/logging_test.dart @@ -7,21 +7,11 @@ import 'package:go_router/src/logging.dart'; import 'package:logging/logging.dart'; void main() { - // Reset the logger before each test. - setUp(() { - setLogging(); - }); - test('setLogging enables log messages on the logger', () { - log.onRecord.listen(expectAsync1((LogRecord r) {})); - + test('setLogging does not clear listeners', () { + log.onRecord + .listen(expectAsync1((LogRecord r) {}, count: 2)); setLogging(enabled: true); log.info('message'); - }); - - test('setLogging disables log messages on the logger', () { - log.onRecord - .listen(expectAsync1((LogRecord r) {}, count: 0)); - setLogging(); log.info('message'); });