From 54d003fdb16c6b0a331bf46f874b8e5e87cbeb5a Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 26 Jul 2023 13:38:16 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E8=87=AA=E5=AE=9A=E4=B9=89toast?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E3=80=81=E8=AF=A6=E6=83=85=E9=A1=B5=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/widgets/custom_toast.dart | 23 ++ lib/common/widgets/stat/danmu.dart | 2 +- lib/common/widgets/stat/view.dart | 2 +- lib/main.dart | 5 +- lib/pages/video/detail/introduction/view.dart | 315 +++++++++--------- lib/pages/video/detail/reply/widgets/zan.dart | 4 +- 6 files changed, 184 insertions(+), 167 deletions(-) create mode 100644 lib/common/widgets/custom_toast.dart diff --git a/lib/common/widgets/custom_toast.dart b/lib/common/widgets/custom_toast.dart new file mode 100644 index 00000000..57b93c90 --- /dev/null +++ b/lib/common/widgets/custom_toast.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; + +class CustomToast extends StatelessWidget { + final String msg; + const CustomToast({Key? key, required this.msg}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + margin: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom), + padding: const EdgeInsets.symmetric(horizontal: 17, vertical: 10), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.8), + borderRadius: BorderRadius.circular(20), + ), + child: Text(msg, + style: Theme.of(context) + .textTheme + .labelMedium! + .copyWith(color: Theme.of(context).colorScheme.primary)), + ); + } +} diff --git a/lib/common/widgets/stat/danmu.dart b/lib/common/widgets/stat/danmu.dart index 5ea9cb01..44f662a9 100644 --- a/lib/common/widgets/stat/danmu.dart +++ b/lib/common/widgets/stat/danmu.dart @@ -24,7 +24,7 @@ class StatDanMu extends StatelessWidget { size: 14, color: color, ), - const SizedBox(width: 3), + const SizedBox(width: 2), Text( Utils.numFormat(danmu!), style: TextStyle( diff --git a/lib/common/widgets/stat/view.dart b/lib/common/widgets/stat/view.dart index 4f2b3441..8b97b605 100644 --- a/lib/common/widgets/stat/view.dart +++ b/lib/common/widgets/stat/view.dart @@ -24,7 +24,7 @@ class StatView extends StatelessWidget { size: 13, color: color, ), - const SizedBox(width: 3), + const SizedBox(width: 2), Text( Utils.numFormat(view!), style: TextStyle( diff --git a/lib/main.dart b/lib/main.dart index ce0793c1..af386de1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:dynamic_color/dynamic_color.dart'; +import 'package:pilipala/common/widgets/custom_toast.dart'; import 'package:pilipala/http/init.dart'; import 'package:pilipala/pages/search/index.dart'; import 'package:pilipala/pages/video/detail/index.dart'; @@ -61,7 +62,9 @@ class MyApp extends StatelessWidget { fallbackLocale: const Locale("zh", "CN"), getPages: Routes.getPages, home: const MainApp(), - builder: FlutterSmartDialog.init(), + builder: FlutterSmartDialog.init( + toastBuilder: (String msg) => CustomToast(msg: msg), + ), navigatorObservers: [ VideoDetailPage.routeObserver, SearchPage.routeObserver diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 8b1a6380..682bfda0 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -107,6 +107,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { sheetHeight = localCache.get('sheetHeight'); } + // 收藏 showFavBottomSheet() { if (videoIntroController.user.get(UserBoxKey.userMid) == null) { SmartDialog.showToast('账号未登录'); @@ -122,8 +123,20 @@ class _VideoInfoState extends State with TickerProviderStateMixin { ); } + // 视频介绍 + showIntroDetail() { + showBottomSheet( + context: context, + enableDrag: true, + builder: (BuildContext context) { + return IntroDetail(videoDetail: widget.videoDetail!); + }, + ); + } + @override Widget build(BuildContext context) { + ThemeData t = Theme.of(context); return SliverPadding( padding: const EdgeInsets.only( left: StyleString.safeSpace, right: StyleString.safeSpace, top: 13), @@ -133,15 +146,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( - onTap: () { - showBottomSheet( - context: context, - enableDrag: true, - builder: (BuildContext context) { - return IntroDetail(videoDetail: widget.videoDetail!); - }, - ); - }, + onTap: () => showIntroDetail(), child: Row( children: [ Expanded( @@ -168,9 +173,7 @@ class _VideoInfoState extends State with TickerProviderStateMixin { MaterialStateProperty.all(EdgeInsets.zero), backgroundColor: MaterialStateProperty.resolveWith((states) { - return Theme.of(context) - .highlightColor - .withOpacity(0.2); + return t.highlightColor.withOpacity(0.2); }), ), onPressed: () { @@ -189,46 +192,49 @@ class _VideoInfoState extends State with TickerProviderStateMixin { ], ), ), - const SizedBox(height: 6), - Row( - children: [ - const SizedBox(width: 2), - StatView( - theme: 'black', - view: !widget.loadingStatus - ? widget.videoDetail!.stat!.view - : videoItem['stat'].view, - size: 'medium', - ), - const SizedBox(width: 10), - StatDanMu( - theme: 'black', - danmu: !widget.loadingStatus - ? widget.videoDetail!.stat!.danmaku - : videoItem['stat'].danmaku, - size: 'medium', - ), - const SizedBox(width: 10), - Text( - Utils.dateFormat( - !widget.loadingStatus - ? widget.videoDetail!.pubdate - : videoItem['pubdate'], - formatType: 'detail'), - style: const TextStyle(fontSize: 12), - ), - ], + GestureDetector( + onTap: () => showIntroDetail(), + child: Row( + children: [ + StatView( + theme: 'gray', + view: !widget.loadingStatus + ? widget.videoDetail!.stat!.view + : videoItem['stat'].view, + size: 'medium', + ), + const SizedBox(width: 10), + StatDanMu( + theme: 'gray', + danmu: !widget.loadingStatus + ? widget.videoDetail!.stat!.danmaku + : videoItem['stat'].danmaku, + size: 'medium', + ), + const SizedBox(width: 10), + Text( + Utils.dateFormat( + !widget.loadingStatus + ? widget.videoDetail!.pubdate + : videoItem['pubdate'], + formatType: 'detail'), + style: TextStyle( + fontSize: 12, + color: t.colorScheme.outline, + ), + ), + ], + ), ), + const SizedBox(height: 6), // 点赞收藏转发 - Padding( - padding: const EdgeInsets.only(top: 15), - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: actionRow( - context, - videoIntroController, - videoDetailCtr, - ), + SingleChildScrollView( + padding: const EdgeInsets.only(top: 7, bottom: 7), + scrollDirection: Axis.horizontal, + child: actionRow( + context, + videoIntroController, + videoDetailCtr, ), ), // 合集 @@ -237,122 +243,105 @@ class _VideoInfoState extends State with TickerProviderStateMixin { seasonPanel(widget.videoDetail!.ugcSeason!, widget.videoDetail!.pages!.first.cid, sheetHeight) ], - // Divider( - // height: 26, - // color: Theme.of(context).dividerColor.withOpacity(0.1), - // ), - const SizedBox(height: 20), GestureDetector( - onTap: () { - int mid = !widget.loadingStatus - ? widget.videoDetail!.owner!.mid - : videoItem['owner'].mid; - String face = !widget.loadingStatus - ? widget.videoDetail!.owner!.face - : videoItem['owner'].face; - Get.toNamed('/member?mid=$mid', arguments: { - 'face': face, - 'heroTag': (mid + 99).toString() - }); - }, - child: Row( - children: [ - const SizedBox(width: 5), - NetworkImgLayer( - type: 'avatar', - src: !widget.loadingStatus - ? widget.videoDetail!.owner!.face - : videoItem['owner'].face, - width: 34, - height: 34, - fadeInDuration: Duration.zero, - fadeOutDuration: Duration.zero, - ), - const SizedBox(width: 10), - Text( - !widget.loadingStatus - ? widget.videoDetail!.owner!.name - : videoItem['owner'].name, - style: const TextStyle(fontSize: 13), - ), - const SizedBox(width: 10), - Text( - widget.loadingStatus - ? '- 粉丝' - : Utils.numFormat( - videoIntroController.userStat['follower']), - style: TextStyle( - fontSize: Theme.of(context) - .textTheme - .labelSmall! - .fontSize, - color: Theme.of(context).colorScheme.outline), - ), - const Spacer(), - AnimatedOpacity( - opacity: widget.loadingStatus ? 0 : 1, - duration: const Duration(milliseconds: 150), - child: SizedBox( - height: 32, - child: Obx( - () => videoIntroController.followStatus.isNotEmpty - ? TextButton( - onPressed: () => videoIntroController - .actionRelationMod(), - style: TextButton.styleFrom( - padding: const EdgeInsets.only( - left: 8, right: 8), - foregroundColor: - videoIntroController.followStatus[ - 'attribute'] != - 0 - ? Theme.of(context) - .colorScheme - .outline - : Theme.of(context) - .colorScheme - .onPrimary, - backgroundColor: - videoIntroController.followStatus[ - 'attribute'] != - 0 - ? Theme.of(context) - .colorScheme - .onInverseSurface - : Theme.of(context) - .colorScheme - .primary, // 设置按钮背景色 - ), - child: Text( - videoIntroController.followStatus[ - 'attribute'] != - 0 - ? '已关注' - : '关注', - style: TextStyle( - fontSize: Theme.of(context) - .textTheme - .labelMedium! - .fontSize), - ), - ) - : ElevatedButton( - onPressed: () => videoIntroController - .actionRelationMod(), - child: const Text('关注'), - ), + onTap: () { + int mid = !widget.loadingStatus + ? widget.videoDetail!.owner!.mid + : videoItem['owner'].mid; + String face = !widget.loadingStatus + ? widget.videoDetail!.owner!.face + : videoItem['owner'].face; + Get.toNamed('/member?mid=$mid', arguments: { + 'face': face, + 'heroTag': (mid + 99).toString() + }); + }, + child: Padding( + padding: const EdgeInsets.only( + top: 12, bottom: 12, left: 4, right: 4), + child: Row( + children: [ + NetworkImgLayer( + type: 'avatar', + src: !widget.loadingStatus + ? widget.videoDetail!.owner!.face + : videoItem['owner'].face, + width: 34, + height: 34, + fadeInDuration: Duration.zero, + fadeOutDuration: Duration.zero, ), - ), + const SizedBox(width: 10), + Text( + !widget.loadingStatus + ? widget.videoDetail!.owner!.name + : videoItem['owner'].name, + style: const TextStyle(fontSize: 13), + ), + const SizedBox(width: 10), + Text( + widget.loadingStatus + ? '-' + : Utils.numFormat(videoIntroController + .userStat['follower']), + style: TextStyle( + fontSize: t.textTheme.labelSmall!.fontSize, + color: t.colorScheme.outline), + ), + const Spacer(), + AnimatedOpacity( + opacity: widget.loadingStatus ? 0 : 1, + duration: const Duration(milliseconds: 150), + child: SizedBox( + height: 32, + child: Obx( + () => videoIntroController + .followStatus.isNotEmpty + ? TextButton( + onPressed: () => videoIntroController + .actionRelationMod(), + style: TextButton.styleFrom( + padding: const EdgeInsets.only( + left: 8, right: 8), + foregroundColor: + videoIntroController + .followStatus[ + 'attribute'] != + 0 + ? t.colorScheme.outline + : t.colorScheme.onPrimary, + backgroundColor: + videoIntroController + .followStatus[ + 'attribute'] != + 0 + ? t.colorScheme + .onInverseSurface + : t.colorScheme + .primary, // 设置按钮背景色 + ), + child: Text( + videoIntroController.followStatus[ + 'attribute'] != + 0 + ? '已关注' + : '关注', + style: TextStyle( + fontSize: t.textTheme + .labelMedium!.fontSize), + ), + ) + : ElevatedButton( + onPressed: () => videoIntroController + .actionRelationMod(), + child: const Text('关注'), + ), + ), + ), + ), + ], ), - const SizedBox(width: 4) - ], - ), - ), - const SizedBox(height: 12), - // Divider( - // height: 12, - // color: Theme.of(context).dividerColor.withOpacity(0.1), - // ), + )), ], ) : const SizedBox( diff --git a/lib/pages/video/detail/reply/widgets/zan.dart b/lib/pages/video/detail/reply/widgets/zan.dart index 8e630260..bc08e839 100644 --- a/lib/pages/video/detail/reply/widgets/zan.dart +++ b/lib/pages/video/detail/reply/widgets/zan.dart @@ -22,6 +22,7 @@ class ZanButton extends StatefulWidget { class _ZanButtonState extends State { // 评论点赞 onLikeReply() async { + SmartDialog.showLoading(msg: 'pilipala ...'); ReplyItemModel replyItem = widget.replyItem!; int oid = replyItem.oid!; int rpid = replyItem.rpid!; @@ -29,8 +30,9 @@ class _ZanButtonState extends State { int action = replyItem.action == 0 ? 1 : 0; var res = await ReplyHttp.likeReply( type: widget.replyType!.index, oid: oid, rpid: rpid, action: action); + SmartDialog.dismiss(); if (res['status']) { - SmartDialog.showToast(replyItem.action == 0 ? '点赞成功' : '取消赞'); + SmartDialog.showToast(replyItem.action == 0 ? '点赞成功 👍' : '取消赞 💔'); if (action == 1) { replyItem.like = replyItem.like! + 1; replyItem.action = 1;