From d58de2175bd794e4aa86207a68d3f6991d017521 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 30 Nov 2023 11:55:28 -0800 Subject: [PATCH 01/15] Factory --- .../lib/http_client_factory.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/flutter_http_example/lib/http_client_factory.dart b/pkgs/flutter_http_example/lib/http_client_factory.dart index cb36597c23..34f78c76af 100644 --- a/pkgs/flutter_http_example/lib/http_client_factory.dart +++ b/pkgs/flutter_http_example/lib/http_client_factory.dart @@ -8,12 +8,20 @@ import 'package:cronet_http/cronet_http.dart'; import 'package:cupertino_http/cupertino_http.dart'; import 'package:http/http.dart'; +const maxCacheSize = 2 * 1024 * 1024; + Client httpClient() { if (Platform.isAndroid) { - return CronetClient.defaultCronetEngine(); + final engine = CronetEngine.build( + cacheMode: CacheMode.memory, + cacheMaxSize: maxCacheSize, + userAgent: 'Book Agent'); + return CronetClient.fromCronetEngine(engine); } if (Platform.isIOS || Platform.isMacOS) { - return CupertinoClient.defaultSessionConfiguration(); + final config = URLSessionConfiguration.ephemeralSessionConfiguration() + ..cache = URLCache.withCapacity(memoryCapacity: maxCacheSize); + return CupertinoClient.fromSessionConfiguration(config); } return Client(); // Return the default client. } From e39a71c719d1bc3b67665206c4b4a333c0641e58 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 7 Dec 2023 13:13:15 -0800 Subject: [PATCH 02/15] Update http_client_factory.dart --- pkgs/flutter_http_example/lib/http_client_factory.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/flutter_http_example/lib/http_client_factory.dart b/pkgs/flutter_http_example/lib/http_client_factory.dart index 34f78c76af..855eef1d1a 100644 --- a/pkgs/flutter_http_example/lib/http_client_factory.dart +++ b/pkgs/flutter_http_example/lib/http_client_factory.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:cronet_http/cronet_http.dart'; import 'package:cupertino_http/cupertino_http.dart'; import 'package:http/http.dart'; +import 'package:http/io_client.dart'; const maxCacheSize = 2 * 1024 * 1024; @@ -23,5 +24,5 @@ Client httpClient() { ..cache = URLCache.withCapacity(memoryCapacity: maxCacheSize); return CupertinoClient.fromSessionConfiguration(config); } - return Client(); // Return the default client. + return IOClient(HttpClient()..userAgent = 'Book Agent'); } From c7ed5e934002ff4335fe56582f25b37ed7feafc4 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 14 Dec 2023 16:53:27 -0800 Subject: [PATCH 03/15] Switch to http_image_provider --- pkgs/cronet_http/example/lib/book.dart | 6 ++-- pkgs/cronet_http/example/lib/main.dart | 35 ++++++++++++------- pkgs/cronet_http/example/pubspec.yaml | 3 +- pkgs/cupertino_http/example/lib/book.dart | 4 +-- pkgs/cupertino_http/example/lib/main.dart | 34 ++++++++++++------ pkgs/cupertino_http/example/pubspec.yaml | 3 +- pkgs/flutter_http_example/lib/book.dart | 4 +-- pkgs/flutter_http_example/lib/main.dart | 31 +++++----------- pkgs/flutter_http_example/pubspec.yaml | 2 +- .../test/widget_test.dart | 17 ++++++--- 10 files changed, 80 insertions(+), 59 deletions(-) diff --git a/pkgs/cronet_http/example/lib/book.dart b/pkgs/cronet_http/example/lib/book.dart index 61a663b4d3..b47ca9e67e 100644 --- a/pkgs/cronet_http/example/lib/book.dart +++ b/pkgs/cronet_http/example/lib/book.dart @@ -1,11 +1,11 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. class Book { String title; String description; - String imageUrl; + Uri imageUrl; Book(this.title, this.description, this.imageUrl); @@ -21,7 +21,7 @@ class Book { 'description': final String description, 'imageLinks': {'smallThumbnail': final String thumbnail} }) { - books.add(Book(title, description, thumbnail)); + books.add(Book(title, description, Uri.parse(thumbnail))); } } } diff --git a/pkgs/cronet_http/example/lib/main.dart b/pkgs/cronet_http/example/lib/main.dart index 61f11a7b01..b06d349602 100644 --- a/pkgs/cronet_http/example/lib/main.dart +++ b/pkgs/cronet_http/example/lib/main.dart @@ -5,21 +5,31 @@ import 'dart:convert'; import 'dart:io'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:cronet_http/cronet_http.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart'; +import 'package:http/io_client.dart'; +import 'package:http_image_provider/http_image_provider.dart'; +import 'package:provider/provider.dart'; import 'book.dart'; void main() { - var clientFactory = Client.new; // Constructs the default client. + late Client httpClient; if (Platform.isAndroid) { final engine = CronetEngine.build( - cacheMode: CacheMode.memory, userAgent: 'Book Agent'); - clientFactory = () => CronetClient.fromCronetEngine(engine); + cacheMode: CacheMode.memory, + cacheMaxSize: 2 * 1024 * 1024, + userAgent: 'Book Agent'); + httpClient = CronetClient.fromCronetEngine(engine); + } else { + httpClient = IOClient(HttpClient()..userAgent = 'Book Agent'); } - runWithClient(() => runApp(const BookSearchApp()), clientFactory); + + runApp(Provider( + create: (_) => httpClient, + child: const BookSearchApp(), + dispose: (_, client) => client.close())); } class BookSearchApp extends StatelessWidget { @@ -44,20 +54,22 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { List? _books; String? _lastQuery; + late Client _client; @override void initState() { super.initState(); + _client = context.read(); } // Get the list of books matching `query`. // The `get` call will automatically use the `client` configurated in `main`. Future> _findMatchingBooks(String query) async { - final response = await get( + final response = await _client.get( Uri.https( 'www.googleapis.com', '/books/v1/volumes', - {'q': query, 'maxResults': '40', 'printType': 'books'}, + {'q': query, 'maxResults': '20', 'printType': 'books'}, ), ); @@ -129,11 +141,10 @@ class _BookListState extends State { itemBuilder: (context, index) => Card( key: ValueKey(widget.books[index].title), child: ListTile( - leading: CachedNetworkImage( - placeholder: (context, url) => - const CircularProgressIndicator(), - imageUrl: - widget.books[index].imageUrl.replaceFirst('http', 'https')), + leading: Image( + image: HttpImage( + widget.books[index].imageUrl.replace(scheme: 'https'), + client: context.read())), title: Text(widget.books[index].title), subtitle: Text(widget.books[index].description), ), diff --git a/pkgs/cronet_http/example/pubspec.yaml b/pkgs/cronet_http/example/pubspec.yaml index 5bb80276a6..904b1e5ade 100644 --- a/pkgs/cronet_http/example/pubspec.yaml +++ b/pkgs/cronet_http/example/pubspec.yaml @@ -7,13 +7,14 @@ environment: sdk: ^3.0.0 dependencies: - cached_network_image: ^3.2.3 cronet_http: path: ../ cupertino_icons: ^1.0.2 flutter: sdk: flutter http: ^1.0.0 + http_image_provider: ^0.0.2 + provider: ^6.1.1 dev_dependencies: dart_flutter_team_lints: ^2.0.0 diff --git a/pkgs/cupertino_http/example/lib/book.dart b/pkgs/cupertino_http/example/lib/book.dart index f2a27fc460..b47ca9e67e 100644 --- a/pkgs/cupertino_http/example/lib/book.dart +++ b/pkgs/cupertino_http/example/lib/book.dart @@ -5,7 +5,7 @@ class Book { String title; String description; - String imageUrl; + Uri imageUrl; Book(this.title, this.description, this.imageUrl); @@ -21,7 +21,7 @@ class Book { 'description': final String description, 'imageLinks': {'smallThumbnail': final String thumbnail} }) { - books.add(Book(title, description, thumbnail)); + books.add(Book(title, description, Uri.parse(thumbnail))); } } } diff --git a/pkgs/cupertino_http/example/lib/main.dart b/pkgs/cupertino_http/example/lib/main.dart index edfceac92e..5cd6ac8bb3 100644 --- a/pkgs/cupertino_http/example/lib/main.dart +++ b/pkgs/cupertino_http/example/lib/main.dart @@ -5,19 +5,30 @@ import 'dart:convert'; import 'dart:io'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:cupertino_http/cupertino_http.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart'; +import 'package:http/io_client.dart'; +import 'package:http_image_provider/http_image_provider.dart'; +import 'package:provider/provider.dart'; import 'book.dart'; void main() { - var clientFactory = Client.new; // The default Client. + late Client httpClient; if (Platform.isIOS || Platform.isMacOS) { - clientFactory = CupertinoClient.defaultSessionConfiguration.call; + /// XXX fix this! + final config = URLSessionConfiguration.ephemeralSessionConfiguration() + ..cache = URLCache.withCapacity(memoryCapacity: 2 * 1024 * 1024); + httpClient = CupertinoClient.fromSessionConfiguration(config); + } else { + httpClient = IOClient(HttpClient()..userAgent = 'Book Agent'); } - runWithClient(() => runApp(const BookSearchApp()), clientFactory); + + runApp(Provider( + create: (_) => httpClient, + child: const BookSearchApp(), + dispose: (_, client) => client.close())); } class BookSearchApp extends StatelessWidget { @@ -42,20 +53,22 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { List? _books; String? _lastQuery; + late Client _client; @override void initState() { super.initState(); + _client = context.read(); } // Get the list of books matching `query`. // The `get` call will automatically use the `client` configurated in `main`. Future> _findMatchingBooks(String query) async { - final response = await get( + final response = await _client.get( Uri.https( 'www.googleapis.com', '/books/v1/volumes', - {'q': query, 'maxResults': '40', 'printType': 'books'}, + {'q': query, 'maxResults': '20', 'printType': 'books'}, ), ); @@ -127,11 +140,10 @@ class _BookListState extends State { itemBuilder: (context, index) => Card( key: ValueKey(widget.books[index].title), child: ListTile( - leading: CachedNetworkImage( - placeholder: (context, url) => - const CircularProgressIndicator(), - imageUrl: - widget.books[index].imageUrl.replaceFirst('http', 'https')), + leading: Image( + image: HttpImage( + widget.books[index].imageUrl.replace(scheme: 'https'), + client: context.read())), title: Text(widget.books[index].title), subtitle: Text(widget.books[index].description), ), diff --git a/pkgs/cupertino_http/example/pubspec.yaml b/pkgs/cupertino_http/example/pubspec.yaml index bae184b71c..08048579ae 100644 --- a/pkgs/cupertino_http/example/pubspec.yaml +++ b/pkgs/cupertino_http/example/pubspec.yaml @@ -10,13 +10,14 @@ environment: flutter: '>=3.10.0' dependencies: - cached_network_image: ^3.2.3 cupertino_http: path: ../ cupertino_icons: ^1.0.2 flutter: sdk: flutter http: ^1.0.0 + http_image_provider: ^0.0.2 + provider: ^6.1.1 dev_dependencies: convert: ^3.1.1 diff --git a/pkgs/flutter_http_example/lib/book.dart b/pkgs/flutter_http_example/lib/book.dart index f2a27fc460..b47ca9e67e 100644 --- a/pkgs/flutter_http_example/lib/book.dart +++ b/pkgs/flutter_http_example/lib/book.dart @@ -5,7 +5,7 @@ class Book { String title; String description; - String imageUrl; + Uri imageUrl; Book(this.title, this.description, this.imageUrl); @@ -21,7 +21,7 @@ class Book { 'description': final String description, 'imageLinks': {'smallThumbnail': final String thumbnail} }) { - books.add(Book(title, description, thumbnail)); + books.add(Book(title, description, Uri.parse(thumbnail))); } } } diff --git a/pkgs/flutter_http_example/lib/main.dart b/pkgs/flutter_http_example/lib/main.dart index 406b9e6b71..548c3dee0a 100644 --- a/pkgs/flutter_http_example/lib/main.dart +++ b/pkgs/flutter_http_example/lib/main.dart @@ -4,9 +4,9 @@ import 'dart:convert'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart'; +import 'package:http_image_provider/http_image_provider.dart'; import 'package:provider/provider.dart'; import 'book.dart'; @@ -14,22 +14,10 @@ import 'http_client_factory.dart' if (dart.library.js_interop) 'http_client_factory_web.dart' as http_factory; void main() { - // `runWithClient` is used to control which `package:http` `Client` is used - // when the `Client` constructor is called. This method allows you to choose - // the `Client` even when the package that you are using does not offer - // explicit parameterization. - // - // However, `runWithClient` does not work with Flutter tests. See - // https://github.com/flutter/flutter/issues/96939. - // - // Use `package:provider` and `runWithClient` together so that tests and - // unparameterized `Client` usages both work. - runWithClient( - () => runApp(Provider( - create: (_) => http_factory.httpClient(), - child: const BookSearchApp(), - dispose: (_, client) => client.close())), - http_factory.httpClient); + runApp(Provider( + create: (_) => http_factory.httpClient(), + child: const BookSearchApp(), + dispose: (_, client) => client.close())); } class BookSearchApp extends StatelessWidget { @@ -141,11 +129,10 @@ class _BookListState extends State { itemBuilder: (context, index) => Card( key: ValueKey(widget.books[index].title), child: ListTile( - leading: CachedNetworkImage( - placeholder: (context, url) => - const CircularProgressIndicator(), - imageUrl: - widget.books[index].imageUrl.replaceFirst('http', 'https')), + leading: Image( + image: HttpImage( + widget.books[index].imageUrl.replace(scheme: 'https'), + client: context.read())), title: Text(widget.books[index].title), subtitle: Text(widget.books[index].description), ), diff --git a/pkgs/flutter_http_example/pubspec.yaml b/pkgs/flutter_http_example/pubspec.yaml index 0331490003..90b449109a 100644 --- a/pkgs/flutter_http_example/pubspec.yaml +++ b/pkgs/flutter_http_example/pubspec.yaml @@ -9,7 +9,6 @@ environment: flutter: '>=3.10.0' dependencies: - cached_network_image: ^3.2.3 cronet_http: ^0.4.1 cupertino_http: ^1.1.0 cupertino_icons: ^1.0.2 @@ -17,6 +16,7 @@ dependencies: flutter: sdk: flutter http: ^1.0.0 + http_image_provider: ^0.0.2 provider: ^6.0.5 dev_dependencies: diff --git a/pkgs/flutter_http_example/test/widget_test.dart b/pkgs/flutter_http_example/test/widget_test.dart index 9e0af25b97..1935ce2c01 100644 --- a/pkgs/flutter_http_example/test/widget_test.dart +++ b/pkgs/flutter_http_example/test/widget_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:flutter_http_example/main.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -25,6 +27,10 @@ const _singleBookResponse = ''' } '''; +final image = base64Decode( + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", +); + void main() { Widget app(Client client) => Provider( create: (_) => client, @@ -42,11 +48,14 @@ void main() { testWidgets('test search with one result', (WidgetTester tester) async { final mockClient = MockClient((request) async { - if (request.url.path != '/books/v1/volumes' && - request.url.queryParameters['q'] != 'Flutter') { - return Response('', 404); + if (request.url.path == '/books/v1/volumes' && + request.url.queryParameters['q'] == 'Flutter') { + return Response(_singleBookResponse, 200); + } else if (request.url.queryParameters['id'] == 'gcnAEAAAQBAJ') { + return Response.bytes(image, 200, + headers: const {'Content-Type': 'image/bmp'}); } - return Response(_singleBookResponse, 200); + return Response('', 404); }); await tester.pumpWidget(app(mockClient)); From 64443056956fc46b1c93cca58e9ea787a2f9234a Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 14 Dec 2023 16:59:32 -0800 Subject: [PATCH 04/15] Update docs --- pkgs/http/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/http/README.md b/pkgs/http/README.md index 642c238035..973ff83c6e 100644 --- a/pkgs/http/README.md +++ b/pkgs/http/README.md @@ -272,7 +272,7 @@ $ dart compile exe --define=no_default_http_client=true ... > [!TIP] > [The Flutter HTTP example application][flutterhttpexample] demonstrates > how to make the configured [`Client`][client] available using -> [`package:provider`][provider] and [`runWithClient`](runwithclient). +> [`package:provider`][provider] and [`package:http_image_provider`][http_image_provider]. [browserclient]: https://pub.dev/documentation/http/latest/browser_client/BrowserClient-class.html [client]: https://pub.dev/documentation/http/latest/http/Client-class.html From 6130cb8fbbc57040a5d885bb2fc2726f5dad34d2 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 14 Dec 2023 17:01:24 -0800 Subject: [PATCH 05/15] Restore copyright date --- pkgs/cronet_http/example/lib/book.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/cronet_http/example/lib/book.dart b/pkgs/cronet_http/example/lib/book.dart index b47ca9e67e..584ae9a361 100644 --- a/pkgs/cronet_http/example/lib/book.dart +++ b/pkgs/cronet_http/example/lib/book.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. From 7199b11a7ba012b523d3633b459702ea7edbfec3 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 14 Dec 2023 17:02:15 -0800 Subject: [PATCH 06/15] Link --- pkgs/http/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/http/README.md b/pkgs/http/README.md index 973ff83c6e..85ec2911df 100644 --- a/pkgs/http/README.md +++ b/pkgs/http/README.md @@ -284,6 +284,7 @@ $ dart compile exe --define=no_default_http_client=true ... [fetch]: https://pub.dev/packages/fetch_client [fetchclient]: https://pub.dev/documentation/fetch_client/latest/fetch_client/FetchClient-class.html [flutterhttpexample]: https://github.com/dart-lang/http/tree/master/pkgs/flutter_http_example +[http_image_provider]: https://pub.dev/documentation/http_image_provider [ioclient]: https://pub.dev/documentation/http/latest/io_client/IOClient-class.html [isolate]: https://dart.dev/language/concurrency#how-isolates-work [flutterstatemanagement]: https://docs.flutter.dev/data-and-backend/state-mgmt/options From 5afe399e9bd5138ab754dd772ebeb36d92bdcc05 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 21 Dec 2023 15:27:28 -0800 Subject: [PATCH 07/15] Update --- pkgs/cupertino_http/README.md | 57 ++++++------------- .../lib/http_client_factory.dart | 3 +- pkgs/flutter_http_example/pubspec.yaml | 4 +- 3 files changed, 20 insertions(+), 44 deletions(-) diff --git a/pkgs/cupertino_http/README.md b/pkgs/cupertino_http/README.md index 83514dcc40..e7ee744566 100644 --- a/pkgs/cupertino_http/README.md +++ b/pkgs/cupertino_http/README.md @@ -24,49 +24,25 @@ This approach allows the same HTTP code to be used on all platforms, while still allowing platform-specific setup. ```dart -late Client client; -if (Platform.isIOS) { - final config = URLSessionConfiguration.ephemeralSessionConfiguration() - ..allowsCellularAccess = false - ..allowsConstrainedNetworkAccess = false - ..allowsExpensiveNetworkAccess = false; - client = CupertinoClient.fromSessionConfiguration(config); -} else { - client = IOClient(); // Uses an HTTP client based on dart:io -} - -final response = await client.get(Uri.https( - 'www.googleapis.com', - '/books/v1/volumes', - {'q': 'HTTP', 'maxResults': '40', 'printType': 'books'})); -``` - -[package:http runWithClient][] can be used to configure the -[package:http Client][] for the entire application. - -```dart -void main() { - late Client client; - if (Platform.isIOS) { - client = CupertinoClient.defaultSessionConfiguration(); +import 'package:cupertino_http/cupertino_http.dart'; +import 'package:http/http.dart'; +import 'package:http/io_client.dart'; + +void main() async { + late Client httpClient; + if (Platform.isIOS || Platform.isMacOS) { + final config = URLSessionConfiguration.ephemeralSessionConfiguration() + ..cache = URLCache.withCapacity(memoryCapacity: 2 * 1024 * 1024) + ..httpAdditionalHeaders = {'User-Agent': 'Book Agent'}; + httpClient = CupertinoClient.fromSessionConfiguration(config); } else { - client = IOClient(); + httpClient = IOClient(HttpClient()..userAgent = 'Book Agent'); } - runWithClient(() => runApp(const MyApp()), () => client); -} - -... - -class MainPageState extends State { - void someMethod() { - // Will use the Client configured in main. - final response = await get(Uri.https( - 'www.googleapis.com', - '/books/v1/volumes', - {'q': 'HTTP', 'maxResults': '40', 'printType': 'books'})); - } - ... + final response = await client.get(Uri.https( + 'www.googleapis.com', + '/books/v1/volumes', + {'q': 'HTTP', 'maxResults': '40', 'printType': 'books'})); } ``` @@ -88,6 +64,5 @@ task.resume(); ``` [package:http Client]: https://pub.dev/documentation/http/latest/http/Client-class.html -[package:http runWithClient]: https://pub.dev/documentation/http/latest/http/runWithClient.html [Foundation URL Loading System]: https://developer.apple.com/documentation/foundation/url_loading_system [dart:io HttpClient]: https://api.dart.dev/stable/dart-io/HttpClient-class.html diff --git a/pkgs/flutter_http_example/lib/http_client_factory.dart b/pkgs/flutter_http_example/lib/http_client_factory.dart index 855eef1d1a..36ab521a0c 100644 --- a/pkgs/flutter_http_example/lib/http_client_factory.dart +++ b/pkgs/flutter_http_example/lib/http_client_factory.dart @@ -21,7 +21,8 @@ Client httpClient() { } if (Platform.isIOS || Platform.isMacOS) { final config = URLSessionConfiguration.ephemeralSessionConfiguration() - ..cache = URLCache.withCapacity(memoryCapacity: maxCacheSize); + ..cache = URLCache.withCapacity(memoryCapacity: maxCacheSize) + ..httpAdditionalHeaders = {'User-Agent': 'Book Agent'}; return CupertinoClient.fromSessionConfiguration(config); } return IOClient(HttpClient()..userAgent = 'Book Agent'); diff --git a/pkgs/flutter_http_example/pubspec.yaml b/pkgs/flutter_http_example/pubspec.yaml index 90b449109a..7d0f0892ce 100644 --- a/pkgs/flutter_http_example/pubspec.yaml +++ b/pkgs/flutter_http_example/pubspec.yaml @@ -9,8 +9,8 @@ environment: flutter: '>=3.10.0' dependencies: - cronet_http: ^0.4.1 - cupertino_http: ^1.1.0 + cronet_http: ^1.0.0 + cupertino_http: ^1.2.0 cupertino_icons: ^1.0.2 fetch_client: ^1.0.2 flutter: From abe76a7cc028ce0bcdc556b654ddcdf9498b26f8 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 21 Dec 2023 15:39:13 -0800 Subject: [PATCH 08/15] Simplify tests --- pkgs/flutter_http_example/test/widget_test.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkgs/flutter_http_example/test/widget_test.dart b/pkgs/flutter_http_example/test/widget_test.dart index 1935ce2c01..f890a1bb11 100644 --- a/pkgs/flutter_http_example/test/widget_test.dart +++ b/pkgs/flutter_http_example/test/widget_test.dart @@ -19,7 +19,7 @@ const _singleBookResponse = ''' "title": "Flutter Cookbook", "description": "Write, test, and publish your web, desktop...", "imageLinks": { - "smallThumbnail": "http://books.google.com/books/content?id=gcnAEAAAQBAJ&printsec=frontcover&img=1&zoom=5&edge=curl&source=gbs_api" + "smallThumbnail": "http://thumbnailurl/" } } } @@ -27,8 +27,9 @@ const _singleBookResponse = ''' } '''; -final image = base64Decode( - "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", +final _dummyPngImage = base64Decode( + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmM' + 'IQAAAABJRU5ErkJggg==', ); void main() { @@ -51,9 +52,9 @@ void main() { if (request.url.path == '/books/v1/volumes' && request.url.queryParameters['q'] == 'Flutter') { return Response(_singleBookResponse, 200); - } else if (request.url.queryParameters['id'] == 'gcnAEAAAQBAJ') { - return Response.bytes(image, 200, - headers: const {'Content-Type': 'image/bmp'}); + } else if (request.url == Uri.https('thumbnailurl', '/')) { + return Response.bytes(_dummyPngImage, 200, + headers: const {'Content-Type': 'image/png'}); } return Response('', 404); }); From acfaa3be74c96a8834a6a0689143f477329b27b9 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 21 Dec 2023 17:07:28 -0800 Subject: [PATCH 09/15] Update --- pkgs/cronet_http/CHANGELOG.md | 4 ++++ pkgs/cronet_http/pubspec.yaml | 2 +- pkgs/cupertino_http/CHANGELOG.md | 4 ++++ pkgs/cupertino_http/pubspec.yaml | 2 +- pkgs/flutter_http_example/README.md | 8 +++----- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkgs/cronet_http/CHANGELOG.md b/pkgs/cronet_http/CHANGELOG.md index cf1fcbc208..6cc73ab31d 100644 --- a/pkgs/cronet_http/CHANGELOG.md +++ b/pkgs/cronet_http/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.1-wip + +* Use `package:http_image_provider` in the example application. + ## 1.0.0 * No functional changes. diff --git a/pkgs/cronet_http/pubspec.yaml b/pkgs/cronet_http/pubspec.yaml index 5f4229ebf8..c9e0e4d0a0 100644 --- a/pkgs/cronet_http/pubspec.yaml +++ b/pkgs/cronet_http/pubspec.yaml @@ -1,5 +1,5 @@ name: cronet_http -version: 1.0.0 +version: 1.0.1-wip description: >- An Android Flutter plugin that provides access to the Cronet HTTP client. repository: https://github.com/dart-lang/http/tree/master/pkgs/cronet_http diff --git a/pkgs/cupertino_http/CHANGELOG.md b/pkgs/cupertino_http/CHANGELOG.md index d768f7a5c7..395bb8b3b7 100644 --- a/pkgs/cupertino_http/CHANGELOG.md +++ b/pkgs/cupertino_http/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.1-wip + +* Use `package:http_image_provider` in the example application. + ## 1.2.0 * Add support for setting additional http headers in diff --git a/pkgs/cupertino_http/pubspec.yaml b/pkgs/cupertino_http/pubspec.yaml index 0a97bdd25d..e9a2bbfdb2 100644 --- a/pkgs/cupertino_http/pubspec.yaml +++ b/pkgs/cupertino_http/pubspec.yaml @@ -1,5 +1,5 @@ name: cupertino_http -version: 1.2.0 +version: 1.2.1-wip description: >- A macOS/iOS Flutter plugin that provides access to the Foundation URL Loading System. diff --git a/pkgs/flutter_http_example/README.md b/pkgs/flutter_http_example/README.md index 2c6cdfd025..763d83c04e 100644 --- a/pkgs/flutter_http_example/README.md +++ b/pkgs/flutter_http_example/README.md @@ -9,8 +9,7 @@ A Flutter sample app that illustrates how to configure and use including: * configuration for multiple platforms. - * using `runWithClient` and `package:provider` to pass `Client`s through - an application. + * using `package:provider` to pass `Client`s through an application. * writing tests using `MockClient`. ## The important bits @@ -34,9 +33,8 @@ This library demonstrates how to: * import `http_client_factory.dart` or `http_client_factory_web.dart`, depending on whether we are targeting the web browser or not. -* share a `package:http` `Client` by using `runWithClient` and - `package:provider`. -* call `package:http` functions. +* share a `package:http` `Client` by `package:provider`. +* call `package:http` `Client` methods. ### `widget_test.dart` From a623f09278ed8473561083604a637074fa28f749 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Tue, 2 Jan 2024 15:48:16 -0800 Subject: [PATCH 10/15] Update README.md --- pkgs/flutter_http_example/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/flutter_http_example/README.md b/pkgs/flutter_http_example/README.md index 763d83c04e..1a9cf9dd8a 100644 --- a/pkgs/flutter_http_example/README.md +++ b/pkgs/flutter_http_example/README.md @@ -33,7 +33,7 @@ This library demonstrates how to: * import `http_client_factory.dart` or `http_client_factory_web.dart`, depending on whether we are targeting the web browser or not. -* share a `package:http` `Client` by `package:provider`. +* share a `package:http` `Client` by using `package:provider`. * call `package:http` `Client` methods. ### `widget_test.dart` From 10a7630d7f6a2606a0b9cbd72e0b828b832ea819 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Wed, 3 Jan 2024 17:53:10 -0800 Subject: [PATCH 11/15] Changed late to final in client assignment --- pkgs/cronet_http/README.md | 2 +- pkgs/cronet_http/example/lib/main.dart | 2 +- pkgs/cupertino_http/README.md | 2 +- pkgs/cupertino_http/example/lib/main.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/cronet_http/README.md b/pkgs/cronet_http/README.md index 49acf3390d..47ebd8bac1 100644 --- a/pkgs/cronet_http/README.md +++ b/pkgs/cronet_http/README.md @@ -37,7 +37,7 @@ import 'package:http/http.dart'; import 'package:http/io_client.dart'; void main() async { - late Client httpClient; + final Client httpClient; if (Platform.isAndroid) { final engine = CronetEngine.build( cacheMode: CacheMode.memory, diff --git a/pkgs/cronet_http/example/lib/main.dart b/pkgs/cronet_http/example/lib/main.dart index b06d349602..6e1bad22c4 100644 --- a/pkgs/cronet_http/example/lib/main.dart +++ b/pkgs/cronet_http/example/lib/main.dart @@ -15,7 +15,7 @@ import 'package:provider/provider.dart'; import 'book.dart'; void main() { - late Client httpClient; + final Client httpClient; if (Platform.isAndroid) { final engine = CronetEngine.build( cacheMode: CacheMode.memory, diff --git a/pkgs/cupertino_http/README.md b/pkgs/cupertino_http/README.md index e7ee744566..77c1d79244 100644 --- a/pkgs/cupertino_http/README.md +++ b/pkgs/cupertino_http/README.md @@ -29,7 +29,7 @@ import 'package:http/http.dart'; import 'package:http/io_client.dart'; void main() async { - late Client httpClient; + final Client httpClient; if (Platform.isIOS || Platform.isMacOS) { final config = URLSessionConfiguration.ephemeralSessionConfiguration() ..cache = URLCache.withCapacity(memoryCapacity: 2 * 1024 * 1024) diff --git a/pkgs/cupertino_http/example/lib/main.dart b/pkgs/cupertino_http/example/lib/main.dart index 6444f0e67e..092300a64c 100644 --- a/pkgs/cupertino_http/example/lib/main.dart +++ b/pkgs/cupertino_http/example/lib/main.dart @@ -15,7 +15,7 @@ import 'package:provider/provider.dart'; import 'book.dart'; void main() { - late Client httpClient; + final Client httpClient; if (Platform.isIOS || Platform.isMacOS) { final config = URLSessionConfiguration.ephemeralSessionConfiguration() ..cache = URLCache.withCapacity(memoryCapacity: 2 * 1024 * 1024) From 8516a9e6cfde59213a1d32f9c6338e7a171be4f7 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Wed, 3 Jan 2024 17:55:03 -0800 Subject: [PATCH 12/15] Update http_client_factory.dart --- pkgs/flutter_http_example/lib/http_client_factory.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/flutter_http_example/lib/http_client_factory.dart b/pkgs/flutter_http_example/lib/http_client_factory.dart index 36ab521a0c..6e6ddc040b 100644 --- a/pkgs/flutter_http_example/lib/http_client_factory.dart +++ b/pkgs/flutter_http_example/lib/http_client_factory.dart @@ -9,19 +9,19 @@ import 'package:cupertino_http/cupertino_http.dart'; import 'package:http/http.dart'; import 'package:http/io_client.dart'; -const maxCacheSize = 2 * 1024 * 1024; +const _maxCacheSize = 2 * 1024 * 1024; Client httpClient() { if (Platform.isAndroid) { final engine = CronetEngine.build( cacheMode: CacheMode.memory, - cacheMaxSize: maxCacheSize, + cacheMaxSize: _maxCacheSize, userAgent: 'Book Agent'); return CronetClient.fromCronetEngine(engine); } if (Platform.isIOS || Platform.isMacOS) { final config = URLSessionConfiguration.ephemeralSessionConfiguration() - ..cache = URLCache.withCapacity(memoryCapacity: maxCacheSize) + ..cache = URLCache.withCapacity(memoryCapacity: _maxCacheSize) ..httpAdditionalHeaders = {'User-Agent': 'Book Agent'}; return CupertinoClient.fromSessionConfiguration(config); } From da4e441debed481b5fa033b4c624651cc6790490 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 4 Jan 2024 15:12:50 -0800 Subject: [PATCH 13/15] Increment JDK version --- pkgs/cronet_http/example/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/cronet_http/example/android/app/build.gradle b/pkgs/cronet_http/example/android/app/build.gradle index 1f7cd94749..ab1c62d006 100644 --- a/pkgs/cronet_http/example/android/app/build.gradle +++ b/pkgs/cronet_http/example/android/app/build.gradle @@ -70,7 +70,7 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" // ""com.google.android.gms:play-services-cronet" is only present so that // `jnigen` will work. Applications should not include this line. implementation "com.google.android.gms:play-services-cronet:18.0.1" From 02cdfaa5731c30ee08866fdb0c25d1d253805ebe Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 4 Jan 2024 15:28:31 -0800 Subject: [PATCH 14/15] Update build.gradle --- pkgs/cronet_http/example/android/app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/cronet_http/example/android/app/build.gradle b/pkgs/cronet_http/example/android/app/build.gradle index ab1c62d006..1f7cd94749 100644 --- a/pkgs/cronet_http/example/android/app/build.gradle +++ b/pkgs/cronet_http/example/android/app/build.gradle @@ -70,7 +70,7 @@ flutter { } dependencies { - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // ""com.google.android.gms:play-services-cronet" is only present so that // `jnigen` will work. Applications should not include this line. implementation "com.google.android.gms:play-services-cronet:18.0.1" From c5e0bcbe4631c691c73b9832b1b7ea4fd59b8188 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 4 Jan 2024 15:39:43 -0800 Subject: [PATCH 15/15] Update cronet.yml --- .github/workflows/cronet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cronet.yml b/.github/workflows/cronet.yml index 0976a756ff..8e114a0055 100644 --- a/.github/workflows/cronet.yml +++ b/.github/workflows/cronet.yml @@ -39,7 +39,7 @@ jobs: - name: Make cronet_http_embedded copy if: ${{ matrix.package == 'cronet_http_embedded' }} run: | - cp -r pkgs/cronet_http pkgs/cronet_http_embedded + mv pkgs/cronet_http pkgs/cronet_http_embedded cd pkgs/cronet_http_embedded flutter pub get && dart tool/prepare_for_embedded.dart - id: install