diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 814fbd6c..6e58a0cb 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -173,7 +173,7 @@ PODS: - SDWebImage (5.12.1): - SDWebImage/Core (= 5.12.1) - SDWebImage/Core (5.12.1) - - shared_preferences (0.0.1): + - shared_preferences_ios (0.0.1): - Flutter - sharesdk_plugin (1.1.2): - Flutter @@ -207,12 +207,12 @@ PODS: - mob_sharesdk/ShareSDKPlatforms/Twitter - mob_sharesdk/ShareSDKPlatforms/VKontakte - mob_sharesdk/ShareSDKPlatforms/WatermelonVideo - - mob_sharesdk/ShareSDKPlatforms/WeChat_Lite - mob_sharesdk/ShareSDKPlatforms/WhatsApp - mob_sharesdk/ShareSDKPlatforms/Yixin - mob_sharesdk/ShareSDKPlatforms/YouDaoNote - mob_sharesdk/ShareSDKRestoreScene - mob_sharesdk/ShareSDKUI + - WechatOpenSDK_Fuck (~> 1.9.2) - sqflite (0.0.2): - Flutter - FMDB (>= 2.7.5) @@ -248,7 +248,7 @@ DEPENDENCIES: - path_provider (from `.symlinks/plugins/path_provider/ios`) - permission_handler (from `.symlinks/plugins/permission_handler/ios`) - scan (from `.symlinks/plugins/scan/ios`) - - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) + - shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`) - sharesdk_plugin (from `.symlinks/plugins/sharesdk_plugin/ios`) - sqflite (from `.symlinks/plugins/sqflite/ios`) - SSZipArchive (~> 2.4.2) @@ -298,8 +298,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/permission_handler/ios" scan: :path: ".symlinks/plugins/scan/ios" - shared_preferences: - :path: ".symlinks/plugins/shared_preferences/ios" + shared_preferences_ios: + :path: ".symlinks/plugins/shared_preferences_ios/ios" sharesdk_plugin: :path: ".symlinks/plugins/sharesdk_plugin/ios" sqflite: @@ -321,13 +321,13 @@ SPEC CHECKSUMS: AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce BaiduMapKit: 907c6d9b74f66c3ff4741fc4b568ae0b339917f8 BMKLocationKit: 097814ef672b1e57e86e6c1968d7892fb78002bf - Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a flutter_baidu_mapapi_base: 90fddba11ec4435406a7211d6ee905b4311c31db flutter_baidu_mapapi_map: 771bf00671832b1fcddb17733518cd631529df16 flutter_baidu_mapapi_search: 4cffaa74e739a4114595c4f82f790e1783bb612d flutter_baidu_mapapi_utils: a5bd582b91ecd35be1bc45558b38f49d5684f70a flutter_bmflocation: 12f1ba91bae4b16d78d4f475023e0254ed351f1c - fluwx: c192ef1ea3617badb813fa1a761ffc5c9c12208a + fluwx: 02670633ce7509206f62b366e9734e7dda81e100 FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a image_pickers: 5e6ec7083f9363d014c0fb061f1b9cd97bb5e451 mob_sharesdk: c771f001e00739d24301a9fa250247601efe7a3c @@ -337,17 +337,17 @@ SPEC CHECKSUMS: permission_handler: ccb20a9fad0ee9b1314a52b70b76b473c5f8dab0 scan: aea35bb4aa59ccc8839c576a18cd57c7d492cc86 SDWebImage: 4dc3e42d9ec0c1028b960a33ac6b637bb432207b - shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d - sharesdk_plugin: 5a59e49d2d5e55c8e8f67cc9ddf05172c2494a6b + shared_preferences_ios: aef470a42dc4675a1cdd50e3158b42e3d1232b32 + sharesdk_plugin: 31d5b9be9522985da8e3a90ff73f6e12e62f9049 sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904 SSZipArchive: e7b4f3d9e780c2acc1764cd88fbf2de28f26e5b2 - thumbnails: bb4f4e9bb4b51c8ae4e6ad9a2fa81373f9b634ad + thumbnails: df4b2db0d4030d134e7665da9c3060b0d78726fe TPNS-iOS: 57a146496858ba2fb5d43e5f240feb19243b69cb tpns_flutter_plugin: a366649c8ad71f19dfb864d3c994ed0480b69daa url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef - video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e + video_player: ecd305f42e9044793efd34846e1ce64c31ea6fcb wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f - webview_flutter: 3603125dfd3bcbc9d8d418c3f80aeecf331c068b + webview_flutter: 5fb4def2bbd4339889ee14d045b605cefc5bc232 WechatOpenSDK_Fuck: aa8f4b0af902837e887a1d40c62f06c060c1dc98 ZLPhotoBrowser-objc: c7657d3bc85ae231884e058d0e3638f619164736 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 1b87181c..83da7dc1 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -674,7 +674,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -994,7 +994,6 @@ "-l\"flutter_baidu_mapapi_map\"", "-l\"flutter_baidu_mapapi_base\"", "-l\"permission_handler\"", - "-l\"shared_preferences\"", "-l\"sqflite\"", "-l\"sqlite3\"", "-l\"video_player\"", @@ -1232,7 +1231,6 @@ "-l\"flutter_baidu_mapapi_map\"", "-l\"flutter_baidu_mapapi_base\"", "-l\"permission_handler\"", - "-l\"shared_preferences\"", "-l\"sqflite\"", "-l\"sqlite3\"", "-l\"video_player\"", @@ -1361,7 +1359,6 @@ "-l\"flutter_baidu_mapapi_map\"", "-l\"flutter_baidu_mapapi_base\"", "-l\"permission_handler\"", - "-l\"shared_preferences\"", "-l\"sqflite\"", "-l\"sqlite3\"", "-l\"video_player\"", diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index fb2dffc4..c87d15a3 100644 --- a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ createState() { + return _CommunityChildList(); + } +} + +class _CommunityChildList extends State { + RefreshController refreshController = RefreshController(); + final ScrollController scrollController = ScrollController(); + ApiService apiService; + int pageNum = 1; + String userId; + bool isLoadMore = false; + + List comments = []; + + @override + void initState() { + super.initState(); + _onRefresh(); + } + + _onRefresh() async { + setState(() {}); + } + + ///动态列表 + queryCommunity() async { + if (apiService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + userId = value.getString('userId'); + apiService = ApiService( + Dio(), + context: context, + token: value.getString("token"), + ); + } + if(isLoadMore){ + pageNum += 1; + isLoadMore = false; + }else pageNum = 1; + BaseData> baseData = await apiService.trendList({ + "onlyFollow": widget.typeStr == "关注" ? true : false, + "onlyMe": false, + "pageNum": pageNum, + "pageSize": 10, + "searchKey": "" + }).catchError((error) { + refreshController.refreshFailed(); + refreshController.loadFailed(); + }); + + refreshController.refreshCompleted(); + refreshController.loadComplete(); + if (baseData.isSuccess) { + if (pageNum == 1) { + comments.clear(); + } + comments.addAll(baseData.data.list); + // comments.sort((a,b)=>b.createTime.compareTo(a.createTime)); + // print("comments: ${comments.length}"); + if (int.tryParse(baseData.data.total) < (pageNum * 10)) { + refreshController.loadNoData(); + } + } + } + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: queryCommunity(), + builder: (context, position) { + return SmartRefresher( + controller: refreshController, + enablePullDown: true, + enablePullUp: true, + physics: BouncingScrollPhysics(), + header: MyHeader(), + footer: CustomFooter( + builder: (context, mode) { + return MyFooter(mode); + }, + ), + onRefresh: _onRefresh, + onLoading: () { + isLoadMore = true; + setState(() {}); + }, + scrollController: scrollController, + child: Container( + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Container( + // color: Color(0xFFF7F7F7), + // margin: EdgeInsets.only(top: 16.h), + child: Column( + children: [ + CommunityList( + comments, + userId, + 0, + isList: true, + exitFull: () { + setState(() { + _onRefresh(); + }); + }, + ), + ], + ), + ), + ), + ), + ); + }, + ); + } +} diff --git a/lib/community/community_child_page.dart b/lib/community/community_child_page.dart index 0295df8b..051bf228 100644 --- a/lib/community/community_child_page.dart +++ b/lib/community/community_child_page.dart @@ -27,8 +27,9 @@ class CommunityChildPage extends StatefulWidget { class _CommunityChildPage extends State { RefreshController refreshController = RefreshController(); ApiService apiService; - int pageNum = 0; + int pageNum = 1; String userId; + bool isLoadMore = false; List
articles = []; @@ -39,7 +40,6 @@ class _CommunityChildPage extends State { } _onRefresh() async { - pageNum = 0; setState(() {}); } @@ -54,7 +54,11 @@ class _CommunityChildPage extends State { token: value.getString("token"), ); } - pageNum += 1; + if(isLoadMore){ + pageNum += 1; + isLoadMore = false; + } + else pageNum = 1; BaseData> baseData = await apiService.trendList({ "onlyFollow": widget.typeStr == "关注" ? true : false, "onlyMe": false, @@ -113,6 +117,7 @@ class _CommunityChildPage extends State { ), onRefresh: _onRefresh, onLoading: () { + isLoadMore = true; setState(() {}); }, child: ListView.builder( diff --git a/lib/community/community_details.dart b/lib/community/community_details.dart index 4b627168..391b8702 100644 --- a/lib/community/community_details.dart +++ b/lib/community/community_details.dart @@ -6,7 +6,6 @@ import 'package:huixiang/generated/l10n.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/retrofit/data/article.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/page.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; diff --git a/lib/community/community_list.dart b/lib/community/community_list.dart new file mode 100644 index 00000000..73531a4a --- /dev/null +++ b/lib/community/community_list.dart @@ -0,0 +1,489 @@ +import 'package:dio/dio.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:huixiang/community/photo_view_gallery_screen.dart'; +import 'package:huixiang/retrofit/data/base_data.dart'; +import 'package:huixiang/retrofit/data/comunity_comment.dart'; +import 'package:huixiang/retrofit/retrofit_api.dart'; +import 'package:huixiang/utils/font_weight.dart'; +import 'package:huixiang/view_widget/border_text.dart'; +import 'package:huixiang/view_widget/custom_image.dart'; +import 'package:huixiang/view_widget/icon_text.dart'; +import 'package:huixiang/view_widget/round_button.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class CommunityList extends StatefulWidget { + final List comments; + final String userId; + final int commentType; + final bool isList; + final Function exitFull; + + CommunityList( + this.comments, + this.userId, + this.commentType,{ + this.isList = false, + this.exitFull, + } + + ); + + @override + State createState() { + return _CommunityList(); + } +} + +class _CommunityList extends State { + ApiService apiService; + + @override + void initState() { + super.initState(); + + SharedPreferences.getInstance().then((value) => { + apiService = ApiService(Dio(), + context: context, token: value.getString("token")), + }); + } + + ///关注/取关会员 + _vipFollow(followId, isFollow) async { + BaseData baseData = await apiService.follow(followId); + if (baseData != null && baseData.isSuccess) { + widget.exitFull(); + SmartDialog.showToast(isFollow ? "关注成功" : "取关成功", + alignment: Alignment.center); + setState(() {}); + } else { + SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + } + } + + ///删除动态 + _deleteDynamic(id) async { + BaseData baseData = await apiService.deleteTrend(id); + if (baseData != null && baseData.isSuccess) { + widget.exitFull(); + SmartDialog.showToast("删除成功", alignment: Alignment.center); + setState(() {}); + } else { + // SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + } + } + + @override + Widget build(BuildContext context) { + return Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + ListView.builder( + padding: EdgeInsets.zero, + itemCount: widget.comments.length, + scrollDirection: Axis.vertical, + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, position) { + return GestureDetector( + onTap: () { + Navigator.of(context) + .pushNamed('/router/new_community_details', arguments: { + "commentsId": widget.comments[position].id, + "userId":widget.userId, + // exitFull: () { + // setState(() {}); + // }, + }); + setState(() {}); + }, + child: communityItem(widget.comments[position], position), + ); + }, + ), + ], + )); + } + + ///动态内容 + Widget buildMedia(SubjectInfo subjectInfo, position) { + if (subjectInfo == null) { + return Container(); + } + Widget itemWidget = Container(); + if (subjectInfo.type == "image" && subjectInfo.images.length > 0) { + if (subjectInfo.images.length == 1) { + itemWidget = Container( + child: InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: subjectInfo.images, //传入图片list + index: 0, //传入当前点击的图片的index + ))); + }, + child: MImage( + subjectInfo.images[0], + fit: BoxFit.contain, + radius: BorderRadius.circular(2), + width: MediaQuery.of(context).size.width / 1.5, + height: MediaQuery.of(context).size.width/1.5, + errorSrc: "assets/image/default_2_1.png", + fadeSrc: "assets/image/default_2_1.png", + )), + ); + } else { + itemWidget = GridView.builder( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: (subjectInfo.images.length == 2 || + subjectInfo.images.length == 4) + ? 2 + : 3, + crossAxisSpacing: 12.w, + mainAxisSpacing: 12.w, + childAspectRatio: 1, + ), + padding: EdgeInsets.zero, + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, position) { + return Container( + child: InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: subjectInfo.images, //传入图片list + index: position, //传入当前点击的图片的index + ))); + }, + child: MImage( + subjectInfo.images[position], + fit: BoxFit.cover, + aspectRatio: 1, + radius: BorderRadius.circular(1), + errorSrc: "assets/image/default_2_1.png", + fadeSrc: "assets/image/default_2_1.png", + ), + ), + ); + }, + itemCount: subjectInfo.images.length, + ); + } + } else if (subjectInfo.type == "video" && subjectInfo.video.isNotEmpty) { + itemWidget = Container( + width: MediaQuery.of(context).size.width, + height: MediaQuery.of(context).size.width / 7 * 5, + color: Colors.black, + child: Stack( + children: [ + Container( + width: double.infinity, + height: double.infinity, + child: MImage( + subjectInfo.video.replaceAll(".mp4", "_poster.jpg"), + fit: BoxFit.cover, + radius: BorderRadius.circular(2), + errorSrc: "assets/image/default_2_1.png", + fadeSrc: "assets/image/default_2_1.png", + ), + ), + Center( + child: Icon( + Icons.play_circle_outline, + color: Colors.white, + size: 60, + ), + ), + ], + ), + ); + } + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 16.h, + ), + itemWidget, + ], + ); + } + + Widget communityItem(ComunityComment comments, position) { + return Container( + width: double.infinity, + padding: EdgeInsets.all(16), + margin: EdgeInsets.only(bottom: 12), + color: Colors.white, + child: Column( + children: [ + Container( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + height: 44, + child: Row( + children: [ + GestureDetector( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + PhotoViewGalleryScreen( + images: [ + (comments?.memberInfo?.avatar ?? "") + .isEmpty + ? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg" + : comments?.memberInfo?.avatar + ], //传入图片list + index: 0, //传入当前点击的图片的index + ), + )); + }, + child: MImage( + (comments?.memberInfo?.avatar ?? + "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg"), + width: 44, + height: 44, + isCircle: true, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.png", + fadeSrc: "assets/image/default_1.png", + ), + ), + SizedBox( + width: 8, + ), + Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + comments?.memberInfo?.nickname ?? "", + style: TextStyle( + fontSize: 15.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF1A1A1A), + ), + ), + Text( + comments?.createTime ?? "", + style: TextStyle( + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF808080), + ), + ), + ], + ), + ], + ), + ), + if ((comments?.memberInfo?.mid ?? "") != (widget.userId)) + GestureDetector( + onTap: () { + setState(() { + if (widget.commentType == 0) { + comments.selfFollow = !(comments.selfFollow ?? false); + _vipFollow(comments?.memberInfo?.mid,comments?.selfFollow ?? false); + } else { + showDeleteDialog(position); + } + }); + }, + child: + (widget.commentType == 0) ? + Container( + width: 56.w, + height: 25.h, + alignment: Alignment.center, + child: RoundButton( + height: 25.h, + backgroup: (comments?.selfFollow ?? false) + ? Color(0xFFE6E6E6) + : Color(0xFF32A060), + textColor: (comments?.selfFollow ?? false) + ? Color(0xFF808080) + : Colors.white, + text: (comments?.selfFollow ?? false) + ? "已关注" + : "关注", + radius: 20, + icons: Icon( + (comments?.selfFollow ?? false) + ? Icons.check + : Icons.add, + color: (comments?.selfFollow ?? false) + ? Color(0xFF808080) + : Colors.white, + size: 15, + ), + )) + : Padding( + padding: EdgeInsets.all(20), + child: Icon( + Icons.close, + color: Colors.black, + size: 16, + ), + ), + ), + ], + ), + SizedBox( + height: 12.h, + ), + Text( + comments.subject ?? "", + maxLines: 5, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFF1A1A1A), + fontWeight: MyFontWeight.regular, + fontSize: 15.sp, + ), + ), + buildMedia(comments?.subjectInfo, position), + // if (!widget.isDetails) + SizedBox( + height: 12.h, + ), + // if (!comments.isDetails) + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + IconText( + "${comments?.viewers ?? ""}", + space: 4.w, + leftImage: "assets/svg/liulanliang.svg", + iconSize: 16, + textStyle: TextStyle( + fontSize: 14.sp, + ), + ), + IconText( + "${comments.comments ?? 0}", + space: 4.w, + leftImage: "assets/svg/pinglun.svg", + iconSize: 16, + textStyle: TextStyle( + fontSize: 14.sp, + ), + ), + GestureDetector( + onTap: () {}, + child: IconText( + "${comments.likes ?? 0}", + space: 4.w, + leftImage: "assets/svg/xihuan.svg", + iconSize: 16, + textStyle: TextStyle( + fontSize: 14.sp, + ), + ), + ), + ], + ), + ], + ), + ), + ], + ), + ); + } + + ///删除动态弹窗 + showDeleteDialog(index) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + content: Container( + width: MediaQuery.of(context).size.width - 84, + height: 130.h, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "确定要删除这条动态?", + style: TextStyle( + fontSize: 17.sp, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + SizedBox( + height: 30.h, + ), + Row( + children: [ + Expanded( + child: InkWell( + child: BorderText( + text: "取消", + textColor: Color(0xFF32A060), + fontSize: 16.sp, + fontWeight: FontWeight.bold, + borderColor: Color(0xFF32A060), + radius: 4, + padding: EdgeInsets.all(12), + borderWidth: 1, + ), + onTap: () { + Navigator.of(context).pop(); + }, + ), + flex: 1, + ), + SizedBox( + width: 16.w, + ), + Expanded( + child: InkWell( + child: RoundButton( + text: "确定", + textColor: Colors.white, + radius: 4, + padding: EdgeInsets.all(12), + backgroup: Color(0xFF32A060), + fontSize: 16.sp, + fontWeight: FontWeight.bold, + ), + onTap: () { + _deleteDynamic(widget.comments[index].id); + Navigator.of(context).pop(); + }, + ), + flex: 1, + ), + ], + ) + ], + ), + ), + ); + }, + ); + } +} diff --git a/lib/community/community_page.dart b/lib/community/community_page.dart index e972a4e5..6a695ff6 100644 --- a/lib/community/community_page.dart +++ b/lib/community/community_page.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.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/home/huixiang_brand_page.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; @@ -20,6 +21,8 @@ class _CommunityPage extends State with SingleTickerProviderStateMixin { TabController tabcontroller; + CommunityChildPage guanzhu,tuijian ; + List lables = [ "关注", "推荐", @@ -108,7 +111,7 @@ class _CommunityPage extends State return CommunityCourse(); } else { - return CommunityChildPage(e); + return CommunityChildList(e); } }).toList(), controller: tabcontroller, diff --git a/lib/community/community_view/class_details_video.dart b/lib/community/community_view/class_details_video.dart index a051e0f6..5c60c698 100644 --- a/lib/community/community_view/class_details_video.dart +++ b/lib/community/community_view/class_details_video.dart @@ -11,6 +11,7 @@ class ClassDetailsVideo extends StatefulWidget { final bool isShowImg; final Function exitFull; final String coverImg; + final String videoUrl; ClassDetailsVideo( { @@ -19,7 +20,8 @@ class ClassDetailsVideo extends StatefulWidget { this.isShowImg, this.exitFull, this.heightFun, - this.coverImg + this.coverImg, + this.videoUrl }) : super(key: key); @override @@ -41,6 +43,9 @@ class ClassDetailsVideoState extends State { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, ]); + if(widget.videoUrl != null){ + initVideo(widget.videoUrl); + } } @override @@ -91,14 +96,11 @@ class ClassDetailsVideoState extends State { @override Widget build(BuildContext context) { return Container( - key: globalKey,child:videoWidget( - MediaQuery.of(context).size.width, - videoPlayerController != null - ? (MediaQuery.of(context).size.width) / - videoPlayerController.value.aspectRatio - : MediaQuery.of(context).size.width / 2, - widget.coverImg, - )); + key: globalKey,child:(videoPlayerController?.value?.isInitialized ?? false) ?videoWidget( + MediaQuery.of(context).size.width, + (MediaQuery.of(context).size.width/videoPlayerController.value.aspectRatio)-43, + widget.coverImg, + ):Container()); } @override @@ -129,15 +131,16 @@ class ClassDetailsVideoState extends State { ? Container( color: Colors.black, width: width, - // height: - height: width / 7 * 5, + // height: width / 7 * 5, + height: height, child: chewies = Chewie( controller: chewieAudioController, ), ) : Container( width: width, - height:width / 7 * 5, + // height:width / 7 * 5, + height: height, )), if (widget.isShowImg) GestureDetector( @@ -150,7 +153,8 @@ class ClassDetailsVideoState extends State { }, child: Container( width: width, - height: width / 7 * 5, + // height: width / 7 * 5, + height: height, color: Colors.black, child: Stack( children: [ diff --git a/lib/community/community_view/community_dynamic.dart b/lib/community/community_view/community_dynamic.dart index 02c421ec..c87e5207 100644 --- a/lib/community/community_view/community_dynamic.dart +++ b/lib/community/community_view/community_dynamic.dart @@ -185,7 +185,7 @@ class _CommunityDynamic extends State { }, child: MImage( - (widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg") + "?imageView2/1/w/200/h/200/format/jpg/q/75", + (widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg"), width: 44, height: 44, isCircle: true, @@ -368,11 +368,10 @@ class _CommunityDynamic extends State { ); }, child: MImage( - cnt["images"][0].replaceAll(".jpg", ".jpg?imageView2/0/q/75"), + cnt["images"][0], fit: BoxFit.contain, radius: BorderRadius.circular(2), - width: MediaQuery.of(context).size.width/1.5, - height:MediaQuery.of(context).size.width, + height:MediaQuery.of(context).size.width/1.5, errorSrc: "assets/image/default_2_1.png", fadeSrc: "assets/image/default_2_1.png", )), diff --git a/lib/community/headlines/article_list.dart b/lib/community/headlines/article_list.dart index 9bf6a0e0..4bf58089 100644 --- a/lib/community/headlines/article_list.dart +++ b/lib/community/headlines/article_list.dart @@ -1,20 +1,10 @@ import 'package:dio/dio.dart'; import 'package:flutter/cupertino.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/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/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/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:flutter_screenutil/flutter_screenutil.dart'; diff --git a/lib/community/new_community_details.dart b/lib/community/new_community_details.dart new file mode 100644 index 00000000..0e0626d1 --- /dev/null +++ b/lib/community/new_community_details.dart @@ -0,0 +1,551 @@ +import 'dart:convert'; + +import 'package:dio/dio.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:huixiang/community/photo_view_gallery_screen.dart'; +import 'package:huixiang/generated/l10n.dart'; +import 'package:huixiang/retrofit/data/article.dart'; +import 'package:huixiang/retrofit/data/base_data.dart'; +import 'package:huixiang/retrofit/data/member_comment_list.dart'; +import 'package:huixiang/retrofit/data/page.dart'; +import 'package:huixiang/retrofit/retrofit_api.dart'; +import 'package:huixiang/utils/font_weight.dart'; +import 'package:huixiang/view_widget/custom_image.dart'; +import 'package:huixiang/view_widget/my_appbar.dart'; +import 'package:huixiang/view_widget/round_button.dart'; +import 'package:huixiang/view_widget/tips_dialog.dart'; +import 'package:huixiang/web/web_view/comment_list.dart'; +import 'package:huixiang/web/web_view/input_comment.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'dart:ui'; + +import 'community_view/class_details_video.dart'; + +class NewCommunityDetails extends StatefulWidget { + final Map arguments; + + NewCommunityDetails({this.arguments}); + + @override + State createState() { + return _NewCommunityDetails(); + } +} + +class _NewCommunityDetails extends State with WidgetsBindingObserver { + ApiService apiService; + final GlobalKey commentKey = GlobalKey(); + final GlobalKey videoKey = GlobalKey(); + double height = 0; + final ScrollController scrollController = ScrollController(); + bool isKeyBoardShow = false; + double commentHeight = 60.h; + var commentFocus = FocusNode(); + String parenId = "0"; + String hintText = S.current.liuxianinjingcaidepinglunba; + final GlobalKey inputKey = GlobalKey(); + final TextEditingController commentTextController = TextEditingController(); + int commentTotal = 0; + List memberList = []; + bool isShowImg = true; + Article article; + String commentsId; + String userId; + + @override + void initState() { + super.initState(); + commentsId = widget.arguments["commentsId"]; + userId = widget.arguments["userId"]; + WidgetsBinding.instance.addObserver(this); + queryDetails(commentsId); + } + + ///详情接口 + queryDetails(id) async { + SharedPreferences value = await SharedPreferences.getInstance(); + if (apiService == null) + apiService = ApiService( + Dio(), + context: context, + token: value.getString("token"), + ); + BaseData
baseData = await apiService.informationInfo(id) + .catchError((onError) { + debugPrint(onError.toString()); + }); + if (baseData != null && baseData.isSuccess) { + setState(() { + article = baseData.data; + }); + } + } + + ///关注/取关会员 + _vipFollow(followId, isFollow) async { + BaseData baseData = await apiService.follow(followId); + if (baseData != null && baseData.isSuccess) { + SmartDialog.showToast(isFollow ? "关注成功" : "取关成功", + alignment: Alignment.center); + setState(() {}); + } else { + // SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + } + } + + @override + void didChangeMetrics() { + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; + if (MediaQuery.of(context).viewInsets.bottom == 0) { + if (isKeyBoardShow) { + FocusScope.of(context).requestFocus(FocusNode()); + if (mounted) + setState(() { + hintText = S.current.liuxianinjingcaidepinglunba; + isKeyBoardShow = false; + }); + } + } else { + if (mounted) + setState(() { + isKeyBoardShow = true; + }); + } + }); + } + + @override + Widget build(BuildContext context) { + return AnnotatedRegion( + value: SystemUiOverlayStyle.light, + child: Material(child: Scaffold( + appBar: MyAppBar( + title: "动态详情", + titleColor: Colors.black, + titleSize: 18.sp, + background: Colors.white, + leading: true, + leadingColor: Colors.black, + ), + body: Container( + margin: EdgeInsets.only(top:2.h), + child: Column( + children: [ + Expanded( + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Column( + children: [ + Container( + padding: EdgeInsets.all(16), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + height: 44, + child: Row( + children: [ + GestureDetector( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: [ + (article?.authorHeadImg ?? "") + .isEmpty + ? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg" + : article?.authorHeadImg + ], //传入图片list + index: 0, //传入当前点击的图片的index + ), + )); + }, + child: MImage( + (article?.authorHeadImg ?? + ""), + width: 44, + height: 44, + isCircle: true, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.png", + fadeSrc: "assets/image/default_1.png", + ), + ), + SizedBox( + width: 8, + ), + Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + article?.authorName ?? "", + style: TextStyle( + fontSize: 15.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF1A1A1A), + ), + ), + Text( + article?.createTime ?? "", + style: TextStyle( + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF808080), + ), + ), + ], + ), + ], + ), + ), + if (article?.updateUser != userId) + GestureDetector( + onTap: () { + setState(() { + article.liked = + !(article.liked ?? false); + _vipFollow(article.updateUser, + article.liked ?? false); + }); + }, + child: + Container( + width: 56.w, + height: 25.h, + alignment: Alignment.center, + child: RoundButton( + height: 25.h, + backgroup: (article?.liked ?? false) + ? Color(0xFFE6E6E6) + : Color(0xFF32A060), + textColor: (article?.liked ?? false) + ? Color(0xFF808080) + : Colors.white, + text: (article?.liked ?? false) + ? "已关注" + : "关注", + radius: 20, + icons: Icon( + (article?.liked ?? false) + ? Icons.check + : Icons.add, + color: (article?.liked ?? false) + ? Color(0xFF808080) + : Colors.white, + size: 15, + ), + )) + ), + ], + ), + SizedBox( + height: 12.h, + ), + Text( + article?.mainTitle ?? "", + maxLines: 5, + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Color(0xFF1A1A1A), + fontWeight: MyFontWeight.regular, + fontSize: 15.sp, + ), + ), + buildMedia(article?.content), + ], + ), + ), + CommentList( + commentKey, + article?.likes ?? 0, + commentsId, + 4, + isKeyBoardShow, + _reply, + _delCommentTips, + 12.sp, + requestApiFinish: (total){setState(() { + commentTotal = total; + });}, + ), + if (memberList == null || memberList.length == 0) + Container( + width: double.infinity, + alignment: Alignment.topCenter, + margin: EdgeInsets.only(top: 40), + padding: EdgeInsets.all(22.h), + child: Text( + S.of(context) + .zanwupinglun, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, + color: Color(0xFFA0A0A0), + ), + ), + ), + ], + ), + ), + flex: 1, + ), + /// 富文本评论的输入框 + InputComment( + inputKey, + hintText, + isKeyBoardShow, + commentFocus, + commentTextController, + _toComment, + _queryMemberComment, + _queryInformationLikes, + isLike: article?.liked ?? false, + ), + ], + ), + ), + ),) + ); + } + + ///动态内容 + Widget buildMedia(String subjectInfo) { + if (subjectInfo == null || !subjectInfo.startsWith("{")) { + return Container(); + } + var cnt = jsonDecode(subjectInfo); + Widget itemWidget = Container(); + if (cnt["type"] == "image" && + cnt["images"] != null && + cnt["images"].length > 0) { + if (cnt["images"].length == 1) { + itemWidget = Container( + child: InkWell( + onTap: () { + // ImagePickers.previewImages(subjectInfo.images,0); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: cnt["images"], //传入图片list + index: 0, //传入当前点击的图片的index + ), + ), + ); + }, + child: MImage( + cnt["images"][0], + radius: BorderRadius.circular(2), + fit: BoxFit.contain, + width: MediaQuery.of(context).size.width / 1.5, + height: MediaQuery.of(context).size.width, + errorSrc: "assets/image/default_2_1.png", + fadeSrc: "assets/image/default_2_1.png", + )), + ); + } else { + itemWidget = GridView.builder( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: + (cnt["images"].length == 2 || cnt["images"].length == 4) + ? 2 + : 3, + crossAxisSpacing: 12.w, + mainAxisSpacing: 12.w, + childAspectRatio: 1, + ), + padding: EdgeInsets.zero, + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, position) { + return Container( + child: InkWell( + onTap: () { + // ImagePickers.previewImages(subjectInfo.images, position); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: cnt["images"], //传入图片list + index: position, //传入当前点击的图片的index + ), + ), + ); + }, + child: MImage( + cnt["images"][position], + fit: BoxFit.cover, + aspectRatio: 1, + radius: BorderRadius.circular(1), + errorSrc: "assets/image/default_2_1.png", + fadeSrc: "assets/image/default_2_1.png", + ), + ), + ); + }, + itemCount: cnt["images"].length, + ); + } + } else if (cnt["type"] == "video" && + cnt["video"] != null && + cnt["video"].isNotEmpty) { + itemWidget = Container( + child:ClassDetailsVideo(key:videoKey,exitFull: (){setState(() {});}, + coverImg: cnt["video"].toString().replaceAll(".mp4", "_poster.jpg"),isShowImg: this.isShowImg, + changeShowImg: (isShowImg){setState(() { + this.isShowImg = isShowImg; + });},videoUrl: cnt["video"], + heightFun: (height) { + this.height = + height + + MediaQuery + .of(context) + .padding + .top + + kToolbarHeight + + 24; + if (mounted) setState(() {}); + },) + ); + } + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 16.h, + ), + itemWidget, + ], + ); + } + + ///给文章/活动点赞 + _queryInformationLikes() async { + BaseData baseData = await apiService.informationLikes(commentsId).catchError((onError) {}); + if (baseData != null && baseData.isSuccess) { + commentKey.currentState.setState(() {}); + setState(() { + if (article?.liked ?? false) + article?.likes -= 1; + else + article?.likes += 1; + article?.liked = !(article.liked ?? false); + }); + } else { + SmartDialog.showToast(baseData.msg, alignment: Alignment.center); + } + } + + ///动态发布评论 + _queryMemberComment(String content) async { + BaseData baseData = await apiService.memberComment({ + "content": content, + "parentId": parenId, + "relationalId": commentsId, + "relationalType":4 + }).catchError((error) {}); + if (baseData != null && baseData.isSuccess) { + CommentListState state = commentKey.currentState; + state.queryMemberCommentList(); + commentTextController.text = ""; + FocusScope.of(context).unfocus(); + _queryMemberCommentList(); + } + } + + ///滑动到评论列表 + _toComment() { + if (commentKey.currentContext == null) return; + RenderBox firstRenderBox = commentKey.currentContext.findRenderObject(); + Offset first = firstRenderBox.localToGlobal(Offset.zero); + scrollController.animateTo( + first.dy + + scrollController.offset - + (kToolbarHeight + MediaQuery + .of(context) + .padding + .top), + duration: Duration(milliseconds: 300), + curve: Curves.easeIn, + ); + } + + contentHeight() { + double contentHeight = MediaQuery + .of(context) + .size + .height - + kToolbarHeight - + MediaQuery + .of(context) + .padding + .top - + 160.h; + if ((contentHeight - 60.h) > (128.h * memberList.length)) { + commentHeight = contentHeight - (128.h * memberList.length); + } + } + + ///删除评论的提示 + _delCommentTips(memberComment) { + SmartDialog.show(widget: Tips(() { + delComment(memberComment); + })); + } + + ///删除评论 + delComment(memberComment) async { + BaseData baseData = await apiService.delComment(memberComment.id); + if (baseData != null && baseData.isSuccess) { + CommentListState state = commentKey.currentState; + state.queryMemberCommentList(); + } + } + + ///评论 回复 + _reply(memberComment) { + FocusScope.of(context).requestFocus(commentFocus); + parenId = memberComment.id; + hintText = S.of(context).huifu_("${memberComment.username}"); + } + + ///评论列表 + _queryMemberCommentList() async { + SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); + if (apiService == null) + apiService = ApiService( + Dio(), + context: context, + token: sharedPreferences.getString("token"), + showLoading: false, + ); + BaseData> baseData = + await apiService.memberCommentList({ + "pageNum": 1, + "pageSize": 100, + "relationalId": commentsId, + "relationalType":4, + }).catchError((error) {}); + if (baseData != null && baseData.isSuccess) { + commentTotal = baseData.data.size; + memberList = baseData.data.list; + contentHeight(); + if (mounted) setState(() {}); + } + } +} diff --git a/lib/community/photo_view_gallery_screen.dart b/lib/community/photo_view_gallery_screen.dart index 08c0e0f7..2076af6a 100644 --- a/lib/community/photo_view_gallery_screen.dart +++ b/lib/community/photo_view_gallery_screen.dart @@ -1,6 +1,9 @@ +import 'dart:io'; 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:path/path.dart' as p; class PhotoViewGalleryScreen extends StatefulWidget { List images=[]; @@ -25,7 +28,10 @@ class _PhotoViewGalleryScreenState extends State { super.initState(); currentIndex=widget.index; } - + File fileFromDocsDir(String filename) { + String pathName = p.join(ImgCachePath.instance.path, filename); + return File(pathName); + } @override Widget build(BuildContext context) { return Scaffold( @@ -41,8 +47,12 @@ class _PhotoViewGalleryScreenState extends State { scrollPhysics: const BouncingScrollPhysics(), builder: (BuildContext context, int index) { return PhotoViewGalleryPageOptions( - imageProvider: NetworkImage(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, diff --git a/lib/community/release_dynamic.dart b/lib/community/release_dynamic.dart index 5d19ede5..6cffea20 100644 --- a/lib/community/release_dynamic.dart +++ b/lib/community/release_dynamic.dart @@ -110,7 +110,7 @@ class _ReleaseDynamic extends State { style: TextStyle( fontWeight: MyFontWeight.medium, fontSize: 14.sp, - color: Colors.black, + color: Color(0xFFA0A0A0), ), ),) ], diff --git a/lib/home/home_view/coupon.dart b/lib/home/home_view/coupon.dart index 0f1f42b8..7114a1d7 100644 --- a/lib/home/home_view/coupon.dart +++ b/lib/home/home_view/coupon.dart @@ -87,12 +87,12 @@ class _CouponView extends State { Widget couponItem(Coupon coupon) { return Container( - width: 0.9.sw, + width: 0.9, height: 122.h, child: Stack( children: [ Container( - width: 0.9.sw, + width: 0.9, height: 122.h, child: SvgPicture.asset( "assets/svg/youhuiquan_bg.svg", @@ -102,7 +102,7 @@ class _CouponView extends State { ), ), Container( - width: 0.9.sw, + width: 0.9, height: 122.h, child: Row( children: [ diff --git a/lib/home/home_view/featured_acticvity.dart b/lib/home/home_view/featured_acticvity.dart index bab089a3..12324473 100644 --- a/lib/home/home_view/featured_acticvity.dart +++ b/lib/home/home_view/featured_acticvity.dart @@ -119,9 +119,9 @@ class _FeaturedActivity extends State { ), ), ), - SizedBox( - height: 5, - ), + // SizedBox( + // height: 5, + // ), // GestureDetector( // onTap: () { // Navigator.of(context).pushNamed('/router/web_page', diff --git a/lib/integral/integral_detailed_page.dart b/lib/integral/integral_detailed_page.dart index c943880c..390dcd7c 100644 --- a/lib/integral/integral_detailed_page.dart +++ b/lib/integral/integral_detailed_page.dart @@ -10,6 +10,7 @@ import 'package:huixiang/retrofit/data/user_info.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/classic_header.dart'; +import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_footer.dart'; import 'package:huixiang/view_widget/my_tab.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; diff --git a/lib/main.dart b/lib/main.dart index ff2580d3..f634b27e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -55,6 +55,7 @@ import 'package:huixiang/store/store_order.dart'; import 'package:huixiang/settlement/settlement.dart'; import 'package:huixiang/test_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/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/headlines/headlines_column_details.dart'; +import 'community/new_community_details.dart'; import 'community/photo_view_gallery_screen.dart'; import 'home/guide_page.dart'; import 'home/home_view/activity_list.dart'; @@ -102,6 +104,7 @@ void main() async { } else { locale = Locale.fromSubtags(languageCode: 'zh', countryCode: 'TW'); } + ImgCachePath(); initSdk(); bool isFirst = sharedPreferences.getBool("isFirst"); @@ -302,6 +305,8 @@ Map routers = { '/router/release_dynamic': (context, {arguments}) => ReleaseDynamic(), '/router/community_details': (context, {arguments}) => CommunityDetails(arguments: arguments), + '/router/new_community_details': (context, {arguments}) => + NewCommunityDetails(arguments: arguments), '/router/user_info_page': (context, {arguments}) => UserInfoPage(), '/router/recharge_page': (context, {arguments}) => RechargePage(), '/router/mine_wallet': (context, {arguments}) => MineWalletPage(), diff --git a/lib/retrofit/retrofit_api.g.dart b/lib/retrofit/retrofit_api.g.dart index b39600ce..71083690 100644 --- a/lib/retrofit/retrofit_api.g.dart +++ b/lib/retrofit/retrofit_api.g.dart @@ -9,7 +9,7 @@ part of 'retrofit_api.dart'; class _ApiService implements ApiService { _ApiService(this._dio, {this.baseUrl}) { ArgumentError.checkNotNull(_dio, '_dio'); - baseUrl ??= 'http://192.168.10.142:8766/app/'; + baseUrl ??= 'http://192.168.10.236:8766/app/'; } final Dio _dio; diff --git a/lib/settlement/settlement.dart b/lib/settlement/settlement.dart index eb7905b2..3d120e31 100644 --- a/lib/settlement/settlement.dart +++ b/lib/settlement/settlement.dart @@ -307,7 +307,9 @@ class _Settlement extends State { } BaseData baseData = await minService .settlementWx(placeOrderFirst.toJson()) - .catchError((error) {}); + .catchError((error) { + print(error); + }); if (baseData != null && baseData.isSuccess) { WxPay wxPay = baseData.data; await registerWxApi( @@ -332,7 +334,9 @@ class _Settlement extends State { } else { BaseData baseData = await minService .settlementApi(placeOrderFirst.toJson()) - .catchError((error) {}); + .catchError((error) { + print(error); + }); if (baseData != null && baseData.isSuccess) { toOrderDetails(placeOrderFirst.id); } else { diff --git a/lib/settlement/settlement_view/coupon.dart b/lib/settlement/settlement_view/coupon.dart index bae2b62b..2eb17ba3 100644 --- a/lib/settlement/settlement_view/coupon.dart +++ b/lib/settlement/settlement_view/coupon.dart @@ -171,8 +171,8 @@ class _CouponWidget extends State { }, child: Image.asset( widget.selected - ? "assets/image/icon_radio_unselected.png" - : "assets/image/icon_radio_selected.png", + ? "assets/image/icon_radio_selected.png" + : "assets/image/icon_radio_unselected.png", width: 24, height: 24, ), diff --git a/lib/settlement/settlement_view/settlement_coupon.dart b/lib/settlement/settlement_view/settlement_coupon.dart index d9bf735f..a8469317 100644 --- a/lib/settlement/settlement_view/settlement_coupon.dart +++ b/lib/settlement/settlement_view/settlement_coupon.dart @@ -115,7 +115,7 @@ class _SettlementCoupon extends State { return CouponWidget( couponCan[position], widget.storeInfo, - selected: widget.couponBean == couponCan[position], + selected: widget?.couponBean?.id == couponCan[position]?.id, ); }, ), diff --git a/lib/settlement/settlement_view/settlement_order_commodity.dart b/lib/settlement/settlement_view/settlement_order_commodity.dart index 67529d5b..ea89f6ab 100644 --- a/lib/settlement/settlement_view/settlement_order_commodity.dart +++ b/lib/settlement/settlement_view/settlement_order_commodity.dart @@ -122,7 +122,7 @@ class _SettlementOrderCommodity extends State { children: [ MImage( productList.skuImg, - width: 44.w, + width: 44, height: 44, fit: BoxFit.cover, errorSrc: "assets/image/default_1.png", @@ -342,10 +342,7 @@ class _SettlementOrderCommodity extends State { ), Container( child: Text( - "已优惠:¥${(widget.minOrderInfo != null) ? (double.parse(widget.minOrderInfo.discountAmount ?? "0") + double.parse(widget.settleOrderInfo.benefitDiscountAmount ?? "0")) : - (double.parse(widget.tableId <= 0 ? "0" : (widget.settleOrderInfo.discountAmount ?? "0")) - + double.parse(widget?.settleOrderInfo?.benefitDiscountAmount ?? "0")) - }", + "已优惠:¥${discountPrice()}", style: TextStyle( fontSize: 12.sp, color: Color(0xFF7B7B7B), @@ -384,6 +381,16 @@ class _SettlementOrderCommodity extends State { ); } + String discountPrice(){ + if(widget.minOrderInfo != null){ + return (widget.minOrderInfo.discountAmount ?? "0") + double.parse(widget.settleOrderInfo.benefitDiscountAmount ?? "0"); + }else if(widget.tableId < 0){ + return "0"; + }else { + return widget?.settleOrderInfo?.discountAmount ?? "0"; + } + } + String totalPrice() { if (widget.minOrderInfo != null && widget.minOrderInfo.orderProductVOList != null) { diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index e4424e29..42c98f39 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -137,11 +137,12 @@ class _StoreOrderPage extends State } queryMemberInfo() async { - BaseData baseData = await minService.memberInfo() - .catchError((error){debugPrint(error);}); + BaseData baseData = await minService.memberInfo().catchError((error) { + debugPrint(error); + }); if (baseData != null && baseData.isSuccess) { SharedPreferences.getInstance().then( - (value) => { + (value) => { value.setString('minMember', jsonEncode(baseData.data)), }, ); @@ -150,8 +151,10 @@ class _StoreOrderPage extends State ///获取父订单(火锅订单加菜前调用) getParentInfo() async { - BaseData baseData = await minService.getParentInfo("$tableId") - .catchError((error) {debugPrint(error);}); + BaseData baseData = + await minService.getParentInfo("$tableId").catchError((error) { + debugPrint(error); + }); if (baseData != null && baseData.isSuccess) { if (baseData.data != null) { parentId = baseData.data["id"]; @@ -182,7 +185,8 @@ class _StoreOrderPage extends State /// 查询店铺信息 queryStoreInfo() async { - BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) { + BaseData baseData = + await apiService.queryStoreInfo(storeId).catchError((error) { debugPrint(error); }); if (baseData != null && baseData.isSuccess) { @@ -202,19 +206,17 @@ class _StoreOrderPage extends State @override Widget build(BuildContext context) { - return - // WillPopScope( - // onWillPop: () async { - // if (dialogShowing) { - // debugPrint("ssssasdadsasdadasd"); - // SmartDialog.dismiss(); - // return false; - // } else { - // return true; - // } - // }, - // child: - Container( + return WillPopScope( + onWillPop: () async { + if (dialogShowing) { + debugPrint("ssssasdadsasdadasd"); + SmartDialog.dismiss(); + return false; + } else { + return true; + } + }, + child: Container( color: Colors.white, child: Stack( children: [ @@ -227,14 +229,15 @@ class _StoreOrderPage extends State controller: controller, dragStartBehavior: DragStartBehavior.start, physics: BouncingScrollPhysics(), - headerSliverBuilder: (BuildContext context, bool innerScrolled) { + headerSliverBuilder: + (BuildContext context, bool innerScrolled) { return [ SliverOverlapAbsorber( handle: NestedScrollView.sliverOverlapAbsorberHandleFor( context), sliver: SliverAppBar( - expandedHeight: - (storeInfo != null && storeInfo.couponVOList != null) + expandedHeight: (storeInfo != null && + storeInfo.couponVOList != null) ? 470.h : 365.h, floating: false, @@ -262,9 +265,8 @@ class _StoreOrderPage extends State ), ), flexibleSpace: FlexibleSpaceBar( - title: Title( - controller, - storeInfo != null ? storeInfo.storeName : ''), + title: Title(controller, + storeInfo != null ? storeInfo.storeName : ''), collapseMode: CollapseMode.pin, stretchModes: [ StretchMode.zoomBackground, @@ -490,8 +492,8 @@ class _StoreOrderPage extends State ), ], ), - ); - // ); + ), + ); } ///领取优惠券 @@ -555,6 +557,7 @@ class _StoreOrderPage extends State return; } } + await Navigator.of(context).pushNamed( '/router/settlement', arguments: { @@ -562,15 +565,15 @@ class _StoreOrderPage extends State "tableId": tableId, "parentCode": parentCode, "parentId": parentId, - "pName":pName, - "pid":pid, - "cName":cName, - "cid":cid, + "pName": pName, + "pid": pid, + "cName": cName, + "cid": cid, "shoppingCart": shopCarGoods, "numberOfPeople": numberOfPeople, }, ); - if(tableId >0){ + if (tableId > 0) { getParentInfo(); } queryShopCar().then((value) { @@ -651,18 +654,19 @@ class _StoreOrderPage extends State } ///选规格 - _queryMiNiDetail(String id,int count) async { + _queryMiNiDetail(String id, int count) async { EasyLoading.show(status: S.current.zhengzaijiazai); BaseData baseData = await minService.miNiDetail(id); if (baseData != null && baseData.isSuccess) { - showStoreSelector(baseData.data, id,count); + showStoreSelector(baseData.data, id, count); } } ///选规格弹窗 - showStoreSelector(MiNiDetail miNiDetail, String id,int count) async { - if (miNiDetail.attrList != null && miNiDetail.attrList.length == 1 - && miNiDetail.attrList[0].attrValueList.length == 1) { + showStoreSelector(MiNiDetail miNiDetail, String id, int count) async { + if (miNiDetail.attrList != null && + miNiDetail.attrList.length == 1 && + miNiDetail.attrList[0].attrValueList.length == 1) { _addShopCar(miNiDetail, [], count); } else { EasyLoading.dismiss(); @@ -687,7 +691,7 @@ class _StoreOrderPage extends State ///添加购物车 Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async { ProductSkuVOListBean productSku; - if (selectSkus!= null && selectSkus.length == 0) { + if (selectSkus != null && selectSkus.length == 0) { productSku = miNiDetail.productSkuVOList.first; } else { productSku = miNiDetail.productSkuVOList.firstWhere((element) { @@ -743,28 +747,28 @@ class _StoreOrderPage extends State ///查询购物车 Future queryShopCar() async { - pName="";//活动 - pid="";//活动 - cName="";//优惠券 - cid="";//优惠券 + pName = ""; //活动 + pid = ""; //活动 + cName = ""; //优惠券 + cid = ""; //优惠券 BaseData> baseDate = await minService.getShoppingCart(tableId); if (baseDate != null && baseDate.isSuccess && baseDate.data != null && baseDate.data.length > 0) { - if( baseDate.data[0].selectDiscount ==1){ + if (baseDate.data[0].selectDiscount == 1) { baseDate.data[0].couponList.forEach((element) { - if(element.isMaxCoupon){ + if (element.isMaxCoupon) { cName = element.promotionName; cid = element.id; } }); - }else if(baseDate.data[0].selectDiscount==2){ + } else if (baseDate.data[0].selectDiscount == 2) { baseDate.data[0].promotionInfoList.forEach((element) { - if(element.isMaxPromotion){ - pName=element.name; - pid=element.id; + if (element.isMaxPromotion) { + pName = element.name; + pid = element.id; } }); } diff --git a/lib/store/store_view/product_sku.dart b/lib/store/store_view/product_sku.dart index 8e7f6e0a..eb6b34b2 100644 --- a/lib/store/store_view/product_sku.dart +++ b/lib/store/store_view/product_sku.dart @@ -34,8 +34,8 @@ class ProductSku extends StatefulWidget { class _ProductSku extends State { List selectSkus = []; - int count = 1; + String selectedPrice = ""; @override void initState() { @@ -59,6 +59,7 @@ class _ProductSku extends State { return; } if (productSku == null) return; + selectedPrice = productSku.skuPrice; String skuId = productSku.id; if (widget.shopCarGoods == null || widget.shopCarGoods.shoppingCartSkuItemList == null) return; int shopSkuIndex = widget.shopCarGoods.shoppingCartSkuItemList.indexWhere((element) => skuId == element.id); @@ -98,6 +99,7 @@ class _ProductSku extends State { height: MediaQuery.of(context).size.height / 3 * 2, width: double.infinity, decoration: BoxDecoration( + // color: Color(0xFFFAFAFA), color: Color(0xFFFAFAFA), borderRadius: BorderRadius.only( topLeft: Radius.circular(8), @@ -123,7 +125,7 @@ class _ProductSku extends State { SizedBox( width: 10, ), - Expanded(child: Column( + Expanded(child:Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( @@ -159,7 +161,7 @@ class _ProductSku extends State { ), ), Text( - widget.miNiDetail.price, + selectedPrice, style: TextStyle( color: Color(0xFFFF7A1A), fontSize: 14.sp, @@ -169,9 +171,7 @@ class _ProductSku extends State { ], ), ], - )) - , - Spacer(), + )), InkWell( onTap: () { // Navigator.of(context).pop(); @@ -352,12 +352,12 @@ class _ProductSku extends State { Widget sweetnessItem(String name, bool isCheck) { return Container( child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 70.w, - height: 29.h, + height:30.h, alignment: Alignment.center, decoration: BoxDecoration( color: !isCheck ? Color(0xFFE5E5E5) : Color(0xFF32A060), diff --git a/lib/store/store_view/shop_goods.dart b/lib/store/store_view/shop_goods.dart index 56fd25d3..d8051136 100644 --- a/lib/store/store_view/shop_goods.dart +++ b/lib/store/store_view/shop_goods.dart @@ -198,7 +198,7 @@ class _ShopGoods extends State { ), ), if (widget.isShopCart || (widget.productListBean?.attrStyle??0) == 0) - InkWell( + GestureDetector( onTap: () { widget.add(widget.shoppingCartSkuItemListBean); }, diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index ae7cf7e8..0f4e50f4 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -230,11 +230,7 @@ class _StoreOrderListPage extends State { } }); } - return InkWell( - onTap: () { - widget.queryMiNiDetail(productListBeans[position].id,1); - }, - child: ShopGoods( + return ShopGoods( (ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) { widget.queryMiNiDetail(productListBeans[position].id,1); }, @@ -247,7 +243,6 @@ class _StoreOrderListPage extends State { isShopCart: false, queryMiNiDetail: widget.queryMiNiDetail, shoppingCartSkuItemListBean: shoppingCartSkuItemListBean, - ), ); } } diff --git a/lib/utils/ImgCachePath.dart b/lib/utils/ImgCachePath.dart new file mode 100644 index 00000000..fa3c41a0 --- /dev/null +++ b/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; + } +} \ No newline at end of file diff --git a/lib/view_widget/custom_image.dart b/lib/view_widget/custom_image.dart index de07a63d..4caaa7b9 100644 --- a/lib/view_widget/custom_image.dart +++ b/lib/view_widget/custom_image.dart @@ -1,8 +1,8 @@ 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: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 { final String src; @@ -29,20 +29,33 @@ class MImage extends StatelessWidget { this.radius = BorderRadius.zero, }); + File fileFromDocsDir(String filename) { + String pathName = p.join(ImgCachePath.instance.path, filename); + return File(pathName); + } + @override Widget build(BuildContext context) { Widget image = LayoutBuilder( builder: (context, constraints) { String imageUrl = ""; ///压缩图片 - if (src != null && src != "" && src.startsWith("http")) { - String oper = src.contains("?") ? "" :"?"; - imageUrl = - "$src$oper/imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}" - "x${constraints.constrainHeight() * scaleIndex}/format/webp/quality/100"; + // if (src != null && src != "" && src.startsWith("http")) { + // String oper = src.contains("?") ? "" :"?"; + // imageUrl = + // "$src$oper/imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}" + // "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")) { + imageUrl = "$src?imageView2/1/w/${_w}/h/${_h}/format/jpg/q/75"; } - // print(imageUrl); + // print("imageUrl:$imageUrl"); // print("constrainWidth: ${constraints.constrainWidth()}"); // print("constrainHeight: ${constraints.constrainHeight()}"); @@ -53,43 +66,38 @@ class MImage extends StatelessWidget { ); } Widget cachedNetworkImage; - if (src.startsWith("http")) { - cachedNetworkImage = CachedNetworkImage( - imageUrl: imageUrl, - cacheManager: DefaultCacheManager(), - fadeInDuration: Duration(milliseconds: 300), - fadeOutDuration: Duration(milliseconds: 300), - imageBuilder: (context, provide) { - return Image( - image: provide, - fit: fit, - ); - }, - errorWidget: (context, error, stackTrace) { - return Image.asset( - errorSrc, - fit: fit, - ); - }, - placeholder: (context, placeholder) { - return Image.asset( - fadeSrc, - fit: fit, - ); - }, - ); - } else if (src.startsWith("file")) { - cachedNetworkImage = Image.file( - File(src), - fit: fit, - errorBuilder: (context, error, stackTrace) { - return Image.asset( - errorSrc, - fit: fit, - ); - }, - ); - } + if (src.startsWith("http")) { + cachedNetworkImage = Image( + image: ResizeImage(NetworkToFileImage( + url: imageUrl, + file: fileFromDocsDir("resize"+src.replaceAll("https:", "") + .replaceAll("http:", "") + .replaceAll("pos.upload.gznl.top", "") + .replaceAll("/", "")), + debug: true, + ), + width: _w, + height: _h), + errorBuilder: (context, error, stackTrace) { + return Image.asset( + errorSrc, + fit: fit, + ); + }, + fit: fit, + ); + } else if (src.startsWith("file")) { + cachedNetworkImage = Image.file( + File(src), + fit: fit, + errorBuilder: (context, error, stackTrace) { + return Image.asset( + errorSrc, + fit: fit, + ); + }, + ); + } return cachedNetworkImage; }, ); diff --git a/lib/view_widget/text_image_dialog.dart b/lib/view_widget/text_image_dialog.dart index 119fbddf..074f64ce 100644 --- a/lib/view_widget/text_image_dialog.dart +++ b/lib/view_widget/text_image_dialog.dart @@ -38,7 +38,7 @@ class _TextImageWidget extends State { child: Center( child: Container( width: double.infinity, - margin: EdgeInsets.symmetric(horizontal:16.w), + margin: EdgeInsets.symmetric(horizontal:26.w), padding: EdgeInsets.symmetric(vertical: 20.h, horizontal: 24.w), decoration: BoxDecoration( color: Colors.white, diff --git a/pubspec.lock b/pubspec.lock index 301148f0..7b7b2595 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -50,13 +50,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: transitive description: @@ -209,13 +202,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: "direct main" description: @@ -269,7 +255,7 @@ packages: name: flutter_screenutil url: "https://pub.flutter-io.cn" source: hosted - version: "5.0.3" + version: "5.1.0" flutter_smart_dialog: dependency: "direct main" description: @@ -350,13 +336,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.15.0" - http: - dependency: transitive - description: - name: http - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.12.2" http_parser: dependency: transitive description: @@ -434,6 +413,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: transitive description: @@ -677,20 +663,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: transitive description: @@ -712,13 +684,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted 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: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 98b64fa5..6f6affec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,7 +65,7 @@ dependencies: scan: ^1.5.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 chewie_audio: ^1.1.2