diff --git a/examples/pub/lib/pub_repository.dart b/examples/pub/lib/pub_repository.dart index 55e457073..a03bbe734 100644 --- a/examples/pub/lib/pub_repository.dart +++ b/examples/pub/lib/pub_repository.dart @@ -11,7 +11,6 @@ class PubRepository { _configureDio(); } - static const _scheme = 'https'; static const _host = 'pub.dartlang.org'; final dio = Dio(); @@ -19,11 +18,10 @@ class PubRepository { required int page, CancelToken? cancelToken, }) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/packages', - queryParameters: {'page': '$page'}, + final uri = Uri.https( + _host, + 'api/packages', + {'page': '$page'}, ); final response = await dio.getUri>( @@ -40,11 +38,10 @@ class PubRepository { required String search, CancelToken? cancelToken, }) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/search', - queryParameters: {'page': '$page', 'q': search}, + final uri = Uri.https( + _host, + 'api/search', + {'page': '$page', 'q': search}, ); // Returns {packages: [{ package: string }]} final response = await dio.getUri>( @@ -60,11 +57,7 @@ class PubRepository { required String packageName, CancelToken? cancelToken, }) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/packages/$packageName', - ); + final uri = Uri.https(_host, 'api/packages/$packageName'); final response = await dio.getUri>( uri, @@ -79,22 +72,14 @@ class PubRepository { required String packageName, CancelToken? cancelToken, }) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/packages/$packageName/metrics', - ); + final uri = Uri.https(_host, 'api/packages/$packageName/metrics'); final responseFuture = dio.getUri>( uri, cancelToken: cancelToken, ); - final likesUri = Uri( - scheme: _scheme, - host: _host, - path: 'api/packages/$packageName/likes', - ); + final likesUri = Uri.https(_host, 'api/packages/$packageName/likes'); /// Although the metrics request does include the likes count, it seems that /// the server caches the response for a long period of time. @@ -116,11 +101,7 @@ class PubRepository { required String packageName, CancelToken? cancelToken, }) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/account/likes/$packageName', - ); + final uri = Uri.https(_host, 'api/account/likes/$packageName'); await dio.putUri( uri, @@ -135,11 +116,7 @@ class PubRepository { required String packageName, CancelToken? cancelToken, }) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/account/likes/$packageName', - ); + final uri = Uri.https(_host, 'api/account/likes/$packageName'); await dio.deleteUri( uri, @@ -149,11 +126,7 @@ class PubRepository { } Future> getLikedPackages({CancelToken? cancelToken}) async { - final uri = Uri( - scheme: _scheme, - host: _host, - path: 'api/account/likes', - ); + final uri = Uri.https(_host, 'api/account/likes'); final response = await dio.getUri>( uri, diff --git a/website/docs/essentials/first_request/codegen/provider.dart b/website/docs/essentials/first_request/codegen/provider.dart index 4c16e2edb..9df7863a1 100644 --- a/website/docs/essentials/first_request/codegen/provider.dart +++ b/website/docs/essentials/first_request/codegen/provider.dart @@ -13,9 +13,7 @@ part 'provider.g.dart'; @riverpod Future activity(ActivityRef ref) async { // Using package:http, we fetch a random activity from the Bored API. - final response = await http.get( - Uri(scheme: 'https', host: 'boredapi.com', path: '/api/activity'), - ); + final response = await http.get(Uri.https('boredapi.com', '/api/activity')); // Using dart:convert, we then decode the JSON payload into a Map data structure. final json = jsonDecode(response.body) as Map; // Finally, we convert the Map into an Activity instance. diff --git a/website/docs/essentials/first_request/raw/provider.dart b/website/docs/essentials/first_request/raw/provider.dart index 2c855f7b0..f1395604f 100644 --- a/website/docs/essentials/first_request/raw/provider.dart +++ b/website/docs/essentials/first_request/raw/provider.dart @@ -7,9 +7,7 @@ import 'activity.dart'; final activityProvider = FutureProvider.autoDispose((ref) async { // Using package:http, we fetch a random activity from the Bored API. - final response = await http.get( - Uri(scheme: 'https', host: 'boredapi.com', path: '/api/activity'), - ); + final response = await http.get(Uri.https('boredapi.com', '/api/activity')); // Using dart:convert, we then decode the JSON payload into a Map data structure. final json = jsonDecode(response.body) as Map; // Finally, we convert the Map into an Activity instance. diff --git a/website/docs/essentials/passing_args/codegen/provider.dart b/website/docs/essentials/passing_args/codegen/provider.dart index 03169ae1d..86bd98255 100644 --- a/website/docs/essentials/passing_args/codegen/provider.dart +++ b/website/docs/essentials/passing_args/codegen/provider.dart @@ -9,9 +9,7 @@ part 'provider.g.dart'; /* SNIPPET START */ @riverpod Future activity(ActivityRef ref) async { - final response = await http.get( - Uri(scheme: 'https', host: 'boredapi.com', path: '/api/activity'), - ); + final response = await http.get(Uri.https('boredapi.com', '/api/activity')); final json = jsonDecode(response.body) as Map; return Activity.fromJson(json); } diff --git a/website/docs/essentials/passing_args/raw/provider.dart b/website/docs/essentials/passing_args/raw/provider.dart index be7a2573c..a79a71bcb 100644 --- a/website/docs/essentials/passing_args/raw/provider.dart +++ b/website/docs/essentials/passing_args/raw/provider.dart @@ -6,9 +6,7 @@ import '../../first_request/raw/activity.dart'; /* SNIPPET START */ final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri(scheme: 'https', host: 'boredapi.com', path: '/api/activity'), - ); + final response = await http.get(Uri.https('boredapi.com', '/api/activity')); final json = jsonDecode(response.body) as Map; return Activity.fromJson(json); }); diff --git a/website/docs/essentials/side_effects/codegen/todo_list_notifier_add_todo.dart b/website/docs/essentials/side_effects/codegen/todo_list_notifier_add_todo.dart index 3d53074e2..15f4ffa7e 100644 --- a/website/docs/essentials/side_effects/codegen/todo_list_notifier_add_todo.dart +++ b/website/docs/essentials/side_effects/codegen/todo_list_notifier_add_todo.dart @@ -17,7 +17,7 @@ class TodoList extends _$TodoList { Future addTodo(Todo todo) async { await http.post( - Uri(scheme: 'https', host: 'your_api.com', path: '/todos'), + Uri.https('your_api.com', '/todos'), // We serialize our Todo object and POST it to the server. headers: {'Content-Type': 'application/json'}, body: jsonEncode(todo.toJson()), diff --git a/website/docs/essentials/side_effects/raw/invalidate_self_add_todo.dart b/website/docs/essentials/side_effects/raw/invalidate_self_add_todo.dart index 54c04c362..09b58fb1e 100644 --- a/website/docs/essentials/side_effects/raw/invalidate_self_add_todo.dart +++ b/website/docs/essentials/side_effects/raw/invalidate_self_add_todo.dart @@ -20,7 +20,7 @@ class TodoList extends AutoDisposeAsyncNotifier> { Future addTodo(Todo todo) async { // We don't care about the API response await http.post( - Uri(scheme: 'https', host: 'your_api.com', path: '/todos'), + Uri.https('your_api.com', '/todos'), headers: {'Content-Type': 'application/json'}, body: jsonEncode(todo.toJson()), ); diff --git a/website/docs/essentials/side_effects/raw/manual_add_todo.dart b/website/docs/essentials/side_effects/raw/manual_add_todo.dart index 574433f9a..ca909a751 100644 --- a/website/docs/essentials/side_effects/raw/manual_add_todo.dart +++ b/website/docs/essentials/side_effects/raw/manual_add_todo.dart @@ -20,7 +20,7 @@ class TodoList extends AutoDisposeAsyncNotifier> { Future addTodo(Todo todo) async { // We don't care about the API response await http.post( - Uri(scheme: 'https', host: 'your_api.com', path: '/todos'), + Uri.https('your_api.com', '/todos'), headers: {'Content-Type': 'application/json'}, body: jsonEncode(todo.toJson()), ); diff --git a/website/docs/essentials/side_effects/raw/mutable_manual_add_todo.dart b/website/docs/essentials/side_effects/raw/mutable_manual_add_todo.dart index d40d4861a..db41ecff9 100644 --- a/website/docs/essentials/side_effects/raw/mutable_manual_add_todo.dart +++ b/website/docs/essentials/side_effects/raw/mutable_manual_add_todo.dart @@ -19,7 +19,7 @@ class TodoList extends AutoDisposeAsyncNotifier> { Future addTodo(Todo todo) async { // We don't care about the API response await http.post( - Uri(scheme: 'https', host: 'your_api.com', path: '/todos'), + Uri.https('your_api.com', '/todos'), headers: {'Content-Type': 'application/json'}, body: jsonEncode(todo.toJson()), ); diff --git a/website/docs/essentials/side_effects/raw/rest_add_todo.dart b/website/docs/essentials/side_effects/raw/rest_add_todo.dart index 41609d31f..e5a2a30df 100644 --- a/website/docs/essentials/side_effects/raw/rest_add_todo.dart +++ b/website/docs/essentials/side_effects/raw/rest_add_todo.dart @@ -20,7 +20,7 @@ class TodoList extends AutoDisposeAsyncNotifier> { Future addTodo(Todo todo) async { // The POST request will return a List matching the new application state final response = await http.post( - Uri(scheme: 'https', host: 'your_api.com', path: '/todos'), + Uri.https('your_api.com', '/todos'), headers: {'Content-Type': 'application/json'}, body: jsonEncode(todo.toJson()), ); diff --git a/website/docs/essentials/side_effects/raw/todo_list_notifier_add_todo.dart b/website/docs/essentials/side_effects/raw/todo_list_notifier_add_todo.dart index ecd4ec00a..2023bdc99 100644 --- a/website/docs/essentials/side_effects/raw/todo_list_notifier_add_todo.dart +++ b/website/docs/essentials/side_effects/raw/todo_list_notifier_add_todo.dart @@ -19,7 +19,7 @@ class TodoList extends AutoDisposeAsyncNotifier> { Future addTodo(Todo todo) async { await http.post( - Uri(scheme: 'https', host: 'your_api.com', path: '/todos'), + Uri.https('your_api.com', '/todos'), // We serialize our Todo object and POST it to the server. headers: {'Content-Type': 'application/json'}, body: jsonEncode(todo.toJson()),