From fa705507ba574c857b1667553737d23b1b7ff495 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 12 五月 2022 12:06:31 +0800 Subject: [PATCH] 后端模板代码优化 --- src/main/resources/code/flutter_module/lib/mine.dart | 798 ++++++++++++++++++++++---------------------------------- 1 files changed, 316 insertions(+), 482 deletions(-) diff --git a/src/main/resources/code/flutter_module/lib/mine.dart b/src/main/resources/code/flutter_module/lib/mine.dart index 9c826d9..b956cdb 100644 --- a/src/main/resources/code/flutter_module/lib/mine.dart +++ b/src/main/resources/code/flutter_module/lib/mine.dart @@ -1,22 +1,16 @@ -import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_boost/flutter_boost.dart'; -import '../../api/video_api.dart'; + import '../../ui/widget/button.dart'; -import '../../ui/widget/video_item.dart'; -import '../../utils/db_manager.dart'; import '../../utils/jump_page.dart'; -import '../../utils/string_util.dart'; import '../../utils/ui_constant.dart'; import '../../utils/user_util.dart'; - import 'model/user/user_info.dart'; -import 'model/video/watch_record_model.dart'; -import 'utils/share_preference.dart'; -import 'package:share_plus/share_plus.dart'; +import 'ui/widget/ad_express.dart'; +import 'ui/widget/images_widget.dart'; +import 'utils/config_util.dart'; class MinePage extends StatefulWidget { MinePage({Key? key, required this.title}) : super(key: key); @@ -29,32 +23,30 @@ class _MinePageState extends State<MinePage> with SingleTickerProviderStateMixin, PageVisibilityObserver { + static const Color COLOR_CONTENT = Color(0xFF999999); + static const Color COLOR_TITLE = Color(0xFF000000); + static const Color COLOR_PORTRAIT_BG = Color(0xFFDBDBDB); + static const Color COLOR_HIGHLIGHT = ColorConstant.theme; + int index = 1; UserInfo? _user; - List<WatchRecordModel> recordList = []; - int collectedVideoCount = 0; - int favoriteVideoCount = 0; - String applink = ""; + int goldCorn = 0; + String balance = "0.00"; + + int firstTeamCount = 0; + int secondTeamCount = 0; + int msgCount = 0; @override void initState() { super.initState(); - if (Platform.isIOS) { - MySharedPreferences.getInstance().getString("appLink").then((value) { - setState(() { - applink = value!; - }); - }); - } _refreshData(); } void _refreshData() { updateUserInfo(); - loadWatchRecord(); - loadUserVideoCount(); } void updateUserInfo() async { @@ -65,6 +57,8 @@ return; } + _user = await UserUtil.getUserInfo(); + UserUtil.updateUserInfo(context).then((value) { print("user:$value"); setState(() { @@ -73,33 +67,15 @@ }); } - void loadWatchRecord() async { - List<WatchRecordModel> temp = await DBManager.listWatchRecord(1, 20); - setState(() { - recordList = temp; - }); - } - - void loadUserVideoCount() async { - if (!await UserUtil.isLogin()) { + void jumpPage(String name, + {Map<String, dynamic>? params, bool needLogin = true}) async { + bool login = await UserUtil.isLogin(); + if (!login && needLogin) { + jumpPage("LoginPage", needLogin: false); return; } - Map<String, dynamic>? result = - await VideoApiUtil.getUserVideoCount(context); - if (result == null) { - return; - } - if (result["IsPost"] == "true") { - setState(() { - collectedVideoCount = result["Data"]["collectionCount"]; - favoriteVideoCount = result["Data"]["attentionCount"]; - }); - } - } - - void jumpPage(String name, {Map<String, dynamic>? params}) { - JumpPageUtil.jumpPage(name, context, native: Platform.isIOS,params: params, - callback: (data) { + JumpPageUtil.jumpPage(name, context, + native: Constant.NATIVE, params: params, callback: (data) { _refreshData(); }); } @@ -148,452 +124,316 @@ Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, - body: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Container( - alignment: Alignment.center, - padding: EdgeInsets.only( - top: 15 + MediaQuery.of(context).viewPadding.top, bottom: 15), - color: ColorConstant.theme, - child: const Text("鎴戠殑", - style: TextStyle(fontSize: 20, color: Colors.white)), + body: Column(children: [ + Expanded( + child: Stack(children: [ + AspectRatio( + aspectRatio: 1.344, + child: Image.asset("assets/imgs/mine/ic_top_bg.png"), ), - Expanded( - child: Container( - height: 20, - color: Colors.white, - child: SingleChildScrollView( - child: Column( - children: [ - Container( - height: 51, - ), - - //涓汉淇℃伅 - InkWell( - child: Row( - children: [ - Container( - width: 18, - ), - portraitWidget(), - Container( - width: 10, - ), - _user != null - ? personInfoWidget() - : - //鐧诲綍妗� - loginBtnWidget(), - Container( - width: 18, - ), - ], - ), - onTap: () { - UserUtil.isLogin().then((value) { - if (value) { - jumpPage("PersonInfoPage"); - } - }); - }, - ), - Container( - height: 8, - ), - //绛惧悕 - signWidget(), - Container( - height: 23, - ), - //鏀惰棌锛岃拷鍓э紝缂撳瓨 - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - InkWell( - onTap: () { - UserUtil.isLogin().then((value) { - if (!value) { - jumpPage("EmailLoginPage"); - return; - } - jumpPage("VideoCollectedPage"); - }); - }, - child: Column( - children: [ - const Text( - "鏀惰棌", - style: TextStyle( - fontSize: 18, color: Color(0xFF888888)), - ), - Text( - "$collectedVideoCount", - style: const TextStyle( - fontSize: 12, color: Color(0xFF888888)), - ), - ], - )), - InkWell( - onTap: () { - UserUtil.isLogin().then((value) { - if (!value) { - jumpPage("EmailLoginPage"); - return; - } - jumpPage("VideoAttentionPage"); - }); - }, - child: Column( - children: [ - const Text( - "杩藉墽", - style: TextStyle( - fontSize: 18, color: Color(0xFF888888)), - ), - Text( - "$favoriteVideoCount", - style: const TextStyle( - fontSize: 12, color: Color(0xFF888888)), - ), - ], - ), - ), - InkWell( - onTap: () { - jumpPage("VideoDownloadPage"); - }, - child: Column( - children: const [ - Text( - "缂撳瓨", - style: TextStyle( - fontSize: 18, color: Color(0xFF888888)), - ), - Text( - "0", - style: TextStyle( - fontSize: 12, color: Color(0xFF888888)), - ), - ], - )), - ], - ), - //鍘嗗彶璁板綍 - Container( - height: 20, - ), - recordList.isNotEmpty - ? Column( - children: [ - //title - InkWell( - onTap: () { - jumpPage("VideoScanRecordPage"); - }, - child: Row( - children: [ - Container( - width: 16, - ), - const Text( - "鍘嗗彶璁板綍", - style: TextStyle( - color: Color(0xFFAAAAAA), - fontSize: 15), - ), - Expanded(child: Container()), - const Text( - "鍏ㄩ儴", - style: TextStyle( - color: Color(0xFFAAAAAA), - fontSize: 15), - ), - Container( - width: 6, - ), - Image.asset( - "assets/imgs/icon_mine_fun_input.png", - width: 6.5, - ), - Container( - width: 16, - ), - ], - )), - //鍐呭 - Container( - margin: const EdgeInsets.only(top: 15), - height: 270, - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Container( - constraints: BoxConstraints( - minWidth: MediaQuery.of(context) - .size - .width), - alignment: Alignment.centerLeft, - child: Wrap( - direction: Axis.vertical, - alignment: WrapAlignment.start, - spacing: 10, - runSpacing: 10, - children: getRecordListWidget()))), - ) - ], - ) - : Container(), - - //鍔熻兘 - Container( - margin: const EdgeInsets.fromLTRB(16, 23, 16, 16), - padding: const EdgeInsets.fromLTRB(24, 10, 24, 10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12.5), - border: Border.all( - color: const Color(0xFFDDDDDD), width: 1)), - child: Column( - children: [ - functionWidget( - "assets/imgs/icon_mine_fun_share.png", "鍒嗕韩APP", 16, - () { - Share.share("娴烽噺闊╁墽锛屽敖鍦ㄥ簲鐢細$applink"); - }), - functionWidget("assets/imgs/icon_mine_fun_privacy.png", - "闅愮鏀跨瓥", 13.5, () { - jumpPage("BrowserPage", params: {"url": Constant.PRIVACY_URL,"title":"闅愮鏀跨瓥"}); - }), - functionWidget("assets/imgs/icon_mine_fun_feedback.png", - "鍙嶉鍚愭Ы", 13.5, () { - jumpPage("AdvicePage"); - }), - functionWidget("assets/imgs/icon_mine_fun_about_us.png", - "鍏充簬鎴戜滑", 17, () { - MySharedPreferences.getInstance() - .getString("aboutUsLink") - .then((value) { - if (!StringUtil.isNullOrEmpty(value)) { - jumpPage("AboutUsPage"); - } - }); - }), - functionWidget("assets/imgs/icon_mine_fun_settings.png", - "璁剧疆", 17.5, () { - jumpPage("SettingPage"); - }), - ], - ), - ) - ], - )), - )) - ], - )); - } - - List<Widget> getRecordListWidget() { - List<Widget> list = recordList.map((e) { - //鏄惁涓轰富鍒嗙被 - List<int> mainTypes = [150, 151, 152, 153]; - if (mainTypes.contains(e.video!.videoType!.id!)) { - return InkWell( - child: getBigRecordItem(e), - onTap: () { - jumpVideoDetail(context, e.video, Platform.isIOS, - position: e.position!); - }, - ); - } else { - return InkWell( - child: getSmallRecordItem(e), - onTap: () { - jumpVideoDetail(context, e.video, Platform.isIOS, - position: e.position!); - }, - ); - } - }).toList(); - list.insert( - 0, - InkWell( - child: Container( - width: 5, - height: 270, - ))); - list.add(InkWell( - child: Container( - width: 5, - height: 270, - ))); - return list; - } - - Widget getSmallRecordItem(WatchRecordModel record) { - return Container( - height: 130, - child: Stack( - children: [ - Container( - margin: const EdgeInsets.only(top: 20), - height: 110, - width: 120 * 1.4, - decoration: BoxDecoration( - color: Colors.black38, - borderRadius: BorderRadius.circular(10)), - ), - Container( - alignment: Alignment.center, - width: 120 * 1.4, - padding: const EdgeInsets.only(left: 10, right: 10), + SingleChildScrollView( child: Column( - children: [ - ClipRRect( - borderRadius: BorderRadius.circular(10), - child: SizedBox( - height: 100, - width: 120 * 1.4 - 20, - child: VideoImage(record.video!.picture), - ), - ), - Container( - height: 5, - ), - Text( - record.video!.name!, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: const TextStyle(color: Colors.white), - ) - ], - )) - ], - )); - } - - Widget getBigRecordItem(WatchRecordModel record) { - return Stack( - children: [ - Container( - margin: const EdgeInsets.only(top: 20), - height: 250, - width: 150, - decoration: BoxDecoration( - color: Colors.black38, borderRadius: BorderRadius.circular(10)), - ), - Container( - alignment: Alignment.center, - width: 150, - padding: EdgeInsets.only(left: 10, right: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: [ - ClipRRect( - borderRadius: BorderRadius.circular(10), - child: Container( - height: 200, - child: VideoImage( - record.video!.vpicture ?? record.video!.picture), - ), + Container( + height: 100, ), Container( - height: 5, - ), - Text( - record.video!.name!, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: const TextStyle(color: Colors.white), - ) + child: Stack( + children: [ + Container( + alignment: Alignment.bottomRight, + color: Colors.white, + padding: EdgeInsets.only(bottom: 10), + margin: EdgeInsets.only(top: 28), + child: Column( + children: [ + const SizedBox( + height: 15, + ), + Container( + alignment: Alignment.topCenter, + color: Colors.white, + height: 100, + padding: + const EdgeInsets.fromLTRB(20, 25, 20, 20), + child: _user != null + ? personInfoWidget() + : + //鐧诲綍妗� + loginBtnWidget(), + ), + Container( + color: Colors.white, + padding: + const EdgeInsets.only(left: 12, right: 12), + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: + MainAxisAlignment.spaceAround, + children: [ + Expanded( + child: InkWell( + onTap: () { + jumpPage("GoldCornPage"); + }, + child: Container( + alignment: Alignment.centerLeft, + child: AspectRatio( + aspectRatio: 2.048, + child: Stack( + alignment: Alignment.centerLeft, + children: [ + ClipRRect( + borderRadius: + BorderRadius.circular( + 12), + child: Image.asset( + "assets/imgs/mine/ic_goldcorn_bg.png")), + Wrap(children: [ + const SizedBox( + width: 14, + ), + Text.rich(TextSpan( + text: "$goldCorn", + style: const TextStyle( + color: Colors.white, + fontSize: 30), + children: const [ + TextSpan( + text: "涓�", + style: TextStyle( + fontSize: 15)) + ])) + ]) + ], + ), + ), + ))), + const SizedBox( + width: 13.5, + ), + Expanded( + child: InkWell( + onTap: () { + jumpPage("BalancePage"); + }, + child: Container( + alignment: Alignment.centerLeft, + child: AspectRatio( + aspectRatio: 2.048, + child: Stack( + alignment: Alignment.centerLeft, + children: [ + ClipRRect( + borderRadius: + BorderRadius.circular( + 12), + child: Image.asset( + "assets/imgs/mine/ic_money_bg.png")), + Wrap( + children: [ + SizedBox( + width: 14, + ), + Text.rich(TextSpan( + text: balance, + style: TextStyle( + color: + Colors.white, + fontSize: 30), + children: [ + TextSpan( + text: "鍏�", + style: TextStyle( + fontSize: + 15)) + ])) + ], + ) + ], + ), + ), + ))), + ], + ), + ), + //鍔熻兘 + Container( + height: 200, + margin: const EdgeInsets.fromLTRB(10, 20, 13, 16), + padding: + const EdgeInsets.fromLTRB(10, 10, 10, 10), + decoration: BoxDecoration( + color: Color(0xFFFAFAFA), + borderRadius: BorderRadius.circular(13)), + child: GridView( + padding: EdgeInsets.zero, + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 4, mainAxisSpacing: 10), + physics: const NeverScrollableScrollPhysics(), + children: [ + functionWidget( + "assets/imgs/mine/ic_fun_invite.png", + "閭�璇峰ソ鍙�", + 28.5, () { + jumpPage("InviteFriendsPage"); + }), + functionWidget( + "assets/imgs/mine/ic_fun_help.png", + "甯姪涓績", + 27, () { + ConfigUtil.getConfig(context, "helpLink") + .then((value) { + jumpPage("BrowserPage", + params: { + "url": value, + "title": "甯姪涓績" + }, + needLogin: false); + }); + }), + functionWidget( + "assets/imgs/mine/ic_fun_kefu.png", + "鍦ㄧ嚎瀹㈡湇", + 28.5, () { + ConfigUtil.getConfig(context, "kefu") + .then((value) { + jumpPage("BrowserPage", + params: {"url": value, "title": "瀹㈡湇"}, + needLogin: false); + }); + }), + functionWidget( + "assets/imgs/mine/ic_fun_about_us.png", + "鍏充簬鎴戜滑", + 25, () { + // MySharedPreferences.getInstance() + // .getString("aboutUsLink") + // .then((value) { + // if (!StringUtil.isNullOrEmpty(value)) { + jumpPage("AboutUsPage", needLogin: false); + // } + // }); + }), + functionWidget( + "assets/imgs/mine/ic_fun_settings.png", + "璁剧疆", + 24.5, () { + jumpPage("SettingPage", needLogin: false); + }), + ], + ), + ), + + Container( + margin: + const EdgeInsets.only(left: 12, right: 12), + width: MediaQuery.of(context).size.width - 12 * 2, + height: + (MediaQuery.of(context).size.width - 12 * 2) * + 0.6, + alignment: Alignment.center, + child: CSJEXpressAd( + "948486374", + MediaQuery.of(context).size.width - 12 * 2, + (MediaQuery.of(context).size.width - 12 * 2) * + 0.6), + ) + ], + )), + Container( + margin: EdgeInsets.only(left: 25), + child: portraitWidget(), + ) + ], + )), ], - )) - ], - ); + )), + ])) + ])); } Widget portraitWidget() { - return Container( - width: 80, - height: 80, - padding: const EdgeInsets.all(2), - alignment: Alignment.center, - decoration: BoxDecoration( - color: const Color(0xFFAAAAAA), - borderRadius: BorderRadius.circular(40)), - child: ClipRRect( - borderRadius: BorderRadius.circular(40), - child: CommonImage( - _user == null - ? "assets/imgs/ic_portrait_default.png" - : _user!.portrait!, - defaultWidget: - Image.asset("assets/imgs/ic_portrait_default.png")), - )); + return InkWell( + onTap: () { + if (_user != null) { + jumpPage("PersonInfoPage"); + } + }, + child: Container( + width: 81, + height: 81, + padding: const EdgeInsets.all(4), + alignment: Alignment.center, + decoration: BoxDecoration( + color: Colors.white, borderRadius: BorderRadius.circular(40)), + child: ClipRRect( + borderRadius: BorderRadius.circular(40), + child: _user == null + ? Container( + color: COLOR_PORTRAIT_BG, + alignment: Alignment.center, + child: Image.asset( + "assets/imgs/mine/icon_no_login_portrait.png", + height: 39, + ), + ) + : CommonImage( + (_user == null || _user!.portrait == null) + ? "assets/imgs/ic_portrait_default.png" + : _user!.portrait!, + defaultWidget: + Image.asset("assets/imgs/ic_portrait_default.png")), + ))); } Widget loginBtnWidget() { - return MyFillButton( - "绔嬪嵆鐧诲綍", - 12.5, - width: 138, - fontSize: 14, - onClick: () { - jumpPage("EmailLoginPage"); - }, - ); + return MyFillButton("鐧诲綍", 13, width: 230, fontSize: 15, height: 41, + onClick: () { + jumpPage("LoginPage", needLogin: false); + }, color: COLOR_HIGHLIGHT); } Widget personInfoWidget() { + print("鐢ㄦ埛淇℃伅:${_user!.toJson()}"); return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(_user!.nickname!, maxLines: 1, + overflow: TextOverflow.ellipsis, style: const TextStyle( - fontSize: 18, - color: ColorConstant.theme, + fontSize: 21, + color: COLOR_TITLE, )), Container( height: 6, ), - Text("ID:${_user!.id!}", - style: const TextStyle( - fontSize: 15, - color: Color(0xFFA9A9A9), - )), ], ); } - Widget signWidget() { - return Container( - padding: const EdgeInsets.only(top: 21.5, left: 12.5, right: 12.5), - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - ColorConstant.theme.withAlpha(0), - ColorConstant.theme.withAlpha(108), + Widget userContent(int number, String content, VoidCallback click, + {color: COLOR_CONTENT}) { + return InkWell( + onTap: () { + click(); + }, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "$number", + style: TextStyle(color: color, fontSize: 18), + ), + Text( + content, + style: TextStyle(color: color, fontSize: 10), + ) ], - ), - ), - child: Container( - height: 64, - padding: const EdgeInsets.only(left: 23, right: 23), - alignment: Alignment.centerLeft, - decoration: const BoxDecoration( - color: ColorConstant.theme, - borderRadius: BorderRadius.only( - topLeft: Radius.circular(15), topRight: Radius.circular(15))), - child: Text( - "涓�х鍚嶏細${(_user == null || _user!.sign == null || _user!.sign!.isEmpty) ? "杩欎釜浜洪潪甯告湁瓒o紝浣嗘槸浠�涔堜篃娌″啓~" : _user!.sign}", - maxLines: 3, - overflow: TextOverflow.ellipsis, - style: const TextStyle(fontSize: 12, color: Colors.white), - ), - ), - ); + )); } Widget functionWidget( @@ -603,28 +443,22 @@ click(); }, child: Container( - padding: const EdgeInsets.only(top: 15, bottom: 15), - child: Row( + padding: const EdgeInsets.only(top: 15, bottom: 14), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ + Image.asset( + icon, + width: width, + ), Container( - width: 20, - alignment: Alignment.center, - child: Image.asset( - icon, - width: width, - )), - Container( - width: 10, + height: 10, ), Text( text, - style: const TextStyle(color: Color(0xFFAAAAAA), fontSize: 15), - ), - Expanded(child: Container()), - Image.asset( - "assets/imgs/icon_mine_fun_input.png", - width: 6.5, - ), + style: const TextStyle(color: COLOR_CONTENT, fontSize: 12), + ) ], )), ); -- Gitblit v1.8.0