feat:riverpod 迁移

This commit is contained in:
2024-03-07 23:01:32 +08:00
parent c6b69c4e08
commit 8e37ebece5
66 changed files with 1126 additions and 10749 deletions

View File

@ -1,41 +0,0 @@
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;
}
},
);
}
}

View File

@ -1,91 +0,0 @@
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

@ -1,25 +0,0 @@
import 'package:fluent_ui/fluent_ui.dart';
class MyPageRoute extends FluentPageRoute {
late final WidgetBuilder _builder;
MyPageRoute({required super.builder}) : _builder = builder;
@override
Widget buildPage(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
assert(debugCheckHasFluentTheme(context));
final result = _builder(context);
return Semantics(
scopesRoute: true,
explicitChildNodes: true,
child: EntrancePageTransition(
animation: CurvedAnimation(
parent: animation,
curve: FluentTheme.of(context).animationCurve,
),
child: result,
),
);
}
}

View File

@ -1,61 +1,56 @@
import 'package:extended_image/extended_image.dart';
import 'dart:ui' as ui;
import 'package:fluent_ui/fluent_ui.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:window_manager/window_manager.dart';
import 'package:markdown_widget/config/all.dart';
import 'package:markdown_widget/widget/all.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:extended_image/extended_image.dart';
import '../base/ui.dart';
Widget makeLoading(
BuildContext context, {
double? width,
}) {
width ??= 30;
return Center(
child: SizedBox(
width: width,
height: width,
// child: Lottie.asset("images/lottie/loading.zip", width: width),
child: const ProgressRing(),
),
Widget makeDefaultPage(BuildContext context,
{Widget? titleRow,
List<Widget>? actions,
Widget? content,
bool automaticallyImplyLeading = true,
String title = ""}) {
return NavigationView(
appBar: NavigationAppBar(
automaticallyImplyLeading: automaticallyImplyLeading,
title: DragToMoveArea(
child: titleRow ??
Column(
children: [
Expanded(
child: Row(
children: [
Text(title),
],
),
)
],
),
),
actions: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [...?actions, const WindowButtons()],
)),
content: content,
);
}
Widget makeSafeAre(BuildContext context, {bool withKeyboard = true}) {
return SafeArea(
child: Column(
children: [
const SizedBox(height: 4),
if (withKeyboard)
SizedBox(
height: MediaQuery.of(context).viewInsets.bottom,
),
],
));
}
class WindowButtons extends StatelessWidget {
const WindowButtons({super.key});
makeSvgColor(Color color) {
return ui.ColorFilter.mode(color, ui.BlendMode.srcIn);
}
bool isPadUI(BuildContext context) {
final size = MediaQuery.of(context).size;
return size.width >= size.height;
}
fastPadding(
{required double? all,
required Widget child,
double left = 0.0,
double top = 0.0,
double right = 0.0,
double bottom = 0.0}) {
return Padding(
padding: all != null
? EdgeInsets.all(all)
: EdgeInsets.only(left: left, top: top, right: right, bottom: bottom),
child: child);
@override
Widget build(BuildContext context) {
final FluentThemeData theme = FluentTheme.of(context);
return SizedBox(
width: 138,
height: 50,
child: WindowCaption(
brightness: theme.brightness,
backgroundColor: Colors.transparent,
),
);
}
}
List<Widget> makeMarkdownView(String description, {String? attachmentsUrl}) {
@ -102,11 +97,3 @@ List<Widget> makeMarkdownView(String description, {String? attachmentsUrl}) {
})
]));
}
class NoScrollBehavior extends ScrollBehavior {
@override
Widget buildOverscrollIndicator(
BuildContext context, Widget child, ScrollableDetails details) {
return child;
}
}