From aa8b753c3c572417c486475cd558ddfe14c60cf5 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 10 Dec 2024 12:09:54 +0530 Subject: [PATCH] Replace Uri copyWith extension with built-in replace (#8615) --- .../extensions/embedded/_controller_web.dart | 2 +- .../lib/src/shared/framework/routing.dart | 7 +++--- .../lib/src/shared/primitives/utils.dart | 24 ------------------- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/packages/devtools_app/lib/src/extensions/embedded/_controller_web.dart b/packages/devtools_app/lib/src/extensions/embedded/_controller_web.dart index ec923e573f4..7f00ec85314 100644 --- a/packages/devtools_app/lib/src/extensions/embedded/_controller_web.dart +++ b/packages/devtools_app/lib/src/extensions/embedded/_controller_web.dart @@ -63,7 +63,7 @@ class EmbeddedExtensionControllerImpl extends EmbeddedExtensionController : ExtensionEventParameters.themeValueLight, if (dtdManager.uri != null) 'dtdUri': dtdManager.uri.toString(), }; - return Uri.parse(baseUri).copyWith(queryParameters: queryParams).toString(); + return Uri.parse(baseUri).replace(queryParameters: queryParams).toString(); } HTMLIFrameElement get extensionIFrame => _extensionIFrame; diff --git a/packages/devtools_app/lib/src/shared/framework/routing.dart b/packages/devtools_app/lib/src/shared/framework/routing.dart index f6e12004aad..7ef1c58f82f 100644 --- a/packages/devtools_app/lib/src/shared/framework/routing.dart +++ b/packages/devtools_app/lib/src/shared/framework/routing.dart @@ -13,7 +13,6 @@ import 'package:flutter/services.dart'; import '../../framework/framework_core.dart'; import '../globals.dart'; import '../primitives/query_parameters.dart'; -import '../primitives/utils.dart'; const homeScreenId = ''; const snapshotScreenId = 'snapshot'; @@ -32,7 +31,7 @@ class DevToolsRouteConfiguration { /// in the address bar/state objects). class DevToolsRouteInformationParser extends RouteInformationParser { - DevToolsRouteInformationParser(); + DevToolsRouteInformationParser() : _testQueryParams = null; @visibleForTesting DevToolsRouteInformationParser.test(this._testQueryParams); @@ -41,7 +40,7 @@ class DevToolsRouteInformationParser /// /// This is to be used in a testing environment only and can be set via the /// [DevToolsRouteInformationParser.test] constructor. - DevToolsQueryParams? _testQueryParams; + final DevToolsQueryParams? _testQueryParams; @override Future parseRouteInformation( @@ -49,7 +48,7 @@ class DevToolsRouteInformationParser ) async { var uri = routeInformation.uri; if (_testQueryParams != null) { - uri = uri.copyWith(queryParameters: _testQueryParams!.params); + uri = uri.replace(queryParameters: _testQueryParams.params); } // routeInformation.path comes from the address bar and (when not empty) is diff --git a/packages/devtools_app/lib/src/shared/primitives/utils.dart b/packages/devtools_app/lib/src/shared/primitives/utils.dart index b2b1c600c2c..50d3ca2caa6 100644 --- a/packages/devtools_app/lib/src/shared/primitives/utils.dart +++ b/packages/devtools_app/lib/src/shared/primitives/utils.dart @@ -1069,30 +1069,6 @@ const connectToNewAppText = 'Connect to a new app'; /// favor of a new request. class ProcessCancelledException implements Exception {} -extension UriExtension on Uri { - Uri copyWith({ - String? scheme, - String? userInfo, - String? host, - int? port, - Iterable? pathSegments, - String? query, - Map? queryParameters, - String? fragment, - }) { - return Uri( - scheme: scheme ?? this.scheme, - userInfo: userInfo ?? this.userInfo, - host: host ?? this.host, - port: port ?? this.port, - pathSegments: pathSegments ?? this.pathSegments, - query: query ?? this.query, - queryParameters: queryParameters ?? this.queryParameters, - fragment: fragment ?? this.fragment, - ); - } -} - // TODO(mtaylee): Prefer to use this helper method whenever a call to // .split('/').last is made on a String (usually on URIs). // See https://github.com/flutter/devtools/issues/4360.