diff --git a/lib/community/community_view/class_details.dart b/lib/community/community_view/class_details.dart index 1c2f8df3..811c2199 100644 --- a/lib/community/community_view/class_details.dart +++ b/lib/community/community_view/class_details.dart @@ -25,13 +25,14 @@ class ClassDetails extends StatefulWidget { final Map arguments; ClassDetails({this.arguments}); + @override State createState() { return _ClassDetails(); } } -class _ClassDetails extends State with WidgetsBindingObserver{ +class _ClassDetails extends State with WidgetsBindingObserver { VideoPlayerController videoPlayerController; Chewie chewies; ChewieController chewieAudioController; @@ -68,7 +69,8 @@ class _ClassDetails extends State with WidgetsBindingObserver{ token: value.getString("token"), ); } - BaseData> baseData = await apiService.catalogList(courseId).catchError((onError) {}); + BaseData> baseData = + await apiService.catalogList(courseId).catchError((onError) {}); if (baseData != null && baseData.isSuccess) { setState(() { chapterList.clear(); @@ -76,7 +78,6 @@ class _ClassDetails extends State with WidgetsBindingObserver{ chapterIndex = 0; initVideo(chapterList[chapterIndex].content.fileUrl); }); - } EasyLoading.dismiss(); } @@ -91,7 +92,8 @@ class _ClassDetails extends State with WidgetsBindingObserver{ token: value.getString("token"), ); } - BaseData baseData = await apiService.course(id).catchError((error) {}); + BaseData baseData = + await apiService.course(id).catchError((error) {}); if (baseData != null && baseData.isSuccess) { setState(() { course = baseData.data; @@ -99,7 +101,6 @@ class _ClassDetails extends State with WidgetsBindingObserver{ } } - @override void dispose() { /** @@ -122,10 +123,7 @@ class _ClassDetails extends State with WidgetsBindingObserver{ void didChangeMetrics() { WidgetsBinding.instance.addPostFrameCallback((_) { if (!mounted) return; - if (MediaQuery - .of(context) - .viewInsets - .bottom == 0) { + if (MediaQuery.of(context).viewInsets.bottom == 0) { if (isKeyBoardShow) { FocusScope.of(context).requestFocus(FocusNode()); if (mounted) @@ -147,198 +145,211 @@ class _ClassDetails extends State with WidgetsBindingObserver{ Widget build(BuildContext context) { return Scaffold( body: Container( - child:Column( + child: Column( children: [ Expanded( child: SingleChildScrollView( - physics: BouncingScrollPhysics(), - child: Column( - children: [ - Stack( - children: [ - videoWidget( - MediaQuery.of(context).size.width, - videoPlayerController != null - ? (MediaQuery.of(context).size.width) / - videoPlayerController.value.aspectRatio - : MediaQuery.of(context).size.width / 2, - chapterList.length>chapterIndex?chapterList[chapterIndex].content.coverImg:"", - ), - Container( - margin: EdgeInsets.only(top: 40.h, left: 16.w, right: 16.w), - decoration: BoxDecoration( - color: Colors.transparent, + physics: BouncingScrollPhysics(), + child: Column( + children: [ + Stack( + children: [ + videoWidget( + MediaQuery.of(context).size.width, + videoPlayerController != null + ? (MediaQuery.of(context).size.width) / + videoPlayerController.value.aspectRatio + : MediaQuery.of(context).size.width / 2, + chapterList.length > chapterIndex + ? chapterList[chapterIndex].content.coverImg + : "", ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - GestureDetector( - child: Image.asset( - "assets/image/integral_return.png", - width: 24, - height: 24, + Container( + margin: EdgeInsets.only( + top: 40.h, left: 16.w, right: 16.w), + decoration: BoxDecoration( + color: Colors.transparent, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + GestureDetector( + child: Image.asset( + "assets/image/integral_return.png", + width: 24, + height: 24, + ), + onTap: () { + Navigator.of(context).pop( + course != null ? course.viewers + 1 : 0); + }, ), - onTap: () { - Navigator.of(context).pop(course != null ? course.viewers+1 :0); - }, - ), - ], + ], + ), ), - ), - ], - ), - Container( - height: 123, - margin: EdgeInsets.only(bottom: 16.h), - padding: EdgeInsets.only(left: 16,top: 16,right: 10), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(12), - offset: Offset(0, 2), - blurRadius: 14, - spreadRadius: 0, - ) ], ), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Container( - height: 22.h, - width: 40.w, - alignment: Alignment.center, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(2), - border: Border.all( - width: 1, - color: Color(0xFFFF7A1A), - style: BorderStyle.solid, - ), - ), - child: Text( - ( course?.tags != null && course.tags.length > 0 )?course.tags[0] : "", - style: TextStyle( - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - color: Color(0xFFFF7A1A), - ), - ), - ), - SizedBox( - width: 6.w, - ), - Expanded( - child: Text( - course != null ?course.subject:"", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 16.sp, - fontWeight: MyFontWeight.semi_bold, - color: Color(0xFF1A1A1A), - ), - ), - flex: 1, - ) - ], - ), - SizedBox( - height:10.h, - ), - Padding(padding: EdgeInsets.only(right: 16), - child: Row( + Container( + height: 123, + margin: EdgeInsets.only(bottom: 16.h), + padding: EdgeInsets.only(left: 16, top: 16, right: 10), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(12), + offset: Offset(0, 2), + blurRadius: 14, + spreadRadius: 0, + ) + ], + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( children: [ - Expanded( - child: Text( - "讲师:${course !=null ? course.author.name :""}", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Colors.black, - ), - )), - Text( - "播放次数:", - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF808080), + Container( + height: 22.h, + width: 40.w, + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(2), + border: Border.all( + width: 1, + color: Color(0xFFFF7A1A), + style: BorderStyle.solid, + ), + ), + child: Text( + (course?.tags != null && + course.tags.length > 0) + ? course.tags[0] + : "", + style: TextStyle( + fontSize: 14.sp, + fontWeight: MyFontWeight.medium, + color: Color(0xFFFF7A1A), + ), ), ), SizedBox( - width:4, + width: 6.w, ), - Text( - course != null ? course.viewers.toString() :"", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Color(0xFF808080), + Expanded( + child: Text( + course != null ? course.subject : "", + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + fontSize: 16.sp, + fontWeight: MyFontWeight.semi_bold, + color: Color(0xFF1A1A1A), + ), ), - ), + flex: 1, + ) ], - ),), - SizedBox( - height:10.h, - ), - Text( - course != null ?course.introduce:"", - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - color: Colors.black, ), - ), - ], + SizedBox( + height: 10.h, + ), + Padding( + padding: EdgeInsets.only(right: 16), + child: Row( + children: [ + Expanded( + child: Text( + "讲师:${course != null ? course.author.name : ""}", + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Colors.black, + ), + )), + Text( + "播放次数:", + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF808080), + ), + ), + SizedBox( + width: 4, + ), + Text( + course != null + ? course.viewers.toString() + : "", + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Color(0xFF808080), + ), + ), + ], + ), + ), + SizedBox( + height: 10.h, + ), + Text( + course != null ? course.introduce : "", + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + fontSize: 12.sp, + fontWeight: MyFontWeight.regular, + color: Colors.black, + ), + ), + ], + ), ), - ), - anthology(), - CommentList( - commentKey, - course?.likes ?? course?.likes?? 0, - widget.arguments["id"], - 3, - isKeyBoardShow, - _reply, - _delCommentTips, - 12.sp, - requestApiFinish: (total){setState(() { - commentTotal = total; - });}, - ), - if (commentTotal == 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), + anthology(), + CommentList( + commentKey, + course?.likes ?? course?.likes ?? 0, + widget.arguments["id"], + 3, + isKeyBoardShow, + _reply, + _delCommentTips, + 12.sp, + requestApiFinish: (total) { + setState(() { + commentTotal = total; + }); + }, + ), + if (commentTotal == 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, ), - flex: 1,), + /// 富文本评论的输入框 InputComment( inputKey, @@ -349,7 +360,7 @@ class _ClassDetails extends State with WidgetsBindingObserver{ _toComment, _queryMemberComment, _queryCourseLikes, - isLike:course?.selfLiked, + isLike: course?.selfLiked, ), ], ), @@ -361,91 +372,95 @@ class _ClassDetails extends State with WidgetsBindingObserver{ videoPlayerController = VideoPlayerController.network( videoUrl, )..initialize().then((value) { - chewieAudioController = ChewieController( - videoPlayerController: videoPlayerController, - aspectRatio: videoPlayerController.value.aspectRatio, - //宽高比 - autoPlay: false, - //自动播放 - looping: false, - //循环播放 - allowFullScreen: true, - // 拖动条样式颜色 - materialProgressColors: chewie.ChewieProgressColors( - playedColor: Colors.white, - handleColor: Colors.white, - backgroundColor: Colors.grey, - bufferedColor: Colors.transparent, - ), - autoInitialize: true, - ); - chewieAudioController.addListener(_fullScreenListener); - if (mounted) setState(() {}); - }); + chewieAudioController = ChewieController( + videoPlayerController: videoPlayerController, + aspectRatio: videoPlayerController.value.aspectRatio, + //宽高比 + autoPlay: false, + //自动播放 + looping: false, + //循环播放 + allowFullScreen: true, + // 拖动条样式颜色 + materialProgressColors: chewie.ChewieProgressColors( + playedColor: Colors.white, + handleColor: Colors.white, + backgroundColor: Colors.grey, + bufferedColor: Colors.transparent, + ), + autoInitialize: true, + ); + chewieAudioController.addListener(_fullScreenListener); + if (mounted) setState(() {}); + }); } Future _fullScreenListener() async { if (!chewieAudioController.isFullScreen) { - Future.delayed(Duration(seconds: 1), () { - }); + Future.delayed(Duration(seconds: 1), () {}); } } Widget videoWidget(double width, double height, src) { print("src : $src"); return MediaQuery( - data: MediaQuery.of(context).copyWith( - textScaleFactor: 0.9, - ), - child: !isShowImg - ? (chewieAudioController != null - ? Container( - width: width, - height: height, - child: chewies = Chewie( - controller: chewieAudioController, + data: MediaQuery.of(context).copyWith( + textScaleFactor: 0.9, ), - ) - : Container( - width: width, - height: height, - )) - : GestureDetector( - onTap: (){ - setState(() { - isShowImg = false; - }); - }, - child: Container( - width: width, - height: width / 7 * 5, - color: Colors.black, - child: Stack( - children: [ - Center( - child: MImage( - src, - fit: BoxFit.cover, - 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, - ), + child: Stack(children: [ + (chewieAudioController != null + ? Container( + width: width, + height: height, + child: chewies = Chewie( + controller: chewieAudioController, + ), + ) + : Container( + width: width, + height: height, + )), + if(isShowImg) + GestureDetector( + onTap: () { + setState(() { + isShowImg = false; + if(chewieAudioController != null) + chewieAudioController.play(); + }); + }, + child: Container( + width: width, + height: height, + color: Colors.black, + child: Stack( + children: [ + Center( + child: MImage( + src, + width:width, + height: height, + fit: BoxFit.fill, + 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, + ), + ), + ], ), - ], + ), ), - ), - ), - ); + ])); } Widget anthology() { - return Container( + return Container( color: Colors.white, margin: EdgeInsets.only(bottom: 16), padding: EdgeInsets.all(16), @@ -475,21 +490,23 @@ class _ClassDetails extends State with WidgetsBindingObserver{ ), Container( height: 70.h, - margin: EdgeInsets.only(top:10), + margin: EdgeInsets.only(top: 10), child: ListView.builder( scrollDirection: Axis.horizontal, physics: BouncingScrollPhysics(), - itemCount:chapterList.length, + itemCount: chapterList.length, itemBuilder: (context, position) { return GestureDetector( onTap: () { setState(() { chapterIndex = position; isShowImg = true; + if(chewieAudioController != null) + chewieAudioController.pause(); initVideo(chapterList[position].content.fileUrl); }); }, - child: classSelectItem(chapterList[position],position), + child: classSelectItem(chapterList[position], position), ); }, ), @@ -499,7 +516,7 @@ class _ClassDetails extends State with WidgetsBindingObserver{ ); } - Widget classSelectItem(Chapter chapterList,position) { + Widget classSelectItem(Chapter chapterList, position) { return Container( width: 106.w, alignment: Alignment.center, @@ -510,23 +527,24 @@ class _ClassDetails extends State with WidgetsBindingObserver{ padding: EdgeInsets.all(8), decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), - color: position==chapterIndex ? Color(0xFF32A060): Color(0xFFE5E5E5), + color: position == chapterIndex ? Color(0xFF32A060) : Color(0xFFE5E5E5), ), - child: Text( + child: Text( chapterList?.name ?? chapterList.name ?? "", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, - color: position == chapterIndex ? Colors.white :Color(0xFF7C7C7C), + color: position == chapterIndex ? Colors.white : Color(0xFF7C7C7C), ), ), ); } - ///课程点赞 _queryCourseLikes() async { - BaseData baseData = await apiService.courseLikes(widget.arguments["id"]).catchError((onError) {}); + BaseData baseData = await apiService + .courseLikes(widget.arguments["id"]) + .catchError((onError) {}); if (baseData != null && baseData.isSuccess) { setState(() { if (course.selfLiked ?? false) @@ -546,7 +564,7 @@ class _ClassDetails extends State with WidgetsBindingObserver{ BaseData baseData = await apiService.memberComment({ "content": content, "parentId": parenId, - "relationalId":widget.arguments["id"], + "relationalId": widget.arguments["id"], "relationalType": 3 }).catchError((error) {}); if (baseData != null && baseData.isSuccess) { @@ -566,10 +584,7 @@ class _ClassDetails extends State with WidgetsBindingObserver{ scrollController.animateTo( first.dy + scrollController.offset - - (kToolbarHeight + MediaQuery - .of(context) - .padding - .top), + (kToolbarHeight + MediaQuery.of(context).padding.top), duration: Duration(milliseconds: 300), curve: Curves.easeIn, ); diff --git a/lib/settlement/settlement.dart b/lib/settlement/settlement.dart index 1622bc1f..2a0157c5 100644 --- a/lib/settlement/settlement.dart +++ b/lib/settlement/settlement.dart @@ -333,6 +333,7 @@ class _Settlement extends State { "id": orderId, }, ); + Navigator.of(context).pop(); } @override diff --git a/lib/store/store_view/product_sku.dart b/lib/store/store_view/product_sku.dart index 9b292e8f..34320ebf 100644 --- a/lib/store/store_view/product_sku.dart +++ b/lib/store/store_view/product_sku.dart @@ -50,9 +50,14 @@ class _ProductSku extends State { buildCount() { count = 1; - ProductSkuVOListBean productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) { - return skuY(element, selectSkus); - }); + ProductSkuVOListBean productSku; + try { + productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) { + return skuY(element, selectSkus); + }); + }catch(ex){ + return; + } if (productSku == null) return; String skuId = productSku.id; if (widget.shopCarGoods == null || widget.shopCarGoods.shoppingCartSkuItemList == null) return;