diff --git a/package/lib/src/beamer.dart b/package/lib/src/beamer.dart index 4dff022..67ecd38 100644 --- a/package/lib/src/beamer.dart +++ b/package/lib/src/beamer.dart @@ -1,11 +1,10 @@ import 'package:beamer/beamer.dart'; +import 'package:beamer/src/utils.dart'; import 'package:flutter/widgets.dart'; import 'package:beamer/src/path_url_strategy_nonweb.dart' if (dart.library.html) 'path_url_strategy_web.dart' as url_strategy; -part 'path_url_query_parameters.dart'; - /// Represents a navigation area and is a wrapper for [Router]. /// /// This is most commonly used for "nested navigation", e.g. in a tabbed view. diff --git a/package/lib/src/path_url_query_parameters.dart b/package/lib/src/path_url_query_parameters.dart deleted file mode 100644 index ff63ba6..0000000 --- a/package/lib/src/path_url_query_parameters.dart +++ /dev/null @@ -1,20 +0,0 @@ -part of 'beamer.dart'; - -/// Returns the provided `String uri` with the constructed `Map? queryParameters` -/// -/// If `Map? queryParameters` is provided, `String uri` should not containt query parameters. -/// -/// When `queryParameters` is used the query is built from the provided map. -/// Each key and value in the map is percent-encoded and joined using equal and ampersand characters. -/// A value in the map must be either a `String`, or an `Iterable`, where the latter corresponds to multiple values for the same key. -@visibleForTesting -String constructUri(String uri, Map? queryParameters) { - final _inputQueryParameters = Uri.parse(uri).queryParameters; - assert(_inputQueryParameters.isEmpty || (queryParameters?.isEmpty ?? true), - 'Avoid passing an uri that already contains query Parameters and a non-empty `queryParameters`'); - - if (queryParameters?.isEmpty ?? true) return uri; - if (_inputQueryParameters.isNotEmpty) return uri; - - return uri + '?' + Uri(queryParameters: queryParameters).query; -} diff --git a/package/lib/src/utils.dart b/package/lib/src/utils.dart index b40c7cd..6a50bc9 100644 --- a/package/lib/src/utils.dart +++ b/package/lib/src/utils.dart @@ -309,3 +309,21 @@ extension BeamerRouteInformationExtension on RouteInformation { return location == other.location && state == other.state; } } + +/// Returns the provided `String uri` with the constructed `Map? queryParameters` +/// +/// If `Map? queryParameters` is provided, `String uri` should not containt query parameters. +/// +/// When `queryParameters` is used the query is built from the provided map. +/// Each key and value in the map is percent-encoded and joined using equal and ampersand characters. +/// A value in the map must be either a `String`, or an `Iterable`, where the latter corresponds to multiple values for the same key. +String constructUri(String uri, Map? queryParameters) { + final _inputQueryParameters = Uri.parse(uri).queryParameters; + assert(_inputQueryParameters.isEmpty || (queryParameters?.isEmpty ?? true), + 'Avoid passing an uri that already contains query Parameters and a non-empty `queryParameters`'); + + if (queryParameters?.isEmpty ?? true) return uri; + if (_inputQueryParameters.isNotEmpty) return uri; + + return uri + '?' + Uri(queryParameters: queryParameters).query; +} diff --git a/package/test/path_url_query_parameters_test.dart b/package/test/path_url_query_parameters_test.dart index edfe9df..1719ba9 100644 --- a/package/test/path_url_query_parameters_test.dart +++ b/package/test/path_url_query_parameters_test.dart @@ -1,4 +1,4 @@ -import 'package:beamer/beamer.dart'; +import 'package:beamer/src/utils.dart'; import 'package:flutter_test/flutter_test.dart'; void main() {