新增倒计时

This commit is contained in:
xkeyC 2023-11-03 00:18:45 +08:00
parent d77f556890
commit 0388b5fb1d
10 changed files with 365 additions and 148 deletions

BIN
assets/countdown/bis.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
assets/countdown/ff.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
assets/countdown/iae.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
assets/countdown/ilw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
import 'package:starcitizen_doctor/common/conf.dart'; import 'package:starcitizen_doctor/common/conf.dart';
import 'package:starcitizen_doctor/data/app_placard_data.dart'; import 'package:starcitizen_doctor/data/app_placard_data.dart';
import 'package:starcitizen_doctor/data/app_version_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'; import 'package:starcitizen_doctor/data/sc_localization_data.dart';
class Api { class Api {
@ -20,6 +21,19 @@ class Api {
await getRepoJson("sc_doctor", "placard.json")); 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( static Future<Map<String, dynamic>> getAppReleaseDataByVersionName(
String version) async { String version) async {
final r = await dio final r = await dio

View 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;
}
}

View File

@ -1,3 +1,4 @@
import 'package:card_swiper/card_swiper.dart';
import 'package:extended_image/extended_image.dart'; import 'package:extended_image/extended_image.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:flutter_svg/flutter_svg.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:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:starcitizen_doctor/api/analytics.dart'; import 'package:starcitizen_doctor/api/analytics.dart';
import 'package:starcitizen_doctor/base/ui.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 'package:url_launcher/url_launcher_string.dart';
import 'home_ui_model.dart'; import 'home_ui_model.dart';
@ -90,11 +92,14 @@ class HomeUI extends BaseUI<HomeUIModel> {
top: 0, top: 0,
right: 24, right: 24,
child: Stack( child: Stack(
children: [
Column(
children: [ children: [
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
color: FluentTheme.of(context).cardColor.withOpacity(.03), color:
FluentTheme.of(context).cardColor.withOpacity(.03),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
@ -145,7 +150,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
), ),
name: "DPS计算器汉化", name: "DPS计算器汉化",
webTitle: "DPS计算器汉化", webTitle: "DPS计算器汉化",
webURL: "https://www.erkul.games/live/calculator", webURL:
"https://www.erkul.games/live/calculator",
info: "在线改船,查询伤害数值和配件购买地点", info: "在线改船,查询伤害数值和配件购买地点",
useLocalization: true, useLocalization: true,
width: width, width: width,
@ -165,8 +171,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
), ),
const SizedBox(width: 12), const SizedBox(width: 12),
Button( Button(
child: child: const FaIcon(FontAwesomeIcons.edge,
const FaIcon(FontAwesomeIcons.edge, size: 18), size: 18),
onPressed: () { onPressed: () {
launchUrlString( launchUrlString(
"https://microsoftedge.microsoft.com/addons/detail/lipbbcckldklpdcpfagicipecaacikgi"); "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) if (model.appWebLocalizationVersionsData == null)
Positioned.fill( Positioned.fill(
child: Container( child: Container(
@ -234,6 +307,12 @@ class HomeUI extends BaseUI<HomeUIModel> {
Tilt( Tilt(
shadowConfig: const ShadowConfig(maxIntensity: .2), shadowConfig: const ShadowConfig(maxIntensity: .2),
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
child: GestureDetector(
onTap: () {
model.goWebView("RSI 服务器状态",
"https://status.robertsspaceindustries.com/",
useLocalization: true);
},
child: Container( child: Container(
width: width, width: width,
decoration: BoxDecoration( decoration: BoxDecoration(
@ -252,7 +331,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
makeLoading(context, width: 20) makeLoading(context, width: 20)
else else
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [ children: [
for (final item in model.scServerStatus ?? []) for (final item in model.scServerStatus ?? [])
Row( Row(
@ -262,8 +342,8 @@ class HomeUI extends BaseUI<HomeUIModel> {
child: Center( child: Center(
child: Icon( child: Icon(
FontAwesomeIcons.solidCircle, FontAwesomeIcons.solidCircle,
color: color: model
model.isRSIServerStatusOK(item) .isRSIServerStatusOK(item)
? Colors.green ? Colors.green
: Colors.red, : Colors.red,
size: 12, size: 12,
@ -290,6 +370,7 @@ class HomeUI extends BaseUI<HomeUIModel> {
// ), // ),
), ),
), ),
),
], ],
)) ))
], ],

View File

@ -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/common/helper/system_helper.dart';
import 'package:starcitizen_doctor/data/app_placard_data.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/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.dart';
import 'package:starcitizen_doctor/ui/home/dialogs/md_content_dialog_ui_model.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'; import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart';
@ -54,6 +55,8 @@ class HomeUIModel extends BaseUIModel {
AppWebLocalizationVersionsData? appWebLocalizationVersionsData; AppWebLocalizationVersionsData? appWebLocalizationVersionsData;
List<CountdownFestivalItemData>? countdownFestivalListData;
final cnExp = RegExp(r"[^\x00-\xff]"); final cnExp = RegExp(r"[^\x00-\xff]");
AppPlacardData? appPlacardData; AppPlacardData? appPlacardData;
@ -89,6 +92,8 @@ class HomeUIModel extends BaseUIModel {
"${AppConf.webTranslateHomeUrl}/versions.json", "${AppConf.webTranslateHomeUrl}/versions.json",
options: Options(responseType: ResponseType.plain))) options: Options(responseType: ResponseType.plain)))
.data)); .data));
countdownFestivalListData = await Api.getFestivalCountdownList();
notifyListeners();
} catch (e) { } catch (e) {
dPrint(e); dPrint(e);
} }

View 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("");
}
}

View File

@ -52,6 +52,7 @@ dependencies:
jwt_decode: ^0.3.1 jwt_decode: ^0.3.1
uuid: ^4.1.0 uuid: ^4.1.0
flutter_tilt: ^2.0.10 flutter_tilt: ^2.0.10
card_swiper: ^3.0.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -77,6 +78,7 @@ flutter:
uses-material-design: true uses-material-design: true
assets: assets:
- assets/ - assets/
- assets/countdown/
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets: