|
| 1 | +// Copyright 2023 BenderBlog Rodriguez and contributors. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +import 'dart:math'; |
| 5 | + |
| 6 | +import 'package:flutter_i18n/flutter_i18n.dart'; |
| 7 | +import 'package:fluttertoast/fluttertoast.dart'; |
| 8 | +import 'package:sn_progress_dialog/progress_dialog.dart'; |
| 9 | +import 'package:watermeter/page/networkcard/network_card_window.dart'; |
| 10 | +import 'package:watermeter/page/public_widget/captcha_input_dialog.dart'; |
| 11 | +import 'package:watermeter/page/public_widget/toast.dart'; |
| 12 | +import 'package:get/get.dart'; |
| 13 | +import 'package:flutter/material.dart'; |
| 14 | +import 'package:watermeter/page/homepage/main_page_card.dart'; |
| 15 | +import 'package:watermeter/page/public_widget/context_extension.dart'; |
| 16 | +import 'package:watermeter/page/schoolcard/school_card_window.dart'; |
| 17 | +import 'package:watermeter/page/setting/dialogs/schoolnet_password_dialog.dart'; |
| 18 | +import 'package:watermeter/repository/network_session.dart'; |
| 19 | +import 'package:watermeter/repository/schoolnet_session.dart'; |
| 20 | +import 'package:watermeter/repository/xidian_ids/ids_session.dart'; |
| 21 | +import 'package:watermeter/repository/preference.dart' as preference; |
| 22 | +import 'package:watermeter/repository/network_session.dart' as network_session; |
| 23 | + |
| 24 | +import 'package:ming_cute_icons/ming_cute_icons.dart'; |
| 25 | + |
| 26 | +class NetworkCard extends StatelessWidget { |
| 27 | + const NetworkCard({super.key}); |
| 28 | + |
| 29 | + @override |
| 30 | + Widget build(BuildContext context) { |
| 31 | + return GestureDetector( |
| 32 | + onTap: () async { |
| 33 | + if (preference |
| 34 | + .getString( |
| 35 | + preference.Preference.schoolNetQueryPassword, |
| 36 | + ) |
| 37 | + .isEmpty) { |
| 38 | + await showDialog( |
| 39 | + context: context, |
| 40 | + builder: (context) => const SchoolNetPasswordDialog(), |
| 41 | + ); |
| 42 | + } |
| 43 | + if (context.mounted) { |
| 44 | + context.pushReplacement(const NetworkCardWindow()); |
| 45 | + } |
| 46 | + }, |
| 47 | + child: Obx( |
| 48 | + () => MainPageCard( |
| 49 | + isLoad: true, |
| 50 | + // network_session.isInit.value == SessionState.fetching, |
| 51 | + icon: MingCuteIcons.mgc_wifi_fill, |
| 52 | + text: preference |
| 53 | + .getString( |
| 54 | + preference.Preference.schoolNetQueryPassword, |
| 55 | + ) |
| 56 | + .isEmpty |
| 57 | + ? FlutterI18n.translate( |
| 58 | + context, |
| 59 | + "homepage.school_card_info_card.bill", |
| 60 | + ) |
| 61 | + : "无校园网密码,点击设置", |
| 62 | + infoText: Text.rich( |
| 63 | + TextSpan( |
| 64 | + style: const TextStyle(fontSize: 20), |
| 65 | + children: [ |
| 66 | + if (network_session.isInit.value == SessionState.fetched) ...[ |
| 67 | + const TextSpan(text: "校园网余量"), |
| 68 | + TextSpan( |
| 69 | + text: "", |
| 70 | + style: const TextStyle( |
| 71 | + fontSize: 24, |
| 72 | + fontWeight: FontWeight.bold, |
| 73 | + ), |
| 74 | + ), |
| 75 | + ] else |
| 76 | + TextSpan( |
| 77 | + text: network_session.isInit.value == SessionState.error |
| 78 | + ? "获取校园网流量信息失败" |
| 79 | + : "正在获取校园网流量信息", |
| 80 | + ), |
| 81 | + ], |
| 82 | + ), |
| 83 | + ), |
| 84 | + bottomText: Text( |
| 85 | + network_session.isInit.value == SessionState.fetched |
| 86 | + ? FlutterI18n.translate( |
| 87 | + context, |
| 88 | + "homepage.school_card_info_card.bottom_text_success", |
| 89 | + ) |
| 90 | + : network_session.isInit.value == SessionState.error |
| 91 | + ? FlutterI18n.translate( |
| 92 | + context, |
| 93 | + "homepage.school_card_info_card.no_info", |
| 94 | + ) |
| 95 | + : FlutterI18n.translate( |
| 96 | + context, |
| 97 | + "homepage.school_card_info_card.fetching_info", |
| 98 | + ), |
| 99 | + overflow: TextOverflow.ellipsis, |
| 100 | + ), |
| 101 | + ), |
| 102 | + ), |
| 103 | + ); |
| 104 | + } |
| 105 | +} |
0 commit comments