From f6f69b21a5c40a5a2e8cc324579aad670b0f39e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=A0=E6=96=87=E8=BD=A9?= <12812285557@qq.com> Date: Thu, 26 May 2022 14:48:33 +0800 Subject: [PATCH] null safe --- .../ios/Flutter/flutter_export_environment.sh | 14 ++++ example/pubspec.lock | 67 ++++++++++--------- lib/flutter_gifimage.dart | 52 +++++++------- pubspec.lock | 17 +++-- pubspec.yaml | 2 +- 5 files changed, 90 insertions(+), 62 deletions(-) create mode 100755 example/ios/Flutter/flutter_export_environment.sh diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..5be25e2 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Applications/sdk/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/datang/flutter_gifimage/example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/example/pubspec.lock b/example/pubspec.lock index 9b9a4ec..df1a849 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,28 +7,42 @@ packages: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.3.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.2" + version: "1.2.0" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.14.11" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -36,6 +50,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.1.2" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -59,35 +80,21 @@ packages: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.5" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.7" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.8.0+1" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -99,55 +106,55 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.5" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.8" + version: "2.1.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/lib/flutter_gifimage.dart b/lib/flutter_gifimage.dart index 4fefcf0..1d0e7a5 100644 --- a/lib/flutter_gifimage.dart +++ b/lib/flutter_gifimage.dart @@ -15,14 +15,14 @@ import 'package:flutter/widgets.dart'; /// cache gif fetched image class GifCache{ - final Map> caches= Map(); + final Map?> caches= Map(); void clear() { caches.clear(); } bool evict(Object key) { - final List pendingImage = caches.remove(key); + final List? pendingImage = caches.remove(key); if(pendingImage!=null){ return true; } @@ -34,11 +34,11 @@ class GifCache{ class GifController extends AnimationController{ GifController({ - @required TickerProvider vsync, + required TickerProvider vsync, double value=0.0, - Duration reverseDuration, - Duration duration, - AnimationBehavior animationBehavior + Duration? reverseDuration, + Duration? duration, + AnimationBehavior? animationBehavior }):super.unbounded( value:value, reverseDuration:reverseDuration, @@ -57,8 +57,8 @@ class GifController extends AnimationController{ class GifImage extends StatefulWidget{ GifImage({ - @required this.image, - @required this.controller, + required this.image, + required this.controller, this.semanticLabel, this.excludeFromSemantics = false, this.width, @@ -73,20 +73,20 @@ class GifImage extends StatefulWidget{ this.matchTextDirection = false, this.gaplessPlayback = false, }); - final VoidCallback onFetchCompleted; + final VoidCallback? onFetchCompleted; final GifController controller; final ImageProvider image; - final double width; - final double height; - final Color color; - final BlendMode colorBlendMode; - final BoxFit fit; + final double? width; + final double? height; + final Color? color; + final BlendMode? colorBlendMode; + final BoxFit? fit; final AlignmentGeometry alignment; final ImageRepeat repeat; - final Rect centerSlice; + final Rect? centerSlice; final bool matchTextDirection; final bool gaplessPlayback; - final String semanticLabel; + final String? semanticLabel; final bool excludeFromSemantics; @override @@ -98,12 +98,12 @@ class GifImage extends StatefulWidget{ } class GifImageState extends State{ - List _infos; + List? _infos; int _curIndex = 0; bool _fetchComplete= false; - ImageInfo get _imageInfo { + ImageInfo? get _imageInfo { if(!_fetchComplete)return null; - return _infos==null?null:_infos[_curIndex]; + return _infos==null?null:_infos![_curIndex]; } @@ -131,7 +131,7 @@ class GifImageState extends State{ _fetchComplete=true; _curIndex = widget.controller.value.toInt(); if(widget.onFetchCompleted!=null){ - widget.onFetchCompleted(); + widget.onFetchCompleted!(); } }); }); @@ -162,7 +162,7 @@ class GifImageState extends State{ _fetchComplete=true; _curIndex = widget.controller.value.toInt(); if(widget.onFetchCompleted!=null){ - widget.onFetchCompleted(); + widget.onFetchCompleted!(); } }); }); @@ -203,16 +203,16 @@ HttpClient get _httpClient { HttpClient client = _sharedHttpClient; assert(() { if (debugNetworkImageHttpClientProvider != null) - client = debugNetworkImageHttpClientProvider(); + client = debugNetworkImageHttpClientProvider!(); return true; }()); return client; } -Future> fetchGif(ImageProvider provider) async{ - List infos = []; - dynamic data; +Future?> fetchGif(ImageProvider provider) async{ + List? infos = []; + late dynamic data; String key =provider is NetworkImage?provider.url:provider is AssetImage?provider.assetName:provider is MemoryImage?provider.bytes.toString():""; if(GifImage.cache.caches.containsKey(key)){ infos = GifImage.cache.caches[key]; @@ -240,7 +240,7 @@ Future> fetchGif(ImageProvider provider) async{ data = provider.bytes; } - ui.Codec codec=await PaintingBinding.instance.instantiateImageCodec(data.buffer.asUint8List()); + ui.Codec codec=await PaintingBinding.instance!.instantiateImageCodec(data.buffer.asUint8List()); infos = []; for(int i = 0;i=2.2.2 <3.0.0" + dart: ">=2.12.0-0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index fd2a933..59da896 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ author: Jpeng homepage: https://github.com/peng8350/flutter_gifimage environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: