import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:wanna_battle/styles/colors.dart'; import 'package:wanna_battle/styles/totast.dart'; import '../styles/colors.dart'; import '../model/CheckinConfig.dart'; import '../net/HttpManager.dart'; void showCheckinDialog(BuildContext context) { showGeneralDialog( context: context, pageBuilder: (BuildContext buildContext, Animation animation, Animation secondaryAnimation) { return Center( child: Material( color: Colors.transparent, child: _CheckinDialog(), ), ); }, barrierDismissible: true, barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, barrierColor: Colors.black87, transitionBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { final curvedValue = Curves.easeInOutBack.transform(animation.value) - 1.0; return Transform( transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0), child: Opacity( opacity: animation.value, child: child, ), ); }, transitionDuration: const Duration(milliseconds: 300), ); } class _CheckinDialog extends StatefulWidget { @override State createState() { return _CheckinDialogState(); } } class _CheckinDialogState extends State<_CheckinDialog> { Map record; bool todayChecked = false; Future getRecords() async { final res = await HttpManager.get('checkinRecord/weekRecord'); if (res.success) { Map map = {}; res.data.forEach((k, v) { map[int.parse(k)] = CheckinConfig.fromJson(v); }); bool todayChecked = false; if (map[DateTime.now().weekday] != null && map[DateTime.now().weekday].checked == 1) { todayChecked = true; } setState(() { record = map; this.todayChecked = todayChecked; }); } } Future checkin() async { Toast.show(context, '加载中', -1, 'loading'); final res = await HttpManager.get('checkinRecord/checkin'); print(res.data.toString()); Toast.hide(); if (res.success) { Toast.show(context, '签到成功', 1500, 'info'); } else { Toast.show(context, res.error, 1500, 'info'); } Navigator.of(context).pop(); } @override void initState() { super.initState(); Future.delayed(Duration.zero, () async { getRecords(); }); } @override Widget build(BuildContext context) { return Container( width: 330, height: 390, decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))), child: record == null ? null : Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( '每日签到', style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold), ), Container( margin: EdgeInsets.only(top: 30), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ item(record[1]), item(record[2]), item(record[3]), item(record[4]), ], ), ), Container( margin: EdgeInsets.only(top: 25), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ item(record[5]), item(record[6]), ], ), ), todayChecked ? Container( margin: EdgeInsets.only(top: 40), child: MaterialButton( minWidth: 220, elevation: 0, highlightElevation: 0, color: Color(0xFF4F5C87), child: Text( '今日已签到', style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold), ), onPressed: () { Navigator.of(context).pop(); }, ), ) : Container( margin: EdgeInsets.only(top: 40), child: MaterialButton( minWidth: 220, elevation: 0, highlightElevation: 0, color: PRIMARY_COLOR, child: Text( '立即签到', style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold), ), onPressed: () { checkin(); }, ), ) ], ), ); } Widget item(CheckinConfig config) { String weekDay = config.weekDay; String icon; String name; if (config.moneyCoin != null) { icon = 'images/icon_jinbi_qiandao.png'; name = config.moneyCoin.toString() + '金币'; } else if (config.pointsRatio != null) { icon = 'images/qiandao_icon_jiacheng.png'; name = '加成卡'; } else if (config.minPoints != null) { icon = 'images/icon_baodi_03.png'; name = '保底卡'; } else if (config.probability != null) { icon = 'images/qiandao_icon_gailv.png'; name = '概率卡'; } int checked = config.checked; List list = [ Container( decoration: BoxDecoration( color: Color(0xFF253051), border: Border.all(width: 1, color: PRIMARY_COLOR), borderRadius: BorderRadius.circular(22), ), ), Center( child: Image.asset( icon, width: 33, ), ), ]; if (checked == 1) { list.add(Center( child: Image.asset( 'images/icon_yiqiandao.png', ), )); } else if (checked == 2) { list.add(Center( child: Container( decoration: BoxDecoration( color: Color(0xFF4f5c87), border: Border.all(width: 1, color: Color(0xFF4f5c87)), borderRadius: BorderRadius.circular(22), ), child: Center( child: Text( '未签到', style: TextStyle(color: Colors.white, fontSize: 10), ), ), ), )); } return Container( width: 76, child: Column( children: [ Container( width: 44, height: 44, child: Stack( children: list, ), ), Container( margin: EdgeInsets.only(top: 6), child: Text( weekDay, style: TextStyle(color: Colors.white, fontSize: 14), ), ), Container( margin: EdgeInsets.only(top: 2), child: Text( name, style: TextStyle( color: PRIMARY_COLOR, fontSize: 12, ), ), ) ], ), ); } }