admin
2022-04-29 67bdeebb4dc381a2f46f31e3027ebcc3243a8aeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
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/model/goldcorn/signin_info_model.dart';
import 'package:makemoney/ui/widget/button.dart';
import 'package:makemoney/ui/widget/refresh_listview.dart';
import 'package:makemoney/utils/ui_constant.dart';
import 'package:makemoney/utils/ui_utils.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<TaskPage>
    with SingleTickerProviderStateMixin {
  final MyRefreshController _refreshController =
      MyRefreshController(initialRefresh: false);
 
  SigninInfoModel? _signInfo;
 
  int selectedIndex = 0;
 
  FToast? fToast;
 
  @override
  void initState() {
    super.initState();
    setStatusBarDark();
    fToast = FToast();
    fToast!.init(context);
 
    //初始化
    _signInfo = SigninInfoModel(
        continueSignInDay: 0,
        isSignIned: false,
        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();
  }
 
  void _getSignInfo() async {
    Map<String, dynamic>? 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;
    });
  }
 
  void _signIn() async {
    Map<String, dynamic>? 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();
  }
 
  @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,
                  ),
                ),
 
                //通知消息
                Container(
                  height: 30,
                  color: Colors.red,
                ),
                //签到
                _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(10, 10, 10, 10),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.end,
                              children: [
                                const Text(
                                  "签到领金币",
                                  style: TextStyle(
                                      color: ColorConstant.theme, fontSize: 15),
                                ),
                                const SizedBox(
                                  width: 5,
                                ),
                                Text.rich(TextSpan(
                                    text: "已连续签到",
                                    style: const TextStyle(
                                        color: Color(0xFF666666), fontSize: 9),
                                    children: [
                                      TextSpan(
                                          text:
                                              "${_signInfo!.continueSignInDay}",
                                          style: const TextStyle(
                                              color: ColorConstant.theme,
                                              fontSize: 12)),
                                      const TextSpan(text: "天")
                                    ])),
                                Expanded(child: Container()),
                                const Text(
                                  "签到提醒",
                                  style: TextStyle(
                                      color: Color(0xFF666666), fontSize: 9),
                                ),
                                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,
                                )
                              ],
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: getSignDayItemList(),
                            ),
                            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();
                              },
                            )
                          ],
                        ),
                      ),
 
                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: 5,
                          ),
                          // Row(
                          //   children: [
                          //     Expanded(child: getNavItem("日常任务", 0)),
                          //     Expanded(child: getNavItem("激励任务", 1)),
                          //   ],
                          // ),
                          Expanded(
                              child: Container(
                            alignment: Alignment.topCenter,
                            margin: EdgeInsets.only(bottom: 10),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(13)),
                            child: RefreshListView(
                              enablePullDown: false,
                              refreshController: _refreshController,
                              loadTextColor: const Color(0xFFFF8316),
                              content: ListView.builder(
                                itemCount: 5,
                                itemBuilder: (BuildContext context, int index) {
                                  return getItemView(index, () {});
                                },
                              ),
                            ),
                          ))
                        ])))
              ],
            )
          ],
        ));
  }
 
  List<Widget> 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),
                ),
                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) {
    _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!
                      ? 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: 9, 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(int index, GestureTapCallback onTap) {
    return Padding(
        padding: const EdgeInsets.only(top: 20, left: 16, right: 16, bottom: 5),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          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: Container(
                margin: const EdgeInsets.all(2),
                decoration: BoxDecoration(
                  color: const Color(0xFFFFF8AE),
                  borderRadius: BorderRadius.circular(40),
                ),
              ),
            ),
            SizedBox(
              width: 10,
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "浏览推荐视频",
                  style: TextStyle(color: Color(0xFF454545), fontSize: 12),
                ),
                Text(
                  "今日进度(1/3)",
                  style: TextStyle(
                      color: Color(0xFF7F7F7F), fontSize: 9, height: 1.5),
                ),
                Text.rich(TextSpan(
                    style: TextStyle(color: Color(0xFFFF8316), fontSize: 9),
                    children: [
                      TextSpan(text: "+"),
                      TextSpan(text: "8888", style: TextStyle(fontSize: 10)),
                      TextSpan(text: "金币/人 (需手动领取)"),
                    ])),
              ],
            ),
            Expanded(child: Container()),
            MyOutlineButton(
              "去完成",
              20,
              width: 62,
              height: 25,
              fontSize: 12,
              textColor: ColorConstant.theme,
              color: ColorConstant.theme,
            )
          ],
        ));
  }
}