From c3a1d6de88e9654b28f480f41279c6f6ca8b2e60 Mon Sep 17 00:00:00 2001 From: "Josh.Lu" <> Date: Wed, 24 Mar 2021 09:47:12 +0800 Subject: [PATCH] =?UTF-8?q?update=20:=20=E6=94=AF=E6=8C=81flutter=202.0?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/vcs.xml | 1 + .idea/workspace.xml | 41 ++++++++++++---- CHANGELOG.md | 5 ++ README.md | 79 +++++++++++++++++-------------- example/lib/main.dart | 3 ++ example/pubspec.lock | 76 ++++++++++++----------------- lib/loader/image_with_loader.dart | 36 +++++++------- lib/widget/nine_old_widget.dart | 5 +- pubspec.lock | 74 ++++++++++++----------------- pubspec.yaml | 10 ++-- 10 files changed, 170 insertions(+), 160 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..0fc7ecb 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 562d874..3df14b2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,19 @@ + + + + + + + + + + + + - - + + + + + + - - + + + - - + + + - - + + + - - + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d9fba6..bf02d26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0 + +1.更新pub依赖以及flutter版本 +2.支持图片加载失败自定义显示 + ## 1.3.4 1.更新pub依赖以及flutter版本 diff --git a/README.md b/README.md index 3efeb0b..fdf9400 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,18 @@ ``` dependencies: ... - nineold: ^1.3.4 + nineold: ^2.0.0 ``` 关于如何运行flutter项目, 参考官方文档[documentation](https://flutter.io/). # 版本更新 +## 2.0.0 + +1.更新pub依赖以及flutter版本 +2.支持图片加载失败自定义显示 + ## 1.3.4 @@ -103,39 +108,42 @@ class _MyHomePageState extends State { } Widget _buildActiveItem(int index, List photos) { - return Container( - margin: EdgeInsets.all(10), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - _buildActiveItemHeader(index), - null != photos || photos.isNotEmpty - ? NineOldWidget( - images: photos, - //必填 - onLongPressListener: (position) { - //可选 - //长按事件回调 - print("长按事件回调当前位置 : $position"); - }, - backgroundColor: Colors.white, - //可选 - //加载背景颜色 - valueColor: Colors.red, - //可选 - //加载进度条颜色 - strokeWidth: 4, - //可选 - //加载进度条宽度 - moreStyle: - TextStyle(fontSize: 28, color: Colors.orange), //更多加号样式 - ) - : SizedBox() - ], - ), - ); - } + return Container( + margin: EdgeInsets.all(10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + _buildActiveItemHeader(index), + null != photos || photos.isNotEmpty + ? NineOldWidget( + images: photos, + //必填 + onLongPressListener: (position) { + //可选 + //长按事件回调 + print("长按事件回调当前位置 : $position"); + }, + backgroundColor: Colors.white, + //可选 + //加载背景颜色 + valueColor: Colors.red, + //可选 + //加载进度条颜色 + strokeWidth: 4, + //可选 + //加载进度条宽度 + moreStyle: + TextStyle(fontSize: 28, color: Colors.orange), //更多加号样式 + //可选 + //资源加载失败显示 + errorWidget: Icon(Icons.error_outline_rounded), + ) + : SizedBox() + ], + ), + ); + } Widget _buildActiveItemHeader(int index) { return Container( @@ -211,7 +219,8 @@ NineOldWidget控件构造方法以及参数设置 this.backgroundColor = Colors.white, this.strokeWidth = 3, this.valueColor = Colors.tealAccent, - this.onLongPressListener}); + this.onLongPressListener, + this.errorWidget}); ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index a247145..f96c549 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -84,6 +84,9 @@ class _MyHomePageState extends State { //加载进度条宽度 moreStyle: TextStyle(fontSize: 28, color: Colors.orange), //更多加号样式 + //可选 + //资源加载失败显示 + errorWidget: Icon(Icons.error_outline_rounded), ) : SizedBox() ], diff --git a/example/pubspec.lock b/example/pubspec.lock index 18990eb..29ea2b0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,77 +7,63 @@ packages: name: archive url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.13" - args: - dependency: transitive - description: - name: args - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.6.0" + version: "3.1.2" async: dependency: transitive description: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" cached_network_image: dependency: transitive description: name: cached_network_image url: "https://pub.flutter-io.cn" source: hosted - version: "2.5.0" + version: "2.5.1" characters: dependency: transitive description: name: characters url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.15.0-nullsafety.3" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.1" + version: "1.15.0" crypto: dependency: transitive description: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.5" + version: "3.0.0" cupertino_icons: dependency: "direct main" description: @@ -91,7 +77,7 @@ packages: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" ffi: dependency: transitive description: @@ -124,7 +110,7 @@ packages: name: flutter_cache_manager url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "2.1.2" flutter_test: dependency: "direct dev" description: flutter @@ -150,7 +136,7 @@ packages: name: image url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.19" + version: "3.0.2" intl: dependency: transitive description: @@ -164,21 +150,21 @@ packages: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" nineold: dependency: "direct dev" description: path: ".." relative: true source: path - version: "1.3.4" + version: "2.0.0" octo_image: dependency: transitive description: @@ -192,7 +178,7 @@ packages: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" path_provider: dependency: transitive description: @@ -241,14 +227,14 @@ packages: name: petitparser url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.0" + version: "4.0.2" photo_view: dependency: transitive description: name: photo_view url: "https://pub.flutter-io.cn" source: hosted - version: "0.10.3" + version: "0.11.1" platform: dependency: transitive description: @@ -288,7 +274,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" sqflite: dependency: transitive description: @@ -309,21 +295,21 @@ packages: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" synchronized: dependency: transitive description: @@ -337,42 +323,42 @@ packages: name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" transparent_image: dependency: transitive description: name: transparent_image url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.0" + version: "2.0.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" uuid: dependency: transitive description: name: uuid url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.2" + version: "3.0.2" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" win32: dependency: transitive description: @@ -393,7 +379,7 @@ packages: name: xml url: "https://pub.flutter-io.cn" source: hosted - version: "4.5.1" + version: "5.0.2" sdks: - dart: ">=2.10.2 <2.11.0" - flutter: ">=1.22.2 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.22.2" diff --git a/lib/loader/image_with_loader.dart b/lib/loader/image_with_loader.dart index 8c7f499..9bd96c1 100644 --- a/lib/loader/image_with_loader.dart +++ b/lib/loader/image_with_loader.dart @@ -1,3 +1,4 @@ +import 'package:cached_network_image/cached_network_image.dart'; import "package:flutter/material.dart"; import 'package:transparent_image/transparent_image.dart'; @@ -7,6 +8,7 @@ class ImageWithLoader extends StatelessWidget { @required this.backgroundColor, @required this.strokeWidth, @required this.valueColor, + this.errorWidget, this.fit = BoxFit.cover, this.loaderSize = 48.0}); @@ -17,6 +19,7 @@ class ImageWithLoader extends StatelessWidget { final Color backgroundColor; final double strokeWidth; final Color valueColor; + final Widget errorWidget; @override Widget build(BuildContext context) { @@ -26,32 +29,25 @@ class ImageWithLoader extends StatelessWidget { children: [ Container( color: Colors.grey, - child: Center( + ), + CachedNetworkImage( + imageUrl: url, + fit: fit, + placeholder: (context, url) => Center( child: SizedBox( width: loaderSize, height: loaderSize, - child: _buildCircularProgressIndicator( - cpBackgroundColor: backgroundColor, - cpStrokeWidth: strokeWidth, - cpValueColor: valueColor), + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation(valueColor), + backgroundColor: backgroundColor, + strokeWidth: strokeWidth, + ), ), ), - ), - FadeInImage.memoryNetwork( - image: url, - fit: fit, - placeholder: kTransparentImage, - ), + errorWidget: (context, url, error) => + null == errorWidget ? Icon(Icons.error) : errorWidget, + ) ], ); } } - -CircularProgressIndicator _buildCircularProgressIndicator( - {Color cpBackgroundColor, double cpStrokeWidth, Color cpValueColor}) { - return CircularProgressIndicator( - backgroundColor: cpBackgroundColor, - strokeWidth: cpStrokeWidth, - valueColor: AlwaysStoppedAnimation(cpValueColor), - ); -} diff --git a/lib/widget/nine_old_widget.dart b/lib/widget/nine_old_widget.dart index f27fe8f..4583f3c 100644 --- a/lib/widget/nine_old_widget.dart +++ b/lib/widget/nine_old_widget.dart @@ -10,6 +10,7 @@ class NineOldWidget extends StatelessWidget { final Color backgroundColor; final double strokeWidth; final Color valueColor; + final Widget errorWidget; final OnLongPressCallback onLongPressListener; @@ -22,7 +23,8 @@ class NineOldWidget extends StatelessWidget { this.backgroundColor = Colors.white, this.strokeWidth = 3, this.valueColor = Colors.tealAccent, - this.onLongPressListener}); + this.onLongPressListener, + this.errorWidget}); double width; double height; @@ -402,6 +404,7 @@ class NineOldWidget extends StatelessWidget { backgroundColor: backgroundColor, valueColor: valueColor, strokeWidth: strokeWidth, + errorWidget: errorWidget, ), )), onTap: () { diff --git a/pubspec.lock b/pubspec.lock index 3f1a165..7616b6e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,84 +7,70 @@ packages: name: archive url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.13" - args: - dependency: transitive - description: - name: args - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.6.0" + version: "3.1.2" async: dependency: transitive description: name: async url: "https://pub.flutter-io.cn" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" cached_network_image: dependency: "direct main" description: name: cached_network_image url: "https://pub.flutter-io.cn" source: hosted - version: "2.5.0" + version: "2.5.1" characters: dependency: transitive description: name: characters url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.flutter-io.cn" source: hosted - version: "1.15.0-nullsafety.3" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.1" + version: "1.15.0" crypto: dependency: transitive description: name: crypto url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.5" + version: "3.0.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" ffi: dependency: transitive description: @@ -117,7 +103,7 @@ packages: name: flutter_cache_manager url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0" + version: "2.1.2" flutter_test: dependency: "direct dev" description: flutter @@ -143,7 +129,7 @@ packages: name: image url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.19" + version: "3.0.2" intl: dependency: transitive description: @@ -157,14 +143,14 @@ packages: name: matcher url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" octo_image: dependency: transitive description: @@ -178,7 +164,7 @@ packages: name: path url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" path_provider: dependency: transitive description: @@ -227,14 +213,14 @@ packages: name: petitparser url: "https://pub.flutter-io.cn" source: hosted - version: "3.1.0" + version: "4.0.2" photo_view: dependency: "direct main" description: name: photo_view url: "https://pub.flutter-io.cn" source: hosted - version: "0.10.3" + version: "0.11.1" platform: dependency: transitive description: @@ -274,7 +260,7 @@ packages: name: source_span url: "https://pub.flutter-io.cn" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" sqflite: dependency: transitive description: @@ -295,21 +281,21 @@ packages: name: stack_trace url: "https://pub.flutter-io.cn" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.flutter-io.cn" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" synchronized: dependency: transitive description: @@ -323,42 +309,42 @@ packages: name: term_glyph url: "https://pub.flutter-io.cn" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" transparent_image: dependency: "direct main" description: name: transparent_image url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.0" + version: "2.0.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.flutter-io.cn" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" uuid: dependency: "direct main" description: name: uuid url: "https://pub.flutter-io.cn" source: hosted - version: "2.2.2" + version: "3.0.2" vector_math: dependency: transitive description: name: vector_math url: "https://pub.flutter-io.cn" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" win32: dependency: transitive description: @@ -379,7 +365,7 @@ packages: name: xml url: "https://pub.flutter-io.cn" source: hosted - version: "4.5.1" + version: "5.0.2" sdks: - dart: ">=2.10.2 <2.11.0" - flutter: ">=1.22.2 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.22.2" diff --git a/pubspec.yaml b/pubspec.yaml index 752d73c..97225bf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: nineold description: Nineoldwidget is a component used to encapsulate the nine palace display of pictures. -version: 1.3.4 +version: 2.0.0 homepage: https://github.com/lanzhu1993/flutter_nineold environment: @@ -10,10 +10,10 @@ environment: dependencies: flutter: sdk: flutter - transparent_image: ^1.0.0 - photo_view: ^0.10.3 - cached_network_image: ^2.5.0 - uuid: ^2.2.2 + transparent_image: ^2.0.0 + photo_view: ^0.11.1 + cached_network_image: ^2.5.1 + uuid: ^3.0.2 dev_dependencies: flutter_test: