Skip to content

Commit a369084

Browse files
nateboschfiliph
authored andcommitted
Pass a URI to package:http API (flutter#5202)
* Pass a URI to package:http API Updates example to be forwards compatible with the breaking change in dart-lang/http#507 * Other usages. Drop local variable type to match other example
1 parent 7376e8c commit a369084

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/docs/cookbook/networking/fetch-data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ This recipe covers how to fetch a sample album from the
5959
<!-- skip -->
6060
```dart
6161
Future<http.Response> fetchAlbum() {
62-
return http.get('https://jsonplaceholder.typicode.com/albums/1');
62+
return http.get(Uri.https('jsonplaceholder.typicode.com','albums/1'));
6363
}
6464
```
6565

@@ -242,7 +242,7 @@ import 'package:http/http.dart' as http;
242242
243243
Future<Album> fetchAlbum() async {
244244
final response =
245-
await http.get('https://jsonplaceholder.typicode.com/albums/1');
245+
await http.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1');
246246
247247
if (response.statusCode == 200) {
248248
// If the server did return a 200 OK response,

src/docs/cookbook/networking/send-data.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ by sending an album title to the
5656
```dart
5757
Future<http.Response> createAlbum(String title) {
5858
return http.post(
59-
'https://jsonplaceholder.typicode.com/albums',
59+
Uri.https('jsonplaceholder.typicode.com','albums'),
6060
headers: <String, String>{
6161
'Content-Type': 'application/json; charset=UTF-8',
6262
},
@@ -132,8 +132,8 @@ function to return a `Future<Album>`:
132132
<!-- skip -->
133133
```dart
134134
Future<Album> createAlbum(String title) async {
135-
final http.Response response = await http.post(
136-
'https://jsonplaceholder.typicode.com/albums',
135+
final response = await http.post(
136+
Uri.https('jsonplaceholder.typicode.com','albums'),
137137
headers: <String, String>{
138138
'Content-Type': 'application/json; charset=UTF-8',
139139
},
@@ -242,8 +242,8 @@ import 'package:flutter/material.dart';
242242
import 'package:http/http.dart' as http;
243243
244244
Future<Album> createAlbum(String title) async {
245-
final http.Response response = await http.post(
246-
'https://jsonplaceholder.typicode.com/albums',
245+
final response = await http.post(
246+
Uri.https('jsonplaceholder.typicode.com','albums'),
247247
headers: <String, String>{
248248
'Content-Type': 'application/json; charset=UTF-8',
249249
},

0 commit comments

Comments
 (0)