From c1ea0d4614c4748c3056ad70e8eabf8ad23593c1 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 20 Feb 2024 10:14:01 -0800 Subject: [PATCH 1/3] Relax http --- packages/flutter_svg/CHANGELOG.md | 4 ++++ packages/flutter_svg/pubspec.yaml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/flutter_svg/CHANGELOG.md b/packages/flutter_svg/CHANGELOG.md index ea9a4e24..d17a8ff4 100644 --- a/packages/flutter_svg/CHANGELOG.md +++ b/packages/flutter_svg/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGES +## 2.0.10+1 + +- Relax http dependency. + ## 2.0.10 - Use package:http for network requests, and allow injection of the client. diff --git a/packages/flutter_svg/pubspec.yaml b/packages/flutter_svg/pubspec.yaml index 4e07c613..a30078b6 100644 --- a/packages/flutter_svg/pubspec.yaml +++ b/packages/flutter_svg/pubspec.yaml @@ -2,12 +2,12 @@ name: flutter_svg description: An SVG rendering and widget library for Flutter, which allows painting and displaying Scalable Vector Graphics 1.1 files. repository: https://github.com/dnfield/flutter_svg/tree/master/packages/flutter_svg issue_tracker: https://github.com/dnfield/flutter_svg/issues -version: 2.0.10 +version: 2.0.10+1 dependencies: flutter: sdk: flutter - http: ^1.2.1 + http: ^1.0.0 vector_graphics: ^1.1.11 vector_graphics_codec: ^1.1.11 vector_graphics_compiler: ^1.1.11 From 24a94c3307b319a0a17e9045cf85e47cb13cea11 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 20 Feb 2024 10:23:00 -0800 Subject: [PATCH 2/3] update test package too --- packages/flutter_svg_test/pubspec.yaml | 9 +- .../test/flutter_svg_test_test.dart | 87 +++---------------- 2 files changed, 17 insertions(+), 79 deletions(-) diff --git a/packages/flutter_svg_test/pubspec.yaml b/packages/flutter_svg_test/pubspec.yaml index 42877752..54a1a426 100644 --- a/packages/flutter_svg_test/pubspec.yaml +++ b/packages/flutter_svg_test/pubspec.yaml @@ -2,17 +2,20 @@ name: flutter_svg_test description: A testing library which makes it easy to test flutter svg . Built to be used with the flutter svg package. repository: https://github.com/dnfield/flutter_svg/tree/master/packages/flutter_svg_test issue_tracker: https://github.com/dnfield/flutter_svg/issues -version: 1.0.0 +version: 1.0.1 dependencies: flutter: sdk: flutter - flutter_svg: ^2.0.4 + flutter_svg: ^2.0.10 flutter_test: sdk: flutter +dev_dependencies: + http: ^1.0.0 + environment: sdk: '>=2.19.0-0 <4.0.0' flutter: ">=3.7.0-0" - + diff --git a/packages/flutter_svg_test/test/flutter_svg_test_test.dart b/packages/flutter_svg_test/test/flutter_svg_test_test.dart index 474b5e79..40208717 100644 --- a/packages/flutter_svg_test/test/flutter_svg_test_test.dart +++ b/packages/flutter_svg_test/test/flutter_svg_test_test.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; @@ -7,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg_test/flutter_svg_test.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart' as http; void main() { group('finds', () { @@ -24,12 +24,11 @@ void main() { }); testWidgets('network svg', (WidgetTester widgetTester) async { - await HttpOverrides.runZoned(() async { - final SvgPicture asset = SvgPicture.network('svg.dart'); - await widgetTester.pumpWidget(asset); + final http.Client fakeClient = _FakeHttpClient(); + final SvgPicture asset = SvgPicture.network('svg.dart', httpClient: fakeClient); + await widgetTester.pumpWidget(asset); - expect(find.svg(asset.bytesLoader), findsOneWidget); - }, createHttpClient: (SecurityContext? c) => _setupFakeClient); + expect(find.svg(asset.bytesLoader), findsOneWidget); }); testWidgets('string svg', (WidgetTester widgetTester) async { @@ -68,12 +67,10 @@ void main() { }); testWidgets('network svg with url', (WidgetTester widgetTester) async { - await HttpOverrides.runZoned(() async { - const String svgUri = 'svg.dart'; - await widgetTester.pumpWidget(SvgPicture.network(svgUri)); + const String svgUri = 'svg.dart'; + await widgetTester.pumpWidget(SvgPicture.network(svgUri)); - expect(find.svgNetworkWithUrl(svgUri), findsOneWidget); - }, createHttpClient: (SecurityContext? c) => _setupFakeClient); + expect(find.svgNetworkWithUrl(svgUri), findsOneWidget); }); testWidgets('file svg wit path', (WidgetTester widgetTester) async { @@ -93,13 +90,6 @@ void main() { }); } -HttpClient get _setupFakeClient { - final _FakeHttpClientResponse fakeResponse = _FakeHttpClientResponse(); - final _FakeHttpClientRequest fakeRequest = - _FakeHttpClientRequest(fakeResponse); - return _FakeHttpClient(fakeRequest); -} - class _FakeAssetBundle extends Fake implements AssetBundle { @override Future loadString(String key, {bool cache = true}) async { @@ -112,65 +102,10 @@ class _FakeAssetBundle extends Fake implements AssetBundle { } } -class _FakeHttpClient extends Fake implements HttpClient { - _FakeHttpClient(this.request); - - _FakeHttpClientRequest request; - - @override - Future getUrl(Uri url) async => request; -} - -class _FakeHttpHeaders extends Fake implements HttpHeaders { - final Map values = {}; - - @override - void add(String name, Object value, {bool preserveHeaderCase = false}) { - values[name] = value.toString(); - } - - @override - List? operator [](String key) { - return [values[key]!]; - } -} - -class _FakeHttpClientRequest extends Fake implements HttpClientRequest { - _FakeHttpClientRequest(this.response); - - _FakeHttpClientResponse response; - - @override - final HttpHeaders headers = _FakeHttpHeaders(); - - @override - Future close() async => response; -} - -class _FakeHttpClientResponse extends Fake implements HttpClientResponse { - @override - int statusCode = 200; - - @override - int contentLength = _svgStr.length; - - @override - HttpClientResponseCompressionState get compressionState => - HttpClientResponseCompressionState.notCompressed; - +class _FakeHttpClient extends Fake implements http.Client { @override - StreamSubscription> listen( - void Function(List event)? onData, { - Function? onError, - void Function()? onDone, - bool? cancelOnError, - }) { - return Stream.fromIterable([_svgBytes]).listen( - onData, - onDone: onDone, - onError: onError, - cancelOnError: cancelOnError, - ); + Future get(Uri url, {Map? headers}) async { + return http.Response(_svgStr, 200); } } From 07f161bf5ec259602a17026b85e3b0fcaa98ed69 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 20 Feb 2024 10:24:29 -0800 Subject: [PATCH 3/3] format; --- packages/flutter_svg_test/test/flutter_svg_test_test.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/flutter_svg_test/test/flutter_svg_test_test.dart b/packages/flutter_svg_test/test/flutter_svg_test_test.dart index 40208717..d00ce7a4 100644 --- a/packages/flutter_svg_test/test/flutter_svg_test_test.dart +++ b/packages/flutter_svg_test/test/flutter_svg_test_test.dart @@ -25,7 +25,10 @@ void main() { testWidgets('network svg', (WidgetTester widgetTester) async { final http.Client fakeClient = _FakeHttpClient(); - final SvgPicture asset = SvgPicture.network('svg.dart', httpClient: fakeClient); + final SvgPicture asset = SvgPicture.network( + 'svg.dart', + httpClient: fakeClient, + ); await widgetTester.pumpWidget(asset); expect(find.svg(asset.bytesLoader), findsOneWidget);