Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer using Uri.parse instead of Uri.http/Uri.https #5834

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http;
// #docregion fetchAlbum
Future<Album> fetchAlbum() async {
final response =
await http.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
await http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));

if (response.statusCode == 200) {
// If the server did return a 200 OK response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import 'package:http/http.dart' as http;

// #docregion fetchAlbum
Future<http.Response> fetchAlbum() {
return http.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
return http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
}
// #enddocregion fetchAlbum
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http;
// #docregion createAlbum
Future<Album> createAlbum(String title) async {
final response = await http.post(
Uri.https('jsonplaceholder.typicode.com', 'albums'),
Uri.parse('https://jsonplaceholder.typicode.com/albums'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:http/http.dart' as http;
// #docregion fetchAlbum
Future<Album> fetchAlbum(http.Client client) async {
final response =
await client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
await client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));

if (response.statusCode == 200) {
// If the server did return a 200 OK response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {

// Use Mockito to return a successful response when it calls the
// provided http.Client.
when(client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1')))
when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
.thenAnswer((_) async => http.Response('{"userId": 1, "id": 2, "title": "mock"}', 200));

expect(await fetchAlbum(client), isA<Album>());
Expand All @@ -29,7 +29,7 @@ void main() {

// Use Mockito to return an unsuccessful response when it calls the
// provided http.Client.
when(client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1')))
when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
.thenAnswer((_) async => http.Response('Not Found', 404));

expect(fetchAlbum(client), throwsException);
Expand Down
7 changes: 3 additions & 4 deletions src/docs/cookbook/networking/fetch-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This recipe covers how to fetch a sample album from the
<?code-excerpt "lib/main_step1.dart (fetchAlbum)"?>
```dart
Future<http.Response> fetchAlbum() {
return http.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
return http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
}
```

Expand Down Expand Up @@ -134,7 +134,7 @@ function to return a `Future<Album>`:
```dart
Future<Album> fetchAlbum() async {
final response =
await http.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
await http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
Expand Down Expand Up @@ -252,7 +252,7 @@ import 'package:http/http.dart' as http;
Future<Album> fetchAlbum() async {
final response =
await http.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
await http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
Expand Down Expand Up @@ -349,4 +349,3 @@ class _MyAppState extends State<MyApp> {
[Mock dependencies using Mockito]: /docs/cookbook/testing/unit/mocking
[JSON and serialization]: /docs/development/data-and-backend/json
[`State`]: {{site.api}}/flutter/widgets/State-class.html

6 changes: 3 additions & 3 deletions src/docs/cookbook/networking/send-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ by sending an album title to the
```dart
Future<http.Response> createAlbum(String title) {
return http.post(
Uri.https('jsonplaceholder.typicode.com', 'albums'),
Uri.parse('https://jsonplaceholder.typicode.com/albums'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
Expand Down Expand Up @@ -135,7 +135,7 @@ function to return a `Future<Album>`:
```dart
Future<Album> createAlbum(String title) async {
final response = await http.post(
Uri.https('jsonplaceholder.typicode.com', 'albums'),
Uri.parse('https://jsonplaceholder.typicode.com/albums'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
Expand Down Expand Up @@ -244,7 +244,7 @@ import 'package:http/http.dart' as http;
Future<Album> createAlbum(String title) async {
final response = await http.post(
Uri.https('jsonplaceholder.typicode.com', 'albums'),
Uri.parse('https://jsonplaceholder.typicode.com/albums'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
Expand Down
12 changes: 6 additions & 6 deletions src/docs/cookbook/testing/unit/mocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The function should now look like this:
```dart
Future<Album> fetchAlbum(http.Client client) async {
final response =
await client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
await client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
Expand Down Expand Up @@ -174,7 +174,7 @@ void main() {
// Use Mockito to return a successful response when it calls the
// provided http.Client.
when(client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1')))
when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
.thenAnswer((_) async => http.Response('{"userId": 1, "id": 2, "title": "mock"}', 200));
expect(await fetchAlbum(client), isA<Album>());
Expand All @@ -185,7 +185,7 @@ void main() {
// Use Mockito to return an unsuccessful response when it calls the
// provided http.Client.
when(client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1')))
when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
.thenAnswer((_) async => http.Response('Not Found', 404));
expect(fetchAlbum(client), throwsException);
Expand Down Expand Up @@ -220,7 +220,7 @@ import 'package:http/http.dart' as http;
Future<Album> fetchAlbum(http.Client client) async {
final response =
await client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1'));
await client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
Expand Down Expand Up @@ -321,7 +321,7 @@ void main() {
// Use Mockito to return a successful response when it calls the
// provided http.Client.
when(client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1')))
when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
.thenAnswer((_) async => http.Response('{"userId": 1, "id": 2, "title": "mock"}', 200));
expect(await fetchAlbum(client), isA<Album>());
Expand All @@ -332,7 +332,7 @@ void main() {
// Use Mockito to return an unsuccessful response when it calls the
// provided http.Client.
when(client.get(Uri.https('jsonplaceholder.typicode.com', 'albums/1')))
when(client.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/1')))
.thenAnswer((_) async => http.Response('Not Found', 404));
expect(fetchAlbum(client), throwsException);
Expand Down
2 changes: 1 addition & 1 deletion src/docs/get-started/flutter-for/react-native-devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ GET, POST, PUT, and DELETE.
<!-- skip -->
```dart
// Flutter
final url = Uri.https('httpbin.org', 'ip');
final url = Uri.parse('https://httpbin.org/ip');
final httpClient = HttpClient();
_getIPAddress() async {
var request = await httpClient.getUrl(url);
Expand Down