import 'dart:ui'; import 'package:flutter/cupertino.dart'; 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'; class TaskPage extends StatefulWidget { TaskPage({Key? key, required this.title}) : super(key: key); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked "final". final String title; @override _TaskPageState createState() => _TaskPageState(); } class _TaskPageState extends State with SingleTickerProviderStateMixin { final MyRefreshController _refreshController = MyRefreshController(initialRefresh: false); SigninInfoModel? _signInfo; int selectedIndex = 0; bool _notify = true; FToast? fToast; int _page = 1; List _taskList = []; @override void initState() { super.initState(); setStatusBarDark(); fToast = FToast(); fToast!.init(context); //初始化 setState(() { _signInfo = SigninInfoModel( continueSignInDay: 0, isSignIned: true, notify: true, dayList: [ DayList(day: "-", goldCorn: 0, state: 2, today: false), DayList(day: "-", goldCorn: 0, state: 2, today: false), DayList(day: "-", goldCorn: 0, state: 2, today: false), DayList(day: "-", goldCorn: 0, state: 2, today: false), DayList(day: "-", goldCorn: 0, state: 2, today: false), DayList(day: "-", goldCorn: 0, state: 2, today: false), DayList(day: "-", goldCorn: 0, state: 2, today: false), ]); }); _getSignInfo(); _getNotify(); _getTaskList(1); } /***签到开始****/ void _getSignInfo() async { Map? result = await GoldCornApiUtil.getSignInInfo(context); if (result == null) { return; } if (result["code"] != 0) { ToastUtil.toast(result["msg"], context); return; } 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? result = await GoldCornApiUtil.signIn(context); if (result == null) { return; } if (result["code"] != 0) { ToastUtil.toast(result["msg"], context); return; } var data = result["data"]; showSignSuccessToast(data["goldCorn"], data["continueDay"]); _getSignInfo(); } void _setSignInNotify(bool notify) async { Map? 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? 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 list = result["data"]["list"]; List 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 Widget build(BuildContext context) { return Scaffold( backgroundColor: const Color(0xFFF0F0F0), body: Stack( children: [ AspectRatio( aspectRatio: 1.8564, child: Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ Color(0xFFFD5B50), Color(0xFFFE0E4B), ], ), ), ), ), Column( children: [ TopNavBar( title: "赚钱", backGround: Colors.transparent, textColor: Colors.white, backIcon: Image.asset( "assets/imgs/common/icon_back_light.png", height: 19, ), ), //通知消息 _notifyMsg == null ? Container( height: 30, ) : NotifyWidget(_notifyMsg!.content!, textColor: Colors.white), //签到 _signInfo == null ? Container() : Container( margin: const EdgeInsets.fromLTRB(8, 8, 8, 8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(13)), 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: 18, fontWeight: FontWeight.bold, height: 1), ), const SizedBox( width: 5, ), Text.rich(TextSpan( text: "已连续签到", style: const TextStyle( color: Color(0xFF666666), fontSize: 12), children: [ TextSpan( text: "${_signInfo!.continueSignInDay}", style: const TextStyle( color: ColorConstant.theme, fontSize: 18, fontWeight: FontWeight.bold)), const TextSpan(text: "天") ])), Expanded(child: Container()), const Text( "签到提醒", style: TextStyle( color: Color(0xFF666666), fontSize: 12, height: 1), ), const SizedBox( width: 5, ), 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: 5, bottom: 2), 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( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: getSignDayItemList(), ), const SizedBox( height: 20, ), Padding( padding: const EdgeInsets.only(left: 6, right: 6), child: MyFillButton( "立即签到", 10, fontSize: 18, height: 45, color: _signInfo!.isSignIned! ? ColorConstant.theme.withAlpha(128) : ColorConstant.theme, onClick: () { if (_signInfo!.isSignIned!) { return; } _signIn(); }, )) ], ), ), Expanded( child: Container( padding: const EdgeInsets.only(left: 10, right: 10), child: Column(children: [ const SizedBox( height: 5, ), const Text( "所有队员完成任务你也能获得金币。", style: TextStyle( fontSize: 10, color: Color(0xFF666666)), ), const SizedBox( height: 8, ), // Row( // children: [ // Expanded(child: getNavItem("日常任务", 0)), // Expanded(child: getNavItem("激励任务", 1)), // ], // ), Expanded( child: Container( alignment: Alignment.topCenter, margin: const EdgeInsets.only(bottom: 10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(13)), child: RefreshListView( refresh: () { _refresh(); }, enablePullUp: false, refreshController: _refreshController, loadTextColor: const Color(0xFFFF8316), content: ListView.builder( padding: const EdgeInsets.only(top: 12), itemCount: _taskList.length, itemBuilder: (BuildContext context, int index) { return getItemView(_taskList[index], () {}); }, ), ), )) ]))) ], ) ], )); } List getSignDayItemList() { return _signInfo!.dayList!.map((e) => getSignDayItem(e)).toList(); } void showSignSuccessToast(int goldCorn, int continueDay) { Widget toast = SizedBox( height: 180, width: 180, child: Stack( children: [ Container( margin: EdgeInsets.only(top: 30), decoration: BoxDecoration( borderRadius: BorderRadius.circular(25.0), color: Color(0xFF000000).withAlpha(160), )), Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset( "assets/imgs/task/icon_sign_success.png", width: 83, ), const Text( "签到成功", style: TextStyle(color: Colors.white, fontSize: 18), ), const SizedBox( height: 5, ), Text.rich( TextSpan( children: [ const TextSpan(text: "连续签到"), TextSpan( text: "$continueDay", style: const TextStyle( fontSize: 20, color: Color(0xFFFFF5A9), fontWeight: FontWeight.bold)), const TextSpan(text: "天"), ], ), style: const TextStyle(color: Colors.white, fontSize: 14), overflow: TextOverflow.ellipsis, maxLines: 1, ), const SizedBox( height: 8, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( "assets/imgs/icon_goldcorn.png", width: 19, ), const SizedBox( width: 2, ), Text( "+$goldCorn", style: const TextStyle( color: Color(0xFFFF8316), fontSize: 15, fontWeight: FontWeight.bold), ), ], ) ], ), ], )); fToast!.showToast( child: toast, gravity: ToastGravity.CENTER, toastDuration: const Duration(seconds: 2), ); } double? _sizeUnit; Widget getSignDayItem(DayList day) { if (_sizeUnit == null || _sizeUnit == 0) { setState(() { _sizeUnit = (MediaQuery.of(context).size.width) / 375; }); } print("$_sizeUnit"); return Expanded( child: Column( children: [ Stack( alignment: Alignment.bottomCenter, children: [ Padding( padding: EdgeInsets.only( left: 5 * _sizeUnit!, right: 5 * _sizeUnit!), child: Image.asset( "assets/imgs/task/ic_task_sign_day_item_bg.png")), Container( margin: EdgeInsets.only(bottom: 10 * _sizeUnit!), alignment: Alignment.bottomCenter, height: 55 * _sizeUnit!, // padding: EdgeInsets.only(left: 10,right: 10), child: Stack(children: [ day.today! && !_signInfo!.isSignIned! ? Image.asset( "assets/imgs/task/ic_task_sign_day_item_hb_today.png") : Padding( padding: EdgeInsets.only( left: 13 * _sizeUnit!, right: 13 * _sizeUnit!), child: Image.asset(getHBPoster(day.state!))), Positioned( bottom: 17 * _sizeUnit!, left: 0, right: 0, child: day.goldCorn == 0 ? Container() : Text.rich( TextSpan( text: "+", style: const TextStyle( fontSize: 8, color: Color(0xFFFFF5A9)), children: [ TextSpan( text: "${day.goldCorn}", style: const TextStyle(fontSize: 10)) ]), textAlign: TextAlign.center)) ])), ], ), const SizedBox( height: 7, ), Text( day.day!, style: const TextStyle(fontSize: 11, color: Color(0xFF999999)), ) ], )); } String getHBPoster(int state) { switch (state) { case 0: return "assets/imgs/task/ic_task_sign_day_item_hb_away.png"; case 1: return "assets/imgs/task/ic_task_sign_day_item_hb_got.png"; case 2: return "assets/imgs/task/ic_task_sign_day_item_hb_not_get.png"; } return "assets/imgs/task/ic_task_sign_day_item_hb_not_get.png"; } Widget getNavItem(title, index) { return InkWell( onTap: () { setState(() { selectedIndex = index; }); }, child: Container( height: 50, alignment: Alignment.center, decoration: selectedIndex == index ? BoxDecoration( color: Colors.white, borderRadius: const BorderRadius.only( topLeft: Radius.circular(13), topRight: Radius.circular(13)), boxShadow: [ BoxShadow( color: const Color(0xFF989898), offset: Offset((index == 0 ? 2 : -2), 0)) ]) : null, child: Text( title, style: TextStyle( color: selectedIndex == index ? ColorConstant.theme : const Color(0xFF666666), fontSize: 15), ), )); } 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.center, children: [ Container( width: 40, height: 40, decoration: BoxDecoration( borderRadius: BorderRadius.circular(40), gradient: const LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Color(0xFFFFCD64), Color(0xFFFE8CA0), ], ), ), child: CommonImage(task.icon!), ), const SizedBox( width: 10, ), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( task.name!, style: const TextStyle( color: Color(0xFF454545), fontSize: 16, height: 1.2), ), const SizedBox( height: 5, ), Text.rich(TextSpan( style: const TextStyle(color: Color(0xFFFF8316), fontSize: 13), children: [ const TextSpan(text: "+"), TextSpan(text: "${task.price}"), TextSpan(text: task.priceUnit), const TextSpan( text: " 今日进度", style: TextStyle( color: Color(0xFF7F7F7F), fontSize: 10, height: 1.5)), TextSpan( text: task.process!, style: const TextStyle( color: Color(0xFF7F7F7F), fontSize: 12, height: 1.5)), ])), ], )), 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); }, ) ], )); } }