# Conflicts: # lib/community/community_view/class_details.dart # lib/community/headlines/headlines_collection.dart # lib/home/home_view/shortcut_operation.dart # lib/mine/mine_page.dart # lib/mine/mine_view/mine_item.dart # lib/mine/mine_wallet_page.dart # lib/retrofit/min_api.dart # lib/retrofit/retrofit_api.dart # lib/store/store_order.dart # lib/store/store_view/product_sku.dart # lib/store/store_view/store_info.dart # lib/store/store_view/store_order_list.dartzyh
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 113 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 284 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 812 B |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 955 B |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,136 @@
|
||||
import 'package:dio/dio.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:huixiang/retrofit/data/base_data.dart'; |
||||
import 'package:huixiang/retrofit/data/comunity_comment.dart'; |
||||
import 'package:huixiang/retrofit/data/page.dart'; |
||||
import 'package:huixiang/retrofit/retrofit_api.dart'; |
||||
import 'package:huixiang/view_widget/classic_header.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 'community_list.dart'; |
||||
|
||||
class CommunityChildList extends StatefulWidget { |
||||
final String typeStr; |
||||
|
||||
CommunityChildList(this.typeStr); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _CommunityChildList(); |
||||
} |
||||
} |
||||
|
||||
class _CommunityChildList extends State<CommunityChildList> { |
||||
RefreshController refreshController = RefreshController(); |
||||
final ScrollController scrollController = ScrollController(); |
||||
ApiService apiService; |
||||
int pageNum = 1; |
||||
String userId; |
||||
bool isLoadMore = false; |
||||
|
||||
List<ComunityComment> comments = []; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_onRefresh(); |
||||
} |
||||
|
||||
_onRefresh() async { |
||||
queryCommunity(); |
||||
} |
||||
|
||||
///动态列表 |
||||
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<PageInfo<ComunityComment>> 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) { |
||||
setState(() { |
||||
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; |
||||
_onRefresh(); |
||||
}, |
||||
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: () { |
||||
_onRefresh(); |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
), |
||||
); |
||||
// }, |
||||
// ); |
||||
} |
||||
} |
@ -0,0 +1,493 @@
|
||||
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<ComunityComment> 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<StatefulWidget> createState() { |
||||
return _CommunityList(); |
||||
} |
||||
} |
||||
|
||||
class _CommunityList extends State<CommunityList> { |
||||
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(() {}); |
||||
// }, |
||||
}).then((value) { |
||||
widget.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, |
||||
), |
||||
], |
||||
) |
||||
], |
||||
), |
||||
), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,171 @@
|
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter/widgets.dart'; |
||||
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; |
||||
import 'package:huixiang/retrofit/data/article.dart'; |
||||
import 'package:huixiang/retrofit/data/collect_class_list.dart'; |
||||
import 'package:huixiang/retrofit/data/course_list.dart'; |
||||
import 'package:huixiang/retrofit/data/headlines_list.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:flutter_screenutil/flutter_screenutil.dart'; |
||||
import 'package:huixiang/view_widget/new_people_reward.dart'; |
||||
|
||||
class ActivityTopList extends StatefulWidget { |
||||
final List<Article> articleTop; |
||||
|
||||
ActivityTopList(this.articleTop); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _ActivityTopList(); |
||||
} |
||||
} |
||||
|
||||
class _ActivityTopList extends State<ActivityTopList> { |
||||
ApiService apiService; |
||||
BMFCoordinate latLng; |
||||
|
||||
final TextEditingController editingController = TextEditingController(); |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Container( |
||||
height: 220.h, |
||||
margin: EdgeInsets.only(top: 10), |
||||
child: ListView.builder( |
||||
scrollDirection: Axis.horizontal, |
||||
physics: BouncingScrollPhysics(), |
||||
padding: EdgeInsets.symmetric(horizontal: 10), |
||||
itemCount: widget.articleTop == null ? 0 : widget.articleTop.length, |
||||
itemBuilder: (context, position) { |
||||
return GestureDetector( |
||||
onTap: () { |
||||
Navigator.of(context).pushNamed('/router/web_page', |
||||
arguments: {"articleId": widget.articleTop[position].id}); |
||||
widget.articleTop[position].viewers = |
||||
(widget.articleTop[position].viewers + 1); |
||||
setState(() {}); |
||||
}, |
||||
child: headlinesCollectionItem(widget.articleTop[position], position), |
||||
); |
||||
}, |
||||
), |
||||
); |
||||
} |
||||
|
||||
Widget headlinesCollectionItem(Article articles, index) { |
||||
return Container( |
||||
width: 340.w, |
||||
height: 220.h, |
||||
decoration: BoxDecoration( |
||||
borderRadius: BorderRadius.circular(4), |
||||
boxShadow: [ |
||||
BoxShadow( |
||||
color: Colors.black.withAlpha(10), |
||||
offset: Offset(0, 3), |
||||
blurRadius: 14, |
||||
spreadRadius: 0, |
||||
) |
||||
], |
||||
color: Colors.black, |
||||
), |
||||
margin: EdgeInsets.symmetric( |
||||
horizontal: 6, |
||||
), |
||||
child:Column( |
||||
children: [ |
||||
Stack( |
||||
alignment: Alignment.bottomLeft, |
||||
children: [ |
||||
Stack( |
||||
children: [ |
||||
ClipRRect( |
||||
child: Opacity( |
||||
opacity: 0.8, |
||||
child: MImage( |
||||
widget?.articleTop[index]?.coverImg ?? "", |
||||
width: 340.w, |
||||
height: 220.h, |
||||
fit: BoxFit.cover, |
||||
errorSrc: "assets/image/default_1.png", |
||||
fadeSrc: "assets/image/default_1.png", |
||||
), |
||||
), |
||||
borderRadius: BorderRadius.vertical( |
||||
top: Radius.circular(4), |
||||
bottom: Radius.circular(4), |
||||
), |
||||
), |
||||
Container( |
||||
padding: EdgeInsets.only(left: 12.w, right: 12.w, top: 8), |
||||
alignment: Alignment.topLeft, |
||||
child: Row( |
||||
children: [ |
||||
Image.asset( |
||||
"assets/image/activity_hot.png", |
||||
width: 20, |
||||
height: 20, |
||||
fit: BoxFit.fill, |
||||
), |
||||
SizedBox( |
||||
width: 4.w, |
||||
), |
||||
Expanded( |
||||
child: Text( |
||||
"精选好文", |
||||
overflow: TextOverflow.ellipsis, |
||||
maxLines: 2, |
||||
style: TextStyle( |
||||
fontSize: 14.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
)), |
||||
], |
||||
), |
||||
Padding(padding:EdgeInsets.only(left: 12.w, right: 12.w, bottom: 8), |
||||
child: Column( |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
children: [ |
||||
Text( |
||||
widget?.articleTop[index]?.mainTitle ?? "", |
||||
overflow: TextOverflow.ellipsis, |
||||
maxLines: 2, |
||||
style: TextStyle( |
||||
fontSize: 16.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
SizedBox(height: 5.h), |
||||
Opacity(opacity:0.8, |
||||
child: Text( |
||||
widget?.articleTop[index]?.viceTitle ?? "", |
||||
overflow: TextOverflow.ellipsis, |
||||
maxLines: 2, |
||||
style: TextStyle( |
||||
fontSize: 12.sp, |
||||
fontWeight: MyFontWeight.regular, |
||||
color: Colors.white, |
||||
), |
||||
),) |
||||
|
||||
], |
||||
)), |
||||
], |
||||
), |
||||
], |
||||
) |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,556 @@
|
||||
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<String, dynamic> arguments; |
||||
|
||||
NewCommunityDetails({this.arguments}); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _NewCommunityDetails(); |
||||
} |
||||
} |
||||
|
||||
class _NewCommunityDetails extends State<NewCommunityDetails> 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<MemberCommentList> 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<Article> 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 WillPopScope( |
||||
onWillPop: () async { |
||||
Navigator.of(context).pop(true); |
||||
return false; |
||||
}, |
||||
child:AnnotatedRegion<SystemUiOverlayStyle>( |
||||
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<PageInfo<MemberCommentList>> 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(() {}); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
|
||||
/// name : "4" |
||||
/// number : 8 |
||||
|
||||
class MsgStats { |
||||
MsgStats({ |
||||
String name, |
||||
int number,}){ |
||||
_name = name; |
||||
_number = number; |
||||
} |
||||
|
||||
MsgStats.fromJson(dynamic json) { |
||||
_name = json['name']; |
||||
_number = json['number']; |
||||
} |
||||
String _name; |
||||
int _number; |
||||
|
||||
String get name => _name; |
||||
int get number => _number; |
||||
|
||||
Map<String, dynamic> toJson() { |
||||
final map = <String, dynamic>{}; |
||||
map['name'] = _name; |
||||
map['number'] = _number; |
||||
return map; |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -0,0 +1,256 @@
|
||||
import 'dart:collection'; |
||||
import 'dart:convert'; |
||||
|
||||
import 'package:dio/dio.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
||||
import 'package:huixiang/retrofit/data/base_data.dart'; |
||||
import 'package:huixiang/retrofit/data/coupon.dart'; |
||||
import 'package:huixiang/retrofit/retrofit_api.dart'; |
||||
import 'package:huixiang/utils/font_weight.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
|
||||
class ActivityCoupons extends StatefulWidget { |
||||
final String result; |
||||
|
||||
ActivityCoupons(this.result); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _ActivityCoupons(); |
||||
} |
||||
} |
||||
|
||||
class _ActivityCoupons extends State<ActivityCoupons> { |
||||
var resultData; |
||||
int pageNum = 1; |
||||
List<Coupon> coupons = []; |
||||
ApiService apiService; |
||||
var receiveCou = new Queue(); |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
resultData = jsonDecode(widget.result); |
||||
} |
||||
|
||||
receiveCoupon() async { |
||||
var id = receiveCou.removeFirst(); |
||||
if (apiService == null) { |
||||
SharedPreferences value = await SharedPreferences.getInstance(); |
||||
apiService = ApiService( |
||||
Dio(), |
||||
context: context, |
||||
token: value.getString("token"), |
||||
); |
||||
} |
||||
BaseData baseData = await apiService.receiveCoupon(id).catchError((onError) {}); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
if (receiveCou.length > 0) { |
||||
receiveCoupon(); |
||||
} else { |
||||
Navigator.of(context).pop(); |
||||
SmartDialog.showToast("领取成功", alignment: Alignment.center); |
||||
} |
||||
} |
||||
else{ |
||||
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
||||
Navigator.of(context).pop(); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Container( |
||||
margin: EdgeInsets.only(top: 150.h), |
||||
height: MediaQuery.of(context).size.height / 2, |
||||
child: Column( |
||||
children: [ |
||||
Container( |
||||
width: double.infinity, |
||||
height: MediaQuery.of(context).size.height / 2, |
||||
padding: EdgeInsets.only(top: 210.h), |
||||
margin: EdgeInsets.only(top: 20.h, left: 20, right: 20), |
||||
decoration: BoxDecoration( |
||||
image: DecorationImage( |
||||
fit: BoxFit.fill, |
||||
image: AssetImage("assets/image/activity_q.png"), |
||||
), |
||||
), |
||||
child: Column( |
||||
children: [ |
||||
Expanded( |
||||
child: couponsActivity(), |
||||
), |
||||
GestureDetector( |
||||
onTap: () { |
||||
(resultData["list"] as List).forEach((element) { |
||||
receiveCou..add(element["id"]); |
||||
}); |
||||
receiveCoupon(); |
||||
}, |
||||
child: Container( |
||||
margin: EdgeInsets.only( |
||||
left: 60.w, right: 60.w, top: 20.h, bottom: 20.h), |
||||
decoration: BoxDecoration( |
||||
gradient: new LinearGradient( |
||||
begin: Alignment.centerLeft, |
||||
end: Alignment.centerRight, |
||||
colors: [ |
||||
Color(0xFFFFDCA1), |
||||
Color(0xFFFAE4C0), |
||||
]), |
||||
borderRadius: BorderRadius.circular(22.5), |
||||
), |
||||
width: MediaQuery.of(context).size.width, |
||||
height: 40, |
||||
alignment: Alignment.center, |
||||
child: Text( |
||||
"立即领取", |
||||
style: TextStyle( |
||||
fontWeight: FontWeight.bold, |
||||
fontSize: 14.sp, |
||||
color: Color(0xFF4A4748), |
||||
), |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
SizedBox(height: 35), |
||||
GestureDetector( |
||||
onTap: () { |
||||
setState(() { |
||||
Navigator.of(context).pop(); |
||||
}); |
||||
}, |
||||
child: Image.asset( |
||||
"assets/image/yq_qx.png", |
||||
width: 34, |
||||
height: 34, |
||||
), |
||||
) |
||||
], |
||||
), |
||||
); |
||||
} |
||||
|
||||
Widget couponsActivity() { |
||||
return ListView.builder( |
||||
padding: EdgeInsets.zero, |
||||
itemCount: (resultData == null || resultData["list"] == null) |
||||
? 0 |
||||
: (resultData["list"] as List).length, |
||||
scrollDirection: Axis.vertical, |
||||
shrinkWrap: true, |
||||
physics: BouncingScrollPhysics(), |
||||
itemBuilder: (context, position) { |
||||
return GestureDetector( |
||||
onTap: () {}, |
||||
child: couponsItem(resultData["list"][position]), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
|
||||
Widget couponsItem(listData) { |
||||
return Container( |
||||
height: 69.h, |
||||
width: double.infinity, |
||||
decoration: BoxDecoration( |
||||
image: DecorationImage( |
||||
fit: BoxFit.fill, |
||||
image: AssetImage("assets/image/xin_rq.png"), |
||||
), |
||||
), |
||||
margin: EdgeInsets.symmetric(horizontal: 60, vertical: 5), |
||||
padding: EdgeInsets.only(left: 16.w, right: 10.w), |
||||
child: Row( |
||||
crossAxisAlignment: CrossAxisAlignment.center, |
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
||||
children: [ |
||||
if (listData["type"] == 1) |
||||
Text.rich( |
||||
TextSpan( |
||||
children: [ |
||||
TextSpan( |
||||
text: "¥", |
||||
style: TextStyle( |
||||
fontSize: 14.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFFDE5F3B), |
||||
), |
||||
), |
||||
TextSpan( |
||||
text: listData["discount"] ?? "", |
||||
style: TextStyle( |
||||
fontSize: 20.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFFDE5F3B), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
if (listData["type"] == 3) |
||||
Text( |
||||
"兑换券", |
||||
overflow: TextOverflow.ellipsis, |
||||
maxLines: 2, |
||||
style: TextStyle( |
||||
fontSize: 16.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFFDE5F3B), |
||||
), |
||||
), |
||||
if (listData["type"] == 2) |
||||
Padding( |
||||
padding: EdgeInsets.only(right: 20), |
||||
child: Text.rich( |
||||
TextSpan( |
||||
children: [ |
||||
TextSpan( |
||||
text: (listData["percent"] / 10).toString() ?? "", |
||||
style: TextStyle( |
||||
fontSize: 25.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFFDE5F3B), |
||||
), |
||||
), |
||||
TextSpan( |
||||
text: "折", |
||||
style: TextStyle( |
||||
fontSize: 14.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFFDE5F3B), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
)), |
||||
Expanded( |
||||
child: Padding( |
||||
padding: EdgeInsets.only(top: 4, bottom: 4, left: 10), |
||||
child: Column( |
||||
crossAxisAlignment: CrossAxisAlignment.center, |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
children: [ |
||||
Text( |
||||
listData["name"] ?? "", |
||||
overflow: TextOverflow.ellipsis, |
||||
maxLines: 2, |
||||
style: TextStyle( |
||||
fontSize: 16.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFF181818), |
||||
), |
||||
), |
||||
], |
||||
))), |
||||
], |
||||
), |
||||
); |
||||
} |
||||
} |