Browse Source

动态列表视频优化

ff_new
w-R 3 years ago
parent
commit
95baeeb134
  1. 3
      ios/Podfile.lock
  2. 3
      lib/community/community_details.dart
  3. 28
      lib/community/community_page.dart
  4. 30
      lib/community/community_view/class_details_video.dart
  5. 10
      lib/community/headlines/article_list.dart
  6. 19
      lib/community/photo_view_gallery_screen.dart
  7. 5
      lib/main.dart
  8. 78
      lib/store/store_order.dart
  9. 35
      lib/utils/ImgCachePath.dart
  10. 87
      lib/view_widget/custom_image.dart
  11. 51
      pubspec.lock
  12. 2
      pubspec.yaml

3
ios/Podfile.lock

@ -143,6 +143,9 @@ PODS:
- mob_sharesdk/ShareSDKPlatforms/WatermelonVideo (4.4.0): - mob_sharesdk/ShareSDKPlatforms/WatermelonVideo (4.4.0):
- mob_sharesdk/ShareSDK - mob_sharesdk/ShareSDK
- MOBFoundation (>= 3.2.9) - MOBFoundation (>= 3.2.9)
- mob_sharesdk/ShareSDKPlatforms/WeChat_Lite (4.4.0):
- mob_sharesdk/ShareSDK
- MOBFoundation (>= 3.2.9)
- mob_sharesdk/ShareSDKPlatforms/WhatsApp (4.4.0): - mob_sharesdk/ShareSDKPlatforms/WhatsApp (4.4.0):
- mob_sharesdk/ShareSDK - mob_sharesdk/ShareSDK
- MOBFoundation (>= 3.2.9) - MOBFoundation (>= 3.2.9)

3
lib/community/community_details.dart

@ -6,7 +6,6 @@ import 'package:huixiang/generated/l10n.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/retrofit/data/article.dart'; import 'package:huixiang/retrofit/data/article.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/comunity_comment.dart';
import 'package:huixiang/retrofit/data/member_comment_list.dart'; import 'package:huixiang/retrofit/data/member_comment_list.dart';
import 'package:huixiang/retrofit/data/page.dart'; import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
@ -14,7 +13,6 @@ import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/tips_dialog.dart'; import 'package:huixiang/view_widget/tips_dialog.dart';
import 'package:huixiang/web/web_view/comment_list.dart'; import 'package:huixiang/web/web_view/comment_list.dart';
import 'package:huixiang/web/web_view/input_comment.dart'; import 'package:huixiang/web/web_view/input_comment.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class CommunityDetails extends StatefulWidget { class CommunityDetails extends StatefulWidget {
@ -100,7 +98,6 @@ class _CommunityDetails extends State<CommunityDetails> with WidgetsBindingObser
setState(() { setState(() {
article = baseData.data; article = baseData.data;
}); });
} else {
} }
} }

28
lib/community/community_page.dart

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/community/community_child_list.dart';
import 'package:huixiang/community/community_child_page.dart'; import 'package:huixiang/community/community_child_page.dart';
import 'package:huixiang/home/huixiang_brand_page.dart'; import 'package:huixiang/home/huixiang_brand_page.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
@ -39,9 +40,20 @@ class _CommunityPage extends State<CommunityPage>
tabcontroller = TabController(length: lables.length, vsync: this, initialIndex: 1); tabcontroller = TabController(length: lables.length, vsync: this, initialIndex: 1);
} }
_toRelease() async {
var result = await Navigator.of(context).pushNamed('/router/release_dynamic');
// int tmpIndex = tabcontroller.index;
// setState(() {
// tabcontroller.index = (tabcontroller.index == lables.length -1)?0:tabcontroller.index+1;
// });
// setState(() {
// tabcontroller.index = tmpIndex;
// });
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("createState createState createState ......");
return Scaffold( return Scaffold(
appBar: MyAppBar( appBar: MyAppBar(
leading: false, leading: false,
@ -72,7 +84,7 @@ class _CommunityPage extends State<CommunityPage>
), ),
), ),
onTap: () { onTap: () {
Navigator.of(context).pushNamed('/router/release_dynamic'); _toRelease();
}, },
action: GestureDetector( action: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
@ -98,16 +110,8 @@ class _CommunityPage extends State<CommunityPage>
}else if(e == "课程"){ }else if(e == "课程"){
return CommunityCourse(); return CommunityCourse();
} }
else if(e == "关注"){ else {
if (guanzhu == null ){ return CommunityChildList(e);
guanzhu = CommunityChildPage("关注");;
}
return guanzhu;
}else if(e == "推荐"){
if (tuijian == null){
tuijian = CommunityChildPage("推荐");
}
return tuijian;
} }
}).toList(), }).toList(),
controller: tabcontroller, controller: tabcontroller,

