Skip to content

Commit

Permalink
Replace Uri copyWith extension with built-in replace (#8615)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Dec 10, 2024
1 parent 564de3c commit aa8b753
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions packages/devtools_app/lib/src/shared/framework/routing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,7 +31,7 @@ class DevToolsRouteConfiguration {
/// in the address bar/state objects).
class DevToolsRouteInformationParser
extends RouteInformationParser<DevToolsRouteConfiguration> {
DevToolsRouteInformationParser();
DevToolsRouteInformationParser() : _testQueryParams = null;

@visibleForTesting
DevToolsRouteInformationParser.test(this._testQueryParams);
Expand All @@ -41,15 +40,15 @@ 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<DevToolsRouteConfiguration> parseRouteInformation(
RouteInformation routeInformation,
) 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
Expand Down
24 changes: 0 additions & 24 deletions packages/devtools_app/lib/src/shared/primitives/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? pathSegments,
String? query,
Map<String, dynamic>? 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.
Expand Down

0 comments on commit aa8b753

Please sign in to comment.