| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- 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<double> animation, Animation<double> secondaryAnimation) {
- return Center(
- child: Material(
- color: Colors.transparent,
- child: _CheckinDialog(),
- ),
- );
- },
- barrierDismissible: true,
- barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
- barrierColor: Colors.black87,
- transitionBuilder: (BuildContext context, Animation<double> animation, Animation<double> 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<StatefulWidget> createState() {
- return _CheckinDialogState();
- }
- }
- class _CheckinDialogState extends State<_CheckinDialog> {
- Map<int, CheckinConfig> record;
- bool todayChecked = false;
- Future<void> getRecords() async {
- final res = await HttpManager.get('checkinRecord/weekRecord');
- if (res.success) {
- Map<int, CheckinConfig> 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<void> 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: <Widget>[
- Text(
- '每日签到',
- style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
- ),
- Container(
- margin: EdgeInsets.only(top: 30),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- item(record[1]),
- item(record[2]),
- item(record[3]),
- item(record[4]),
- ],
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 25),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- 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<Widget> 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: <Widget>[
- 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,
- ),
- ),
- )
- ],
- ),
- );
- }
- }
|