Skip to content

Commit

Permalink
moved constructUri to utils.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzohidalgo committed Oct 17, 2022
1 parent a76118e commit ec9006c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
3 changes: 1 addition & 2 deletions package/lib/src/beamer.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 0 additions & 20 deletions package/lib/src/path_url_query_parameters.dart

This file was deleted.

18 changes: 18 additions & 0 deletions package/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,21 @@ extension BeamerRouteInformationExtension on RouteInformation {
return location == other.location && state == other.state;
}
}

/// Returns the provided `String uri` with the constructed `Map<String, dynamic>? queryParameters`
///
/// If `Map<String, dynamic>? 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<String>`, where the latter corresponds to multiple values for the same key.
String constructUri(String uri, Map<String, dynamic>? 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;
}
2 changes: 1 addition & 1 deletion package/test/path_url_query_parameters_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:beamer/beamer.dart';
import 'package:beamer/src/utils.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Expand Down

0 comments on commit ec9006c

Please sign in to comment.