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

Migrate to null-safety #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions example/lib/main.dart

Large diffs are not rendered by default.

103 changes: 55 additions & 48 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,58 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
version: "1.15.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -47,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1"
version: "1.1.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -57,37 +78,23 @@ packages:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.5"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
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"
url: "https://pub.dartlang.org"
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
Expand All @@ -97,57 +104,57 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
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"
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ description: A new Flutter project.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
version: 1.1.0

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down
48 changes: 24 additions & 24 deletions lib/flutter_gifimage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GifCache{
}

bool evict(Object key) {
final List<ImageInfo> pendingImage = caches.remove(key);
final List<ImageInfo>? pendingImage = caches.remove(key);
if(pendingImage!=null){
return true;
}
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -98,12 +98,12 @@ class GifImage extends StatefulWidget{
}

class GifImageState extends State<GifImage>{
List<ImageInfo> _infos;
List<ImageInfo>? _infos;
int _curIndex = 0;
bool _fetchComplete= false;
ImageInfo get _imageInfo {
if(!_fetchComplete)return null;
return _infos==null?null:_infos[_curIndex];
ImageInfo? get _imageInfo {
if(!_fetchComplete) return null;
return _infos==null ? null : _infos![_curIndex];
}


Expand Down Expand Up @@ -131,7 +131,7 @@ class GifImageState extends State<GifImage>{
_fetchComplete=true;
_curIndex = widget.controller.value.toInt();
if(widget.onFetchCompleted!=null){
widget.onFetchCompleted();
widget.onFetchCompleted!();
}
});
});
Expand Down Expand Up @@ -162,7 +162,7 @@ class GifImageState extends State<GifImage>{
_fetchComplete=true;
_curIndex = widget.controller.value.toInt();
if(widget.onFetchCompleted!=null){
widget.onFetchCompleted();
widget.onFetchCompleted!();
}
});
});
Expand Down Expand Up @@ -203,7 +203,7 @@ HttpClient get _httpClient {
HttpClient client = _sharedHttpClient;
assert(() {
if (debugNetworkImageHttpClientProvider != null)
client = debugNetworkImageHttpClientProvider();
client = debugNetworkImageHttpClientProvider!();
return true;
}());
return client;
Expand All @@ -215,7 +215,7 @@ Future<List<ImageInfo>> fetchGif(ImageProvider provider) async{
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];
infos = GifImage.cache.caches[key]!;
return infos;
}
if(provider is NetworkImage){
Expand All @@ -240,7 +240,7 @@ Future<List<ImageInfo>> 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<codec.frameCount;i++){
FrameInfo frameInfo = await codec.getNextFrame();
Expand Down
25 changes: 16 additions & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
version: "1.15.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -17,9 +24,9 @@ packages:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.7"
version: "1.3.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -29,15 +36,15 @@ packages:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
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"
Loading