mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 00:33:42 +08:00
新增倒计时
This commit is contained in:
parent
d77f556890
commit
0388b5fb1d
BIN
assets/countdown/bis.png
Normal file
BIN
assets/countdown/bis.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
BIN
assets/countdown/ff.png
Normal file
BIN
assets/countdown/ff.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
assets/countdown/iae.png
Normal file
BIN
assets/countdown/iae.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
BIN
assets/countdown/ilw.png
Normal file
BIN
assets/countdown/ilw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
|
||||
import 'package:starcitizen_doctor/common/conf.dart';
|
||||
import 'package:starcitizen_doctor/data/app_placard_data.dart';
|
||||
import 'package:starcitizen_doctor/data/app_version_data.dart';
|
||||
import 'package:starcitizen_doctor/data/countdown_festival_item_data.dart';
|
||||
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
|
||||
|
||||
class Api {
|
||||
@ -20,6 +21,19 @@ class Api {
|
||||
await getRepoJson("sc_doctor", "placard.json"));
|
||||
}
|
||||
|
||||
static Future<List<CountdownFestivalItemData>>
|
||||
getFestivalCountdownList() async {
|
||||
List<CountdownFestivalItemData> l = [];
|
||||
final r = json.decode(await getRepoData("sc_doctor", "countdown.json"));
|
||||
if (r is List) {
|
||||
for (var element in r) {
|
||||
l.add(CountdownFestivalItemData.fromJson(element));
|
||||
}
|
||||
}
|
||||
l.sort((a, b) => (a.time ?? 0) - (b.time ?? 0));
|
||||
return l;
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(
|
||||
String version) async {
|
||||
final r = await dio
|
||||
|
24
lib/data/countdown_festival_item_data.dart
Normal file
24
lib/data/countdown_festival_item_data.dart
Normal file
@ -0,0 +1,24 @@
|
||||
class CountdownFestivalItemData {
|
||||
CountdownFestivalItemData({
|
||||
this.name,
|
||||
this.time,
|
||||
this.icon,});
|
||||
|
||||
CountdownFestivalItemData.fromJson(dynamic json) {
|
||||
name = json['name'];
|
||||
time = json['time'];
|
||||
icon = json['icon'];
|
||||
}
|
||||
String? name;
|
||||
int? time;
|
||||
String? icon;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['name'] = name;
|
||||
map['time'] = time;
|
||||
map['icon'] = icon;
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import 'package:card_swiper/card_swiper.dart';
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
@ -5,6 +6,7 @@ import 'package:flutter_tilt/flutter_tilt.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
import 'package:starcitizen_doctor/widgets/countdown_time_text.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
import 'home_ui_model.dart';
|
||||
@ -90,11 +92,14 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
top: 0,
|
||||
right: 24,
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: FluentTheme.of(context).cardColor.withOpacity(.03),
|
||||
color:
|
||||
FluentTheme.of(context).cardColor.withOpacity(.03),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
@ -145,7 +150,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
),
|
||||
name: "DPS计算器汉化",
|
||||
webTitle: "DPS计算器汉化",
|
||||
webURL: "https://www.erkul.games/live/calculator",
|
||||
webURL:
|
||||
"https://www.erkul.games/live/calculator",
|
||||
info: "在线改船,查询伤害数值和配件购买地点",
|
||||
useLocalization: true,
|
||||
width: width,
|
||||
@ -165,8 +171,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Button(
|
||||
child:
|
||||
const FaIcon(FontAwesomeIcons.edge, size: 18),
|
||||
child: const FaIcon(FontAwesomeIcons.edge,
|
||||
size: 18),
|
||||
onPressed: () {
|
||||
launchUrlString(
|
||||
"https://microsoftedge.microsoft.com/addons/detail/lipbbcckldklpdcpfagicipecaacikgi");
|
||||
@ -198,6 +204,73 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
width: width + 24,
|
||||
decoration: BoxDecoration(
|
||||
color: FluentTheme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12, right: 12, top: 6, bottom: 6),
|
||||
child: (model.countdownFestivalListData == null)
|
||||
? SizedBox(
|
||||
width: width,
|
||||
height: 62,
|
||||
child: const Center(
|
||||
child: ProgressRing(),
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
width: width,
|
||||
height: 62,
|
||||
child: Swiper(
|
||||
itemCount:
|
||||
model.countdownFestivalListData!.length,
|
||||
autoplay: true,
|
||||
autoplayDelay: 5000,
|
||||
itemBuilder: (context, index) {
|
||||
final item = model
|
||||
.countdownFestivalListData![index];
|
||||
return Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
if (item.icon != null &&
|
||||
item.icon != "") ...[
|
||||
ClipRRect(
|
||||
borderRadius:
|
||||
BorderRadius.circular(1000),
|
||||
child: Image.asset(
|
||||
"assets/countdown/${item.icon}",
|
||||
width: 48,
|
||||
height: 48,
|
||||
),
|
||||
),
|
||||
],
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
item.name ?? "",
|
||||
style: const TextStyle(
|
||||
fontSize: 15),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
CountdownTimeText(
|
||||
targetTime: DateTime
|
||||
.fromMillisecondsSinceEpoch(
|
||||
item.time ?? 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
if (model.appWebLocalizationVersionsData == null)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
@ -234,6 +307,12 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
Tilt(
|
||||
shadowConfig: const ShadowConfig(maxIntensity: .2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
model.goWebView("RSI 服务器状态",
|
||||
"https://status.robertsspaceindustries.com/",
|
||||
useLocalization: true);
|
||||
},
|
||||
child: Container(
|
||||
width: width,
|
||||
decoration: BoxDecoration(
|
||||
@ -252,7 +331,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
makeLoading(context, width: 20)
|
||||
else
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
for (final item in model.scServerStatus ?? [])
|
||||
Row(
|
||||
@ -262,8 +342,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
child: Center(
|
||||
child: Icon(
|
||||
FontAwesomeIcons.solidCircle,
|
||||
color:
|
||||
model.isRSIServerStatusOK(item)
|
||||
color: model
|
||||
.isRSIServerStatusOK(item)
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
size: 12,
|
||||
@ -290,6 +370,7 @@ class HomeUI extends BaseUI<HomeUIModel> {
|
||||
// ),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
))
|
||||
],
|
||||
|
@ -13,6 +13,7 @@ import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/data/app_placard_data.dart';
|
||||
import 'package:starcitizen_doctor/data/app_web_localization_versions_data.dart';
|
||||
import 'package:starcitizen_doctor/data/countdown_festival_item_data.dart';
|
||||
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui.dart';
|
||||
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui_model.dart';
|
||||
import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
|
||||
@ -54,6 +55,8 @@ class HomeUIModel extends BaseUIModel {
|
||||
|
||||
AppWebLocalizationVersionsData? appWebLocalizationVersionsData;
|
||||
|
||||
List<CountdownFestivalItemData>? countdownFestivalListData;
|
||||
|
||||
final cnExp = RegExp(r"[^\x00-\xff]");
|
||||
|
||||
AppPlacardData? appPlacardData;
|
||||
@ -89,6 +92,8 @@ class HomeUIModel extends BaseUIModel {
|
||||
"${AppConf.webTranslateHomeUrl}/versions.json",
|
||||
options: Options(responseType: ResponseType.plain)))
|
||||
.data));
|
||||
countdownFestivalListData = await Api.getFestivalCountdownList();
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
dPrint(e);
|
||||
}
|
||||
|
91
lib/widgets/countdown_time_text.dart
Normal file
91
lib/widgets/countdown_time_text.dart
Normal file
@ -0,0 +1,91 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
|
||||
class CountdownTimeText extends StatefulWidget {
|
||||
final DateTime targetTime;
|
||||
|
||||
const CountdownTimeText({super.key, required this.targetTime});
|
||||
|
||||
@override
|
||||
State<CountdownTimeText> createState() => _CountdownTimeTextState();
|
||||
}
|
||||
|
||||
class _CountdownTimeTextState extends State<CountdownTimeText> {
|
||||
Timer? _timer;
|
||||
|
||||
Widget? textWidget;
|
||||
|
||||
bool stopTimer = false;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
_onUpdateTime(null);
|
||||
if (!stopTimer) {
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), _onUpdateTime);
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
_onUpdateTime(_) {
|
||||
final now = DateTime.now();
|
||||
final dur = widget.targetTime.difference(now);
|
||||
setState(() {
|
||||
textWidget = _chineseTimeText(dur);
|
||||
});
|
||||
// 时间到,停止计时,并向宿主传递超时信息
|
||||
if (dur.inMilliseconds <= 0) {
|
||||
stopTimer = true;
|
||||
setState(() {});
|
||||
}
|
||||
if (stopTimer) {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _chineseTimeText(Duration duration) {
|
||||
final surplus = duration;
|
||||
int day = (surplus.inSeconds ~/ 3600) ~/ 24;
|
||||
int hour = (surplus.inSeconds ~/ 3600) % 24;
|
||||
int minute = surplus.inSeconds % 3600 ~/ 60;
|
||||
int second = surplus.inSeconds % 60;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"$day天 ",
|
||||
style: TextStyle(
|
||||
fontSize: 24, color: day < 30 ? Colors.red : Colors.white),
|
||||
),
|
||||
Text("${timePart(hour)}:${timePart(minute)}:${timePart(second)}"),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String timePart(int p) {
|
||||
if (p.toString().length == 1) return "0$p";
|
||||
return "$p";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (stopTimer) {
|
||||
return const Text(
|
||||
"正在进行中",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Color.fromRGBO(32, 220, 89, 1.0),
|
||||
fontWeight: FontWeight.bold),
|
||||
);
|
||||
}
|
||||
return textWidget ?? const Text("");
|
||||
}
|
||||
}
|
@ -52,6 +52,7 @@ dependencies:
|
||||
jwt_decode: ^0.3.1
|
||||
uuid: ^4.1.0
|
||||
flutter_tilt: ^2.0.10
|
||||
card_swiper: ^3.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
@ -77,6 +78,7 @@ flutter:
|
||||
uses-material-design: true
|
||||
assets:
|
||||
- assets/
|
||||
- assets/countdown/
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
|
Loading…
Reference in New Issue
Block a user