Skip to content

Commit 89cd1ac

Browse files
committed
fix something
1 parent a7d6e6e commit 89cd1ac

File tree

6 files changed

+121
-12
lines changed

6 files changed

+121
-12
lines changed

lib/bloc/base/base_bloc.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ abstract class BlocListBase extends BlocBase {
9090
doNext(res) async {
9191
if (res.next != null) {
9292
var resNext = await res.next;
93-
changeLoadMoreStatus(getLoadMoreStatus(resNext));
94-
refreshData(resNext);
93+
if(resNext != null && resNext.result) {
94+
changeLoadMoreStatus(getLoadMoreStatus(resNext));
95+
refreshData(resNext);
96+
}
9597
}
9698
}
9799

lib/main.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ import 'package:redux/redux.dart';
1818
import 'package:gsy_github_app_flutter/common/net/code.dart';
1919

2020
void main() {
21-
runApp(new FlutterReduxApp());
22-
PaintingBinding.instance.imageCache.maximumSize = 100;
21+
runZoned(() {
22+
runApp(FlutterReduxApp());
23+
PaintingBinding.instance.imageCache.maximumSize = 100;
24+
}, onError: (Object obj, StackTrace stack) {
25+
print(obj);
26+
print(stack);
27+
});
2328
}
2429

2530
class FlutterReduxApp extends StatelessWidget {

lib/widget/gsy_pull_new_load_widget.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,17 @@ class GSYPullLoadWidgetControl extends ChangeNotifier {
192192

193193
set dataList(List value) {
194194
_dataList.clear();
195-
_dataList.addAll(value);
196-
notifyListeners();
195+
if(value != null) {
196+
_dataList.addAll(value);
197+
notifyListeners();
198+
}
197199
}
198200

199201
addList(List value) {
200-
_dataList.addAll(value);
201-
notifyListeners();
202+
if(value != null) {
203+
_dataList.addAll(value);
204+
notifyListeners();
205+
}
202206
}
203207

204208
///是否需要加载更多

lib/widget/gsy_user_icon_widget.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:gsy_github_app_flutter/common/style/gsy_style.dart';
3+
import 'package:gsy_github_app_flutter/widget/network_cache_image.dart';
34

45
/**
56
* 头像Icon
@@ -23,11 +24,10 @@ class GSYUserIconWidget extends StatelessWidget {
2324
padding: padding ?? const EdgeInsets.only(top: 4.0, right: 5.0, left: 5.0),
2425
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
2526
child: new ClipOval(
26-
child: new FadeInImage.assetNetwork(
27-
placeholder: GSYICons.DEFAULT_USER_ICON,
27+
child: Image(
28+
image: NetworkCacheImage(image),
2829
//预览图
2930
fit: BoxFit.fitWidth,
30-
image: image,
3131
width: width,
3232
height: height,
3333
),
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import 'dart:io';
2+
import 'dart:typed_data';
3+
4+
import 'package:flutter/foundation.dart';
5+
import 'package:flutter/material.dart';
6+
import 'dart:ui' as ui show Codec;
7+
8+
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
9+
10+
/**
11+
* Created by guoshuyu
12+
* on 2019/4/13.
13+
*/
14+
class NetworkCacheImage extends ImageProvider<NetworkCacheImage> {
15+
/// Creates an object that fetches the image at the given URL.
16+
///
17+
/// The arguments must not be null.
18+
const NetworkCacheImage(this.url, { this.scale = 1.0, this.headers })
19+
: assert(url != null),
20+
assert(scale != null);
21+
22+
/// The URL from which the image will be fetched.
23+
final String url;
24+
25+
/// The scale to place in the [ImageInfo] object of the image.
26+
final double scale;
27+
28+
/// The HTTP headers that will be used with [HttpClient.get] to fetch image from network.
29+
final Map<String, String> headers;
30+
31+
@override
32+
Future<NetworkCacheImage> obtainKey(ImageConfiguration configuration) {
33+
return SynchronousFuture<NetworkCacheImage>(this);
34+
}
35+
36+
@override
37+
ImageStreamCompleter load(NetworkCacheImage key) {
38+
return MultiFrameImageStreamCompleter(
39+
codec: _loadAsync(key),
40+
scale: key.scale,
41+
informationCollector: (StringBuffer information) {
42+
information.writeln('Image provider: $this');
43+
information.write('Image key: $key');
44+
},
45+
);
46+
}
47+
48+
static final HttpClient _httpClient = HttpClient();
49+
50+
Future<ui.Codec> _loadAsync(NetworkCacheImage key) async {
51+
assert(key == this);
52+
53+
/// add this start
54+
/// flutter_cache_manager DefaultCacheManager
55+
final fileInfo = await DefaultCacheManager().getFileFromCache(key.url);
56+
if(fileInfo != null && fileInfo.file != null) {
57+
final Uint8List cacheBytes = await fileInfo.file.readAsBytes();
58+
if (cacheBytes != null) {
59+
return PaintingBinding.instance.instantiateImageCodec(cacheBytes);
60+
}
61+
}
62+
/// add this end
63+
64+
final Uri resolved = Uri.base.resolve(key.url);
65+
final HttpClientRequest request = await _httpClient.getUrl(resolved);
66+
headers?.forEach((String name, String value) {
67+
request.headers.add(name, value);
68+
});
69+
final HttpClientResponse response = await request.close();
70+
if (response.statusCode != HttpStatus.ok)
71+
throw Exception('HTTP request failed, statusCode: ${response?.statusCode}, $resolved');
72+
73+
final Uint8List bytes = await consolidateHttpClientResponseBytes(response);
74+
if (bytes.lengthInBytes == 0)
75+
throw Exception('NetworkCacheImage is an empty file: $resolved');
76+
77+
/// add this start
78+
await DefaultCacheManager().putFile(key.url, bytes);
79+
/// add this edn
80+
81+
return PaintingBinding.instance.instantiateImageCodec(bytes);
82+
}
83+
84+
@override
85+
bool operator ==(dynamic other) {
86+
if (other.runtimeType != runtimeType)
87+
return false;
88+
final NetworkCacheImage typedOther = other;
89+
return url == typedOther.url
90+
&& scale == typedOther.scale;
91+
}
92+
93+
@override
94+
int get hashCode => hashValues(url, scale);
95+
96+
@override
97+
String toString() => '$runtimeType("$url", scale: $scale)';
98+
}

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ packages:
318318
name: intl
319319
url: "https://pub.flutter-io.cn"
320320
source: hosted
321-
version: "0.15.7"
321+
version: "0.15.8"
322322
io:
323323
dependency: transitive
324324
description:

0 commit comments

Comments
 (0)