diff --git a/example/bin/main.dart b/example/bin/main.dart index dee1665..4d126bf 100644 --- a/example/bin/main.dart +++ b/example/bin/main.dart @@ -4,10 +4,10 @@ import 'package:diff_image/diff_image.dart'; import 'package:image/image.dart'; void main() async { - final FIRST_IMAGE_URL = - 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-cs.png'; - final SECOND_IMAGE_URL = - 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-node.png'; + final FIRST_IMAGE_URL = Uri.parse( + 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-cs.png'); + final SECOND_IMAGE_URL = Uri.parse( + 'https://raw.githubusercontent.com/nicolashahn/diffimg/master/images/mario-circle-node.png'); // You need a try/catch block to handle the exceptions (http request, different size, etc) try { diff --git a/lib/src/diff_image_html.dart b/lib/src/diff_image_html.dart index 60778eb..64ce748 100644 --- a/lib/src/diff_image_html.dart +++ b/lib/src/diff_image_html.dart @@ -1,14 +1,13 @@ import 'package:image/image.dart'; -import 'package:meta/meta.dart'; import 'helper_functions.dart'; import 'models/diff_img_result.dart'; class DiffImage { /// Returns a single number representing the difference between two RGB pixels static num _diffBetweenPixels({ - @required int firstPixel, - @required bool ignoreAlpha, - @required int secondPixel, + required int firstPixel, + required bool ignoreAlpha, + required int secondPixel, }) { var fRed = getRed(firstPixel); var fGreen = getGreen(firstPixel); @@ -100,9 +99,9 @@ class DiffImage { secondPixel = secondImg.getPixel(i, j); diffAtPixel = _diffBetweenPixels( - firstPixel: firstPixel, + firstPixel: firstPixel.toInt(), ignoreAlpha: ignoreAlpha, - secondPixel: secondPixel, + secondPixel: secondPixel.toInt(), ); diff += diffAtPixel; @@ -112,8 +111,8 @@ class DiffImage { j, selectColor( diffAtPixel: diffAtPixel, - firstPixel: firstPixel, - secondPixel: secondPixel, + firstPixel: firstPixel.toInt(), + secondPixel: secondPixel.toInt(), ), ); } @@ -132,7 +131,7 @@ class DiffImage { /// Function to store an [Image] object as PNG in local storage. /// Not supported on web. static Future saveDiffImg({ - @required Image diffImg, + required Image diffImg, }) async { // TODO Define if can download image file or just show throw UnsupportedError( diff --git a/lib/src/diff_image_io.dart b/lib/src/diff_image_io.dart index 67549b6..ff3bf61 100644 --- a/lib/src/diff_image_io.dart +++ b/lib/src/diff_image_io.dart @@ -1,16 +1,15 @@ import 'dart:io' as io; import 'package:image/image.dart'; -import 'package:meta/meta.dart'; import 'helper_functions.dart'; import 'models/diff_img_result.dart'; class DiffImage { /// Returns a single number representing the difference between two RGB pixels static num _diffBetweenPixels({ - @required int firstPixel, - @required bool ignoreAlpha, - @required int secondPixel, + required int firstPixel, + required bool ignoreAlpha, + required int secondPixel, }) { var fRed = getRed(firstPixel); var fGreen = getGreen(firstPixel); @@ -43,8 +42,8 @@ class DiffImage { /// /// Can throw an [Exception]. static Future compareFromUrl( - dynamic firstImgSrc, - dynamic secondImgSrc, { + Uri firstImgSrc, + Uri secondImgSrc, { bool asPercentage = true, bool ignoreAlpha = true, }) async { @@ -102,9 +101,9 @@ class DiffImage { secondPixel = secondImg.getPixel(i, j); diffAtPixel = _diffBetweenPixels( - firstPixel: firstPixel, + firstPixel: firstPixel.toInt(), ignoreAlpha: ignoreAlpha, - secondPixel: secondPixel, + secondPixel: secondPixel.toInt(), ); diff += diffAtPixel; @@ -114,8 +113,8 @@ class DiffImage { j, selectColor( diffAtPixel: diffAtPixel, - firstPixel: firstPixel, - secondPixel: secondPixel, + firstPixel: firstPixel.toInt(), + secondPixel: secondPixel.toInt(), ), ); } @@ -134,7 +133,7 @@ class DiffImage { /// Function to store an [Image] object as PNG in local storage. /// Not supported on web. static Future saveDiffImg({ - @required Image diffImg, + required Image diffImg, }) async { await io.File('DiffImg.png').writeAsBytes( encodePng(diffImg), diff --git a/lib/src/helper_functions.dart b/lib/src/helper_functions.dart index 0a0a0a3..f1abfa4 100644 --- a/lib/src/helper_functions.dart +++ b/lib/src/helper_functions.dart @@ -1,11 +1,10 @@ import 'package:http/http.dart' as http; import 'package:image/image.dart'; -import 'package:meta/meta.dart'; /// Through http get request to [imgSrc] obtains the bytes /// that make up an image. Can throw an [Exception]. -Future getImg({@required dynamic imgSrc}) async { - Image img; +Future getImg({required Uri imgSrc}) async { + Image? img; var response = await http.get(imgSrc); if (response.statusCode != 200) { @@ -26,8 +25,8 @@ Future getImg({@required dynamic imgSrc}) async { /// Check if [firstImg] and [secondImg] have the same width and height. bool haveSameSize({ - @required Image firstImg, - @required Image secondImg, + required Image firstImg, + required Image secondImg, }) { return firstImg.width == secondImg.width && firstImg.height == secondImg.height; @@ -37,9 +36,9 @@ bool haveSameSize({ /// If one of the pixels is black, the resulting color will be the /// other pixel but more transparent. int selectColor({ - @required num diffAtPixel, - @required int firstPixel, - @required int secondPixel, + required num diffAtPixel, + required int firstPixel, + required int secondPixel, }) { int result; diff --git a/lib/src/models/diff_img_result.dart b/lib/src/models/diff_img_result.dart index 117aac3..dd5c435 100644 --- a/lib/src/models/diff_img_result.dart +++ b/lib/src/models/diff_img_result.dart @@ -1,12 +1,11 @@ import 'package:image/image.dart'; -import 'package:meta/meta.dart'; /// Model to encapsulate the results of a difference between images /// query. class DiffImgResult { DiffImgResult({ - @required this.diffImg, - @required this.diffValue, + required this.diffImg, + required this.diffValue, }); final Image diffImg; diff --git a/pubspec.yaml b/pubspec.yaml index 4a5ebcb..7d5d0ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,14 +4,12 @@ version: 1.0.1 homepage: https://github.com/limonadev/diff_image environment: - sdk: '>=2.5.0 <3.0.0' + sdk: ">=2.15.0 <3.0.0" dependencies: - http: ^0.12.2 - image: ^2.1.18 - meta: ^1.1.8 + http: ^0.13.5 + image: ^3.2.0 # path: ^1.6.0 dev_dependencies: - pedantic: ^1.8.0 - test: ^1.15.4 + test: ^1.21.4 diff --git a/test/helper_test.dart b/test/helper_test.dart index d7f2f11..c1de9e5 100644 --- a/test/helper_test.dart +++ b/test/helper_test.dart @@ -1,13 +1,12 @@ @TestOn('vm') -import 'package:test/test.dart'; -import 'package:image/image.dart'; - import 'package:diff_image/src/helper_functions.dart'; +import 'package:image/image.dart'; +import 'package:test/test.dart'; void main() { group('Test for helper functions', () { - String flutterLogoUrl, badUrl, anotherLogoUrl; + late String flutterLogoUrl, badUrl, anotherLogoUrl; setUp(() { // A real image @@ -22,13 +21,13 @@ void main() { test('Get image from url', () async { var first = await getImg( - imgSrc: flutterLogoUrl, + imgSrc: Uri.parse(flutterLogoUrl), ); expect(first, isA()); expect( () async { await getImg( - imgSrc: badUrl, + imgSrc: Uri.parse(badUrl), ); }, throwsException, @@ -37,7 +36,7 @@ void main() { test('Compare images size', () async { var img1 = await getImg( - imgSrc: flutterLogoUrl, + imgSrc: Uri.parse(flutterLogoUrl), ); var areEquals = haveSameSize( firstImg: img1, @@ -46,7 +45,7 @@ void main() { expect(areEquals, isTrue); var img2 = await getImg( - imgSrc: anotherLogoUrl, + imgSrc: Uri.parse(anotherLogoUrl), ); areEquals = haveSameSize( firstImg: img1, diff --git a/test/html_test.dart b/test/html_test.dart index 3357a91..7307d53 100644 --- a/test/html_test.dart +++ b/test/html_test.dart @@ -6,18 +6,18 @@ import 'package:test/test.dart'; void main() { group('Test when dart:html is supported', () { - String flutterLogoUrl, dartLogoUrl, androidLogoUrl; + late Uri flutterLogoUrl, dartLogoUrl, androidLogoUrl; setUp(() { // A real image - flutterLogoUrl = - 'https://seeklogo.com/images/F/flutter-logo-5086DD11C5-seeklogo.com.png'; + flutterLogoUrl = Uri.parse( + 'https://seeklogo.com/images/F/flutter-logo-5086DD11C5-seeklogo.com.png'); // Image with different size with respect to flutterLogoUrl - dartLogoUrl = - 'https://www.extremetech.com/wp-content/uploads/2011/10/dart-logo-banner1-348x196.jpg'; + dartLogoUrl = Uri.parse( + 'https://www.extremetech.com/wp-content/uploads/2011/10/dart-logo-banner1-348x196.jpg'); // Image with the same size as flutterLogoUrl - androidLogoUrl = - 'https://seeklogo.com/images/A/android-western-logo-8F117A7F00-seeklogo.com.png'; + androidLogoUrl = Uri.parse( + 'https://seeklogo.com/images/A/android-western-logo-8F117A7F00-seeklogo.com.png'); }); test('Compare the same image', () async { diff --git a/test/io_test.dart b/test/io_test.dart index 153b14d..c93d825 100644 --- a/test/io_test.dart +++ b/test/io_test.dart @@ -1,23 +1,23 @@ @TestOn('vm') -import 'package:test/test.dart'; import 'package:diff_image/diff_image.dart'; import 'package:diff_image/src/helper_functions.dart'; +import 'package:test/test.dart'; void main() { group('Test when dart:io is supported', () { - String flutterLogoUrl, dartLogoUrl, androidLogoUrl; + late Uri flutterLogoUrl, dartLogoUrl, androidLogoUrl; setUp(() { // A real image - flutterLogoUrl = - 'https://seeklogo.com/images/F/flutter-logo-5086DD11C5-seeklogo.com.png'; + flutterLogoUrl = Uri.parse( + 'https://seeklogo.com/images/F/flutter-logo-5086DD11C5-seeklogo.com.png'); // Image with different size with respect to flutterLogoUrl - dartLogoUrl = - 'https://www.extremetech.com/wp-content/uploads/2011/10/dart-logo-banner1-348x196.jpg'; + dartLogoUrl = Uri.parse( + 'https://www.extremetech.com/wp-content/uploads/2011/10/dart-logo-banner1-348x196.jpg'); // Image with the same size as flutterLogoUrl - androidLogoUrl = - 'https://seeklogo.com/images/A/android-western-logo-8F117A7F00-seeklogo.com.png'; + androidLogoUrl = Uri.parse( + 'https://seeklogo.com/images/A/android-western-logo-8F117A7F00-seeklogo.com.png'); }); test('Compare the same image', () async {