30
lib/community/community_view/class_details_video.dart

@ -11,6 +11,7 @@ class ClassDetailsVideo extends StatefulWidget {
final bool isShowImg; final bool isShowImg;
final Function exitFull; final Function exitFull;
final String coverImg; final String coverImg;
final String videoUrl;
ClassDetailsVideo( ClassDetailsVideo(
{ {
@ -19,7 +20,8 @@ class ClassDetailsVideo extends StatefulWidget {
this.isShowImg, this.isShowImg,
this.exitFull, this.exitFull,
this.heightFun, this.heightFun,
this.coverImg this.coverImg,
this.videoUrl
}) : super(key: key); }) : super(key: key);
@override @override
@ -41,6 +43,9 @@ class ClassDetailsVideoState extends State<ClassDetailsVideo> {
SystemChrome.setPreferredOrientations([ SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp, DeviceOrientation.portraitUp,
]); ]);
if(widget.videoUrl != null){
initVideo(widget.videoUrl);
}
} }
@override @override
@ -91,14 +96,11 @@ class ClassDetailsVideoState extends State<ClassDetailsVideo> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
key: globalKey,child:videoWidget( key: globalKey,child:(videoPlayerController?.value?.isInitialized ?? false) ?videoWidget(
MediaQuery.of(context).size.width, MediaQuery.of(context).size.width,
videoPlayerController != null (MediaQuery.of(context).size.width/videoPlayerController.value.aspectRatio)-43,
? (MediaQuery.of(context).size.width) / widget.coverImg,
videoPlayerController.value.aspectRatio ):Container());
: MediaQuery.of(context).size.width / 2,
widget.coverImg,
));
} }
@override @override
@ -129,15 +131,16 @@ class ClassDetailsVideoState extends State<ClassDetailsVideo> {
? Container( ? Container(
color: Colors.black, color: Colors.black,
width: width, width: width,
// height: // height: width / 7 * 5,
height: width / 7 * 5, height: height,
child: chewies = Chewie( child: chewies = Chewie(
controller: chewieAudioController, controller: chewieAudioController,
), ),
) )
: Container( : Container(
width: width, width: width,
height:width / 7 * 5, // height:width / 7 * 5,
height: height,
)), )),
if (widget.isShowImg) if (widget.isShowImg)
GestureDetector( GestureDetector(
@ -150,7 +153,8 @@ class ClassDetailsVideoState extends State<ClassDetailsVideo> {
}, },
child: Container( child: Container(
width: width, width: width,
height: width / 7 * 5, // height: width / 7 * 5,
height: height,
color: Colors.black, color: Colors.black,
child: Stack( child: Stack(
children: [ children: [

10
lib/community/headlines/article_list.dart

@ -1,20 +1,10 @@
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/article.dart'; import 'package:huixiang/retrofit/data/article.dart';
import 'package:huixiang/retrofit/data/banner.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/hot_item.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';

19
lib/community/photo_view_gallery_screen.dart

@ -1,7 +1,9 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart'; import 'package:huixiang/utils/ImgCachePath.dart';
import 'package:network_to_file_image/network_to_file_image.dart';
import 'package:photo_view/photo_view_gallery.dart'; import 'package:photo_view/photo_view_gallery.dart';
import 'package:path/path.dart' as p;
class PhotoViewGalleryScreen extends StatefulWidget { class PhotoViewGalleryScreen extends StatefulWidget {
List images=[]; List images=[];
@ -26,7 +28,10 @@ class _PhotoViewGalleryScreenState extends State<PhotoViewGalleryScreen> {
super.initState(); super.initState();
currentIndex=widget.index; currentIndex=widget.index;
} }
File fileFromDocsDir(String filename) {
String pathName = p.join(ImgCachePath.instance.path, filename);
return File(pathName);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -42,8 +47,12 @@ class _PhotoViewGalleryScreenState extends State<PhotoViewGalleryScreen> {
scrollPhysics: const BouncingScrollPhysics(), scrollPhysics: const BouncingScrollPhysics(),
builder: (BuildContext context, int index) { builder: (BuildContext context, int index) {
return PhotoViewGalleryPageOptions( return PhotoViewGalleryPageOptions(
imageProvider: CachedNetworkImageProvider(widget.images[index]), imageProvider: NetworkToFileImage(
url: widget.images[index],
file: fileFromDocsDir(widget.images[index].toString()
.replaceAll("https://pos.upload.gznl.top/", "").replaceAll("/", "")),
debug: true,
),
); );
}, },
itemCount: widget.images.length, itemCount: widget.images.length,

5
lib/main.dart

@ -55,6 +55,7 @@ import 'package:huixiang/store/store_order.dart';
import 'package:huixiang/settlement/settlement.dart'; import 'package:huixiang/settlement/settlement.dart';
import 'package:huixiang/test_page.dart'; import 'package:huixiang/test_page.dart';
import 'package:huixiang/union/location_map_page.dart'; import 'package:huixiang/union/location_map_page.dart';
import 'package:huixiang/utils/ImgCachePath.dart';
import 'package:huixiang/web/web_page.dart'; import 'package:huixiang/web/web_page.dart';
import 'package:huixiang/union/union_details_page.dart'; import 'package:huixiang/union/union_details_page.dart';
@ -70,6 +71,7 @@ import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'community/community_view/class_details.dart'; import 'community/community_view/class_details.dart';
import 'community/headlines/headlines_column_details.dart'; import 'community/headlines/headlines_column_details.dart';
import 'community/new_community_details.dart';
import 'community/photo_view_gallery_screen.dart'; import 'community/photo_view_gallery_screen.dart';
import 'home/guide_page.dart'; import 'home/guide_page.dart';
import 'home/home_view/activity_list.dart'; import 'home/home_view/activity_list.dart';
@ -102,6 +104,7 @@ void main() async {
} else { } else {
locale = Locale.fromSubtags(languageCode: 'zh', countryCode: 'TW'); locale = Locale.fromSubtags(languageCode: 'zh', countryCode: 'TW');
} }
ImgCachePath();
initSdk(); initSdk();
bool isFirst = sharedPreferences.getBool("isFirst"); bool isFirst = sharedPreferences.getBool("isFirst");
@ -302,6 +305,8 @@ Map<String, WidgetBuilder> routers = <String, WidgetBuilder>{
'/router/release_dynamic': (context, {arguments}) => ReleaseDynamic(), '/router/release_dynamic': (context, {arguments}) => ReleaseDynamic(),
'/router/community_details': (context, {arguments}) => '/router/community_details': (context, {arguments}) =>
CommunityDetails(arguments: arguments), CommunityDetails(arguments: arguments),
'/router/new_community_details': (context, {arguments}) =>
NewCommunityDetails(arguments: arguments),
'/router/user_info_page': (context, {arguments}) => UserInfoPage(), '/router/user_info_page': (context, {arguments}) => UserInfoPage(),
'/router/recharge_page': (context, {arguments}) => RechargePage(), '/router/recharge_page': (context, {arguments}) => RechargePage(),
'/router/mine_wallet': (context, {arguments}) => MineWalletPage(), '/router/mine_wallet': (context, {arguments}) => MineWalletPage(),

78
lib/store/store_order.dart

@ -137,11 +137,12 @@ class _StoreOrderPage extends State<StoreOrderPage>
} }
queryMemberInfo() async { queryMemberInfo() async {
BaseData baseData = await minService.memberInfo() BaseData baseData = await minService.memberInfo().catchError((error) {
.catchError((error){debugPrint(error);}); debugPrint(error);
});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
SharedPreferences.getInstance().then( SharedPreferences.getInstance().then(
(value) => { (value) => {
value.setString('minMember', jsonEncode(baseData.data)), value.setString('minMember', jsonEncode(baseData.data)),
}, },
); );
@ -150,8 +151,10 @@ class _StoreOrderPage extends State<StoreOrderPage>
/// ///
getParentInfo() async { getParentInfo() async {
BaseData baseData = await minService.getParentInfo("$tableId") BaseData baseData =
.catchError((error) {debugPrint(error);}); await minService.getParentInfo("$tableId").catchError((error) {
debugPrint(error);
});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
if (baseData.data != null) { if (baseData.data != null) {
parentId = baseData.data["id"]; parentId = baseData.data["id"];
@ -182,7 +185,8 @@ class _StoreOrderPage extends State<StoreOrderPage>
/// ///
queryStoreInfo() async { queryStoreInfo() async {
BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) { BaseData baseData =
await apiService.queryStoreInfo(storeId).catchError((error) {
debugPrint(error); debugPrint(error);
}); });
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
@ -202,8 +206,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return return WillPopScope(
WillPopScope(
onWillPop: () async { onWillPop: () async {
if (dialogShowing) { if (dialogShowing) {
debugPrint("ssssasdadsasdadasd"); debugPrint("ssssasdadsasdadasd");
@ -213,8 +216,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
return true; return true;
} }
}, },
child: child: Container(
Container(
color: Colors.white, color: Colors.white,
child: Stack( child: Stack(
children: [ children: [
@ -227,14 +229,15 @@ class _StoreOrderPage extends State<StoreOrderPage>
controller: controller, controller: controller,
dragStartBehavior: DragStartBehavior.start, dragStartBehavior: DragStartBehavior.start,
physics: BouncingScrollPhysics(), physics: BouncingScrollPhysics(),
headerSliverBuilder: (BuildContext context, bool innerScrolled) { headerSliverBuilder:
(BuildContext context, bool innerScrolled) {
return [ return [
SliverOverlapAbsorber( SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor( handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
context), context),
sliver: SliverAppBar( sliver: SliverAppBar(
expandedHeight: expandedHeight: (storeInfo != null &&
(storeInfo != null && storeInfo.couponVOList != null) storeInfo.couponVOList != null)
? 470.h ? 470.h
: 365.h, : 365.h,
floating: false, floating: false,
@ -262,9 +265,8 @@ class _StoreOrderPage extends State<StoreOrderPage>
), ),
), ),
flexibleSpace: FlexibleSpaceBar( flexibleSpace: FlexibleSpaceBar(
title: Title( title: Title(controller,
controller, storeInfo != null ? storeInfo.storeName : ''),
storeInfo != null ? storeInfo.storeName : ''),
collapseMode: CollapseMode.pin, collapseMode: CollapseMode.pin,
stretchModes: [ stretchModes: [
StretchMode.zoomBackground, StretchMode.zoomBackground,
@ -555,6 +557,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
return; return;
} }
} }
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(
'/router/settlement', '/router/settlement',
arguments: { arguments: {
@ -562,15 +565,15 @@ class _StoreOrderPage extends State<StoreOrderPage>
"tableId": tableId, "tableId": tableId,
"parentCode": parentCode, "parentCode": parentCode,
"parentId": parentId, "parentId": parentId,
"pName":pName, "pName": pName,
"pid":pid, "pid": pid,
"cName":cName, "cName": cName,
"cid":cid, "cid": cid,
"shoppingCart": shopCarGoods, "shoppingCart": shopCarGoods,
"numberOfPeople": numberOfPeople, "numberOfPeople": numberOfPeople,
}, },
); );
if(tableId >0){ if (tableId > 0) {
getParentInfo(); getParentInfo();
} }
queryShopCar().then((value) { queryShopCar().then((value) {
@ -651,18 +654,19 @@ class _StoreOrderPage extends State<StoreOrderPage>
} }
/// ///
_queryMiNiDetail(String id,int count) async { _queryMiNiDetail(String id, int count) async {
EasyLoading.show(status: S.current.zhengzaijiazai); EasyLoading.show(status: S.current.zhengzaijiazai);
BaseData<MiNiDetail> baseData = await minService.miNiDetail(id); BaseData<MiNiDetail> baseData = await minService.miNiDetail(id);
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
showStoreSelector(baseData.data, id,count); showStoreSelector(baseData.data, id, count);
} }
} }
/// ///
showStoreSelector(MiNiDetail miNiDetail, String id,int count) async { showStoreSelector(MiNiDetail miNiDetail, String id, int count) async {
if (miNiDetail.attrList != null && miNiDetail.attrList.length == 1 if (miNiDetail.attrList != null &&
&& miNiDetail.attrList[0].attrValueList.length == 1) { miNiDetail.attrList.length == 1 &&
miNiDetail.attrList[0].attrValueList.length == 1) {
_addShopCar(miNiDetail, [], count); _addShopCar(miNiDetail, [], count);
} else { } else {
EasyLoading.dismiss(); EasyLoading.dismiss();
@ -687,7 +691,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
/// ///
Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async { Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async {
ProductSkuVOListBean productSku; ProductSkuVOListBean productSku;
if (selectSkus!= null && selectSkus.length == 0) { if (selectSkus != null && selectSkus.length == 0) {
productSku = miNiDetail.productSkuVOList.first; productSku = miNiDetail.productSkuVOList.first;
} else { } else {
productSku = miNiDetail.productSkuVOList.firstWhere((element) { productSku = miNiDetail.productSkuVOList.firstWhere((element) {
@ -743,28 +747,28 @@ class _StoreOrderPage extends State<StoreOrderPage>
/// ///
Future<ShoppingCart> queryShopCar() async { Future<ShoppingCart> queryShopCar() async {
pName="";// pName = ""; //
pid="";// pid = ""; //
cName="";// cName = ""; //
cid="";// cid = ""; //
BaseData<List<ShoppingCart>> baseDate = BaseData<List<ShoppingCart>> baseDate =
await minService.getShoppingCart(tableId); await minService.getShoppingCart(tableId);
if (baseDate != null && if (baseDate != null &&
baseDate.isSuccess && baseDate.isSuccess &&
baseDate.data != null && baseDate.data != null &&
baseDate.data.length > 0) { baseDate.data.length > 0) {
if( baseDate.data[0].selectDiscount ==1){ if (baseDate.data[0].selectDiscount == 1) {
baseDate.data[0].couponList.forEach((element) { baseDate.data[0].couponList.forEach((element) {
if(element.isMaxCoupon){ if (element.isMaxCoupon) {
cName = element.promotionName; cName = element.promotionName;
cid = element.id; cid = element.id;
} }
}); });
}else if(baseDate.data[0].selectDiscount==2){ } else if (baseDate.data[0].selectDiscount == 2) {
baseDate.data[0].promotionInfoList.forEach((element) { baseDate.data[0].promotionInfoList.forEach((element) {
if(element.isMaxPromotion){ if (element.isMaxPromotion) {
pName=element.name; pName = element.name;
pid=element.id; pid = element.id;
} }
}); });
} }

35
lib/utils/ImgCachePath.dart

@ -0,0 +1,35 @@
import 'dart:io';
import 'package:path_provider/path_provider.dart';
class ImgCachePath{
factory ImgCachePath() => _getInstance();
static ImgCachePath get instance => _getInstance();
static ImgCachePath _instance;
String _path;
String get path => _path;
ImgCachePath._internal(){
fileFromDocsDir();
}
fileFromDocsDir() async {
Directory tempDir = await getTemporaryDirectory();
Directory directory = new Directory('${tempDir.path}/ImgCache');
if (!directory.existsSync()) {
directory.createSync();
}
_path = directory.path;
}
static ImgCachePath _getInstance(){
if(_instance == null){
_instance = ImgCachePath._internal();
}
return _instance;
}
}

87
lib/view_widget/custom_image.dart

@ -1,8 +1,8 @@
import 'dart:io'; import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:huixiang/utils/ImgCachePath.dart';
import 'package:network_to_file_image/network_to_file_image.dart';
import 'package:path/path.dart' as p;
class MImage extends StatelessWidget { class MImage extends StatelessWidget {
final String src; final String src;
@ -29,6 +29,11 @@ class MImage extends StatelessWidget {
this.radius = BorderRadius.zero, this.radius = BorderRadius.zero,
}); });
File fileFromDocsDir(String filename) {
String pathName = p.join(ImgCachePath.instance.path, filename);
return File(pathName);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget image = LayoutBuilder( Widget image = LayoutBuilder(
@ -41,10 +46,13 @@ class MImage extends StatelessWidget {
// "$src$oper/imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}" // "$src$oper/imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}"
// "x${constraints.constrainHeight() * scaleIndex}/format/webp/quality/100"; // "x${constraints.constrainHeight() * scaleIndex}/format/webp/quality/100";
// } // }
int _w = ((constraints.constrainWidth()==double.infinity?
MediaQuery.of(context).size.width:constraints.constrainWidth()) * scaleIndex).toInt();
int _h = ((constraints.constrainHeight()==double.infinity?
MediaQuery.of(context).size.height:constraints.constrainHeight()) * scaleIndex).toInt();
/// ///
if ((src??"").startsWith("http")) { if ((src??"").startsWith("http")) {
imageUrl = "$src?imageView2/1/format/jpg/q/50"; imageUrl = "$src?imageView2/1/w/${_w}/h/${_h}/format/jpg/q/75";
} }
// print("imageUrl:$imageUrl"); // print("imageUrl:$imageUrl");
@ -58,43 +66,38 @@ class MImage extends StatelessWidget {
); );
} }
Widget cachedNetworkImage; Widget cachedNetworkImage;
if (src.startsWith("http")) { if (src.startsWith("http")) {
cachedNetworkImage = CachedNetworkImage( cachedNetworkImage = Image(
imageUrl: imageUrl, image: ResizeImage(NetworkToFileImage(
cacheManager: DefaultCacheManager(), url: imageUrl,
fadeInDuration: Duration(milliseconds: 300), file: fileFromDocsDir("resize"+src.replaceAll("https:", "")
fadeOutDuration: Duration(milliseconds: 300), .replaceAll("http:", "")
imageBuilder: (context, provide) { .replaceAll("pos.upload.gznl.top", "")
return Image( .replaceAll("/", "")),
image: provide, debug: true,
fit: fit, ),
); width: _w,
}, height: _h),
errorWidget: (context, error, stackTrace) { errorBuilder: (context, error, stackTrace) {
return Image.asset( return Image.asset(
errorSrc, errorSrc,
fit: fit, fit: fit,
); );
}, },
placeholder: (context, placeholder) { fit: fit,
return Image.asset( );
fadeSrc, } else if (src.startsWith("file")) {
fit: fit, cachedNetworkImage = Image.file(
); File(src),
}, fit: fit,
); errorBuilder: (context, error, stackTrace) {
} else if (src.startsWith("file")) { return Image.asset(
cachedNetworkImage = Image.file( errorSrc,
File(src), fit: fit,
fit: fit, );
errorBuilder: (context, error, stackTrace) { },
return Image.asset( );
errorSrc, }
fit: fit,
);
},
);
}
return cachedNetworkImage; return cachedNetworkImage;
}, },
); );

51
pubspec.lock

@ -50,13 +50,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.1.6" version: "0.1.6"
cached_network_image:
dependency: "direct main"
description:
name: cached_network_image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
characters: characters:
dependency: transitive dependency: transitive
description: description:
@ -209,13 +202,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
flutter_cache_manager:
dependency: transitive
description:
name: flutter_cache_manager
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.3"
flutter_easyloading: flutter_easyloading:
dependency: "direct main" dependency: "direct main"
description: description:
@ -269,7 +255,7 @@ packages:
name: flutter_screenutil name: flutter_screenutil
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "5.0.3" version: "5.1.0"
flutter_smart_dialog: flutter_smart_dialog:
dependency: "direct main" dependency: "direct main"
description: description:
@ -350,13 +336,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.15.0" version: "0.15.0"
http:
dependency: transitive
description:
name: http
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.2"
http_parser: http_parser:
dependency: transitive dependency: transitive
description: description:
@ -434,6 +413,13 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.0" version: "1.0.0"
network_to_file_image:
dependency: "direct main"
description:
name: network_to_file_image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.8"
numerus: numerus:
dependency: transitive dependency: transitive
description: description:
@ -677,20 +663,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.8.1" version: "1.8.1"
sqflite:
dependency: transitive
description:
name: sqflite
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2+4"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.3+3"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -712,13 +684,6 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
synchronized:
dependency: transitive
description:
name: synchronized
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0+2"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:

2
pubspec.yaml

@ -65,7 +65,7 @@ dependencies:
scan: ^1.5.0 scan: ^1.5.0
path_provider: ^1.2.0 path_provider: ^1.2.0
cached_network_image: ^2.0.0 network_to_file_image: ^2.0.0
flutter_html: ^2.1.5 #2.1.0 flutter_html: ^2.1.5 #2.1.0
chewie_audio: ^1.1.2 chewie_audio: ^1.1.2

Loading…
Cancel
Save