mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 04:24:45 +08:00
feat:riverpod 迁移 HomeUI
This commit is contained in:
41
lib/widgets/src/cache_image.dart
Normal file
41
lib/widgets/src/cache_image.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
|
||||
class CacheNetImage extends StatelessWidget {
|
||||
final String url;
|
||||
final double? width;
|
||||
final double? height;
|
||||
final BoxFit? fit;
|
||||
|
||||
const CacheNetImage(
|
||||
{super.key, required this.url, this.width, this.height, this.fit});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ExtendedImage.network(
|
||||
url,
|
||||
width: width,
|
||||
height: height,
|
||||
fit: fit,
|
||||
loadStateChanged: (ExtendedImageState state) {
|
||||
switch (state.extendedImageLoadState) {
|
||||
case LoadState.loading:
|
||||
return const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
ProgressRing(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
case LoadState.failed:
|
||||
return const Text("Loading Image error");
|
||||
case LoadState.completed:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
91
lib/widgets/src/countdown_time_text.dart
Normal file
91
lib/widgets/src/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("");
|
||||
}
|
||||
}
|
@ -5,6 +5,25 @@ import 'package:window_manager/window_manager.dart';
|
||||
import 'package:markdown_widget/config/all.dart';
|
||||
import 'package:markdown_widget/widget/all.dart';
|
||||
import 'package:extended_image/extended_image.dart';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
export 'src/cache_image.dart';
|
||||
export 'src/countdown_time_text.dart';
|
||||
export '../common/utils/base_utils.dart';
|
||||
|
||||
Widget makeLoading(
|
||||
BuildContext context, {
|
||||
double? width,
|
||||
}) {
|
||||
width ??= 30;
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: width,
|
||||
child: const ProgressRing(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget makeDefaultPage(BuildContext context,
|
||||
{Widget? titleRow,
|
||||
@ -99,6 +118,10 @@ List<Widget> makeMarkdownView(String description, {String? attachmentsUrl}) {
|
||||
]));
|
||||
}
|
||||
|
||||
ColorFilter makeSvgColor(Color color) {
|
||||
return ui.ColorFilter.mode(color, ui.BlendMode.srcIn);
|
||||
}
|
||||
|
||||
CustomTransitionPage<T> myPageBuilder<T>(
|
||||
BuildContext context, GoRouterState state, Widget child) {
|
||||
return CustomTransitionPage(
|
||||
|
Reference in New Issue
Block a user