| | |
| | | import 'package:flutter/material.dart'; |
| | | import 'package:fluttertoast/fluttertoast.dart'; |
| | | import 'package:makemoney/api/gold_corn_api.dart'; |
| | | import 'package:makemoney/api/msg_api.dart'; |
| | | import 'package:makemoney/model/goldcorn/signin_info_model.dart'; |
| | | import 'package:makemoney/model/goldcorn/task_list_model.dart'; |
| | | import 'package:makemoney/model/msg/app_notify_msg_model.dart'; |
| | | import 'package:makemoney/ui/mine/login.dart'; |
| | | import 'package:makemoney/ui/widget/base_ui.dart'; |
| | | import 'package:makemoney/ui/widget/button.dart'; |
| | | import 'package:makemoney/ui/widget/images_widget.dart'; |
| | | import 'package:makemoney/ui/widget/refresh_listview.dart'; |
| | | import 'package:makemoney/utils/pageutils.dart'; |
| | | import 'package:makemoney/utils/ui_constant.dart'; |
| | | import 'package:makemoney/utils/ui_utils.dart'; |
| | | import 'package:makemoney/utils/user_util.dart'; |
| | | |
| | | import '../../ui/widget/nav.dart'; |
| | | |
| | |
| | | |
| | | int selectedIndex = 0; |
| | | |
| | | bool _notify = true; |
| | | |
| | | FToast? fToast; |
| | | |
| | | int _page = 1; |
| | | |
| | | List<TaskListModel> _taskList = []; |
| | | |
| | | @override |
| | | void initState() { |
| | |
| | | //初始化 |
| | | _signInfo = SigninInfoModel( |
| | | continueSignInDay: 0, |
| | | isSignIned: false, |
| | | isSignIned: true, |
| | | notify: true, |
| | | dayList: [ |
| | | DayList(day: "-", goldCorn: 0, state: 2, today: false), |
| | |
| | | ]); |
| | | |
| | | _getSignInfo(); |
| | | _getNotify(); |
| | | _getTaskList(1); |
| | | } |
| | | |
| | | /***签到开始****/ |
| | | void _getSignInfo() async { |
| | | Map<String, dynamic>? result = await GoldCornApiUtil.getSignInInfo(context); |
| | | if (result == null) { |
| | |
| | | SigninInfoModel temp = SigninInfoModel.fromJson(result["data"]); |
| | | setState(() { |
| | | _signInfo = temp; |
| | | _notify = _signInfo!.notify!; |
| | | }); |
| | | } |
| | | |
| | | void _signIn() async { |
| | | bool login = await UserUtil.isLogin(); |
| | | if (!login) { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, LoginPage(title: ""), (data) {}); |
| | | return; |
| | | } |
| | | |
| | | Map<String, dynamic>? result = await GoldCornApiUtil.signIn(context); |
| | | if (result == null) { |
| | | return; |
| | |
| | | var data = result["data"]; |
| | | showSignSuccessToast(data["goldCorn"], data["continueDay"]); |
| | | _getSignInfo(); |
| | | } |
| | | |
| | | void _setSignInNotify(bool notify) async { |
| | | Map<String, dynamic>? result = |
| | | await GoldCornApiUtil.setSignInNotify(context, notify); |
| | | if (result == null) { |
| | | return; |
| | | } |
| | | if (result["code"] != 0) { |
| | | ToastUtil.toast(result["msg"], context); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | /***签到结束****/ |
| | | |
| | | AppNotifyMsgModel? _notifyMsg; |
| | | |
| | | void _getNotify() async { |
| | | AppNotifyMsgModel? notifyMsgModel = |
| | | await MsgApiUtil.getNotifyMsg(context, "task"); |
| | | setState(() { |
| | | _notifyMsg = notifyMsgModel; |
| | | }); |
| | | } |
| | | |
| | | //下拉刷新 |
| | | void _refresh() { |
| | | if (_refreshController.dataNormal != null) { |
| | | _refreshController.dataNormal!(); |
| | | } |
| | | _refreshController.loadComplete(); |
| | | _getTaskList(1); |
| | | } |
| | | |
| | | //获取队员列表 |
| | | void _getTaskList(int page) async { |
| | | setState(() { |
| | | _page = page; |
| | | }); |
| | | |
| | | Map<String, dynamic>? result = await GoldCornApiUtil.getTaskList(context); |
| | | |
| | | _refreshController.refreshCompleted(); |
| | | _refreshController.loadComplete(); |
| | | |
| | | if (result == null && _page == 1&&_taskList.isEmpty) { |
| | | _refreshController.apiError!(); |
| | | } |
| | | |
| | | if (result == null || result["code"] != 0) { |
| | | //页码回滚 |
| | | if (_page > 1) { |
| | | setState(() { |
| | | _page = _page - 1; |
| | | }); |
| | | } |
| | | return; |
| | | } |
| | | //解析数据 |
| | | int count = result["data"]["count"]; |
| | | List<dynamic> list = result["data"]["list"]; |
| | | List<TaskListModel> tempList = []; |
| | | list.forEach((element) { |
| | | tempList.add(TaskListModel.fromJson(element)); |
| | | }); |
| | | |
| | | if (_page == 1) { |
| | | setState(() { |
| | | _taskList = tempList; |
| | | }); |
| | | } else { |
| | | setState(() { |
| | | _taskList.addAll(tempList); |
| | | }); |
| | | } |
| | | |
| | | //判断数据 |
| | | |
| | | if (_taskList.isEmpty) { |
| | | //空数据 |
| | | _refreshController.dataEmpty!(); |
| | | } else { |
| | | _refreshController.dataNormal!(); |
| | | if (count <= _taskList.length) { |
| | | //没有数据了 |
| | | _refreshController.loadNoData(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @override |
| | |
| | | ), |
| | | |
| | | //通知消息 |
| | | Container( |
| | | height: 30, |
| | | color: Colors.red, |
| | | ), |
| | | _notifyMsg == null |
| | | ? Container( |
| | | height: 30, |
| | | ) |
| | | : NotifyWidget(_notifyMsg!.content!, |
| | | textColor: Colors.white), |
| | | |
| | | //签到 |
| | | _signInfo == null |
| | | ? Container() |
| | |
| | | decoration: BoxDecoration( |
| | | color: Colors.white, |
| | | borderRadius: BorderRadius.circular(13)), |
| | | padding: const EdgeInsets.fromLTRB(10, 10, 10, 10), |
| | | padding: const EdgeInsets.fromLTRB(4, 20, 4, 10), |
| | | child: Column( |
| | | mainAxisSize: MainAxisSize.min, |
| | | children: [ |
| | | Row( |
| | | crossAxisAlignment: CrossAxisAlignment.end, |
| | | children: [ |
| | | SizedBox( |
| | | width: 6, |
| | | ), |
| | | const Text( |
| | | "签到领金币", |
| | | style: TextStyle( |
| | | color: ColorConstant.theme, fontSize: 15), |
| | | color: ColorConstant.theme, |
| | | fontSize: 15, |
| | | fontWeight: FontWeight.bold, |
| | | height: 1), |
| | | ), |
| | | const SizedBox( |
| | | width: 5, |
| | |
| | | "${_signInfo!.continueSignInDay}", |
| | | style: const TextStyle( |
| | | color: ColorConstant.theme, |
| | | fontSize: 12)), |
| | | fontSize: 12, |
| | | fontWeight: FontWeight.bold)), |
| | | const TextSpan(text: "天") |
| | | ])), |
| | | Expanded(child: Container()), |
| | |
| | | const SizedBox( |
| | | width: 5, |
| | | ), |
| | | Image.asset( |
| | | _signInfo!.notify! |
| | | ? "assets/imgs/task/icon_task_sign_notify_checked.png" |
| | | : "assets/imgs/task/icon_task_sign_notify.png", |
| | | height: 12, |
| | | ) |
| | | InkWell( |
| | | onTap: () { |
| | | UserUtil.isLogin().then((value) { |
| | | if (!value) { |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, |
| | | LoginPage(title: ""), |
| | | (data) {}); |
| | | return; |
| | | } |
| | | setState(() { |
| | | _notify = !_notify; |
| | | }); |
| | | _setSignInNotify(_notify); |
| | | }); |
| | | }, |
| | | child: Padding( |
| | | padding: const EdgeInsets.only(top: 10), |
| | | child: Image.asset( |
| | | _notify |
| | | ? "assets/imgs/task/icon_task_sign_notify_checked.png" |
| | | : "assets/imgs/task/icon_task_sign_notify.png", |
| | | width: 22, |
| | | ))), |
| | | const SizedBox( |
| | | width: 6, |
| | | ), |
| | | ], |
| | | ), |
| | | Row( |
| | |
| | | const SizedBox( |
| | | height: 20, |
| | | ), |
| | | MyFillButton( |
| | | "立即签到", |
| | | 10, |
| | | fontSize: 15, |
| | | height: 42, |
| | | color: _signInfo!.isSignIned! |
| | | ? ColorConstant.theme.withAlpha(128) |
| | | : ColorConstant.theme, |
| | | onClick: () { |
| | | if (_signInfo!.isSignIned!) { |
| | | return; |
| | | } |
| | | _signIn(); |
| | | }, |
| | | ) |
| | | Padding( |
| | | padding: |
| | | const EdgeInsets.only(left: 6, right: 6), |
| | | child: MyFillButton( |
| | | "立即签到", |
| | | 10, |
| | | fontSize: 15, |
| | | height: 42, |
| | | color: _signInfo!.isSignIned! |
| | | ? ColorConstant.theme.withAlpha(128) |
| | | : ColorConstant.theme, |
| | | onClick: () { |
| | | if (_signInfo!.isSignIned!) { |
| | | return; |
| | | } |
| | | |
| | | _signIn(); |
| | | }, |
| | | )) |
| | | ], |
| | | ), |
| | | ), |
| | |
| | | fontSize: 10, color: Color(0xFF666666)), |
| | | ), |
| | | const SizedBox( |
| | | height: 5, |
| | | height: 8, |
| | | ), |
| | | // Row( |
| | | // children: [ |
| | |
| | | Expanded( |
| | | child: Container( |
| | | alignment: Alignment.topCenter, |
| | | margin: EdgeInsets.only(bottom: 10), |
| | | margin: const EdgeInsets.only(bottom: 10), |
| | | decoration: BoxDecoration( |
| | | color: Colors.white, |
| | | borderRadius: BorderRadius.circular(13)), |
| | | child: RefreshListView( |
| | | enablePullDown: false, |
| | | refresh: () { |
| | | _refresh(); |
| | | }, |
| | | enablePullUp: false, |
| | | refreshController: _refreshController, |
| | | loadTextColor: const Color(0xFFFF8316), |
| | | content: ListView.builder( |
| | | itemCount: 5, |
| | | padding: const EdgeInsets.only(top: 12), |
| | | itemCount: _taskList.length, |
| | | itemBuilder: (BuildContext context, int index) { |
| | | return getItemView(index, () {}); |
| | | return getItemView(_taskList[index], () {}); |
| | | }, |
| | | ), |
| | | ), |
| | |
| | | height: 55 * _sizeUnit!, |
| | | // padding: EdgeInsets.only(left: 10,right: 10), |
| | | child: Stack(children: [ |
| | | day.today! |
| | | day.today! && !_signInfo!.isSignIned! |
| | | ? Image.asset( |
| | | "assets/imgs/task/ic_task_sign_day_item_hb_today.png") |
| | | : Padding( |
| | |
| | | )); |
| | | } |
| | | |
| | | Widget getItemView(int index, GestureTapCallback onTap) { |
| | | return Padding( |
| | | padding: const EdgeInsets.only(top: 20, left: 16, right: 16, bottom: 5), |
| | | Widget getItemView(TaskListModel task, GestureTapCallback onTap) { |
| | | return Container( |
| | | padding: |
| | | const EdgeInsets.only(top: 10, left: 16, right: 16, bottom: 10), |
| | | child: Row( |
| | | mainAxisAlignment: MainAxisAlignment.start, |
| | | crossAxisAlignment: CrossAxisAlignment.start, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Container( |
| | | width: 40, |
| | |
| | | ], |
| | | ), |
| | | ), |
| | | child: Container( |
| | | margin: const EdgeInsets.all(2), |
| | | decoration: BoxDecoration( |
| | | color: const Color(0xFFFFF8AE), |
| | | borderRadius: BorderRadius.circular(40), |
| | | ), |
| | | ), |
| | | child: CommonImage(task.icon!), |
| | | ), |
| | | SizedBox( |
| | | const SizedBox( |
| | | width: 10, |
| | | ), |
| | | Column( |
| | | crossAxisAlignment: CrossAxisAlignment.start, |
| | | children: [ |
| | | Text( |
| | | "浏览推荐视频", |
| | | style: TextStyle(color: Color(0xFF454545), fontSize: 12), |
| | | task.name!, |
| | | style: TextStyle( |
| | | color: Color(0xFF454545), fontSize: 12, height: 1.2), |
| | | ), |
| | | Text( |
| | | "今日进度(1/3)", |
| | | style: TextStyle( |
| | | task.process!, |
| | | style: const TextStyle( |
| | | color: Color(0xFF7F7F7F), fontSize: 9, height: 1.5), |
| | | ), |
| | | Text.rich(TextSpan( |
| | | style: TextStyle(color: Color(0xFFFF8316), fontSize: 9), |
| | | style: |
| | | TextStyle(color: const Color(0xFFFF8316), fontSize: 9), |
| | | children: [ |
| | | TextSpan(text: "+"), |
| | | TextSpan(text: "8888", style: TextStyle(fontSize: 10)), |
| | | TextSpan(text: "金币/人 (需手动领取)"), |
| | | const TextSpan(text: "+"), |
| | | TextSpan( |
| | | text: "${task.price}", |
| | | style: TextStyle(fontSize: 10)), |
| | | TextSpan(text: task.priceUnit), |
| | | ])), |
| | | ], |
| | | ), |
| | | Expanded(child: Container()), |
| | | MyOutlineButton( |
| | | "去完成", |
| | | task.actionName!, |
| | | 20, |
| | | width: 62, |
| | | height: 25, |
| | | fontSize: 12, |
| | | textColor: ColorConstant.theme, |
| | | color: ColorConstant.theme, |
| | | onClick: () { |
| | | if (false == task.active!) { |
| | | return; |
| | | } |
| | | jumpAppPage(task.jumpType!, null); |
| | | }, |
| | | ) |
| | | ], |
| | | )); |