mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-23 01:53:41 +08:00
feat:riverpod 迁移 HomeMdContentDialogUI
This commit is contained in:
parent
c9bd9ed677
commit
7b195271af
55
lib/ui/home/dialogs/home_md_content_dialog_ui.dart
Normal file
55
lib/ui/home/dialogs/home_md_content_dialog_ui.dart
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:flutter/material.dart' show Material;
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
||||||
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
||||||
|
|
||||||
|
class HomeMdContentDialogUI extends HookConsumerWidget {
|
||||||
|
final String title;
|
||||||
|
final String url;
|
||||||
|
|
||||||
|
const HomeMdContentDialogUI(
|
||||||
|
{super.key, required this.title, required this.url});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
return Material(
|
||||||
|
child: ContentDialog(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: MediaQuery.of(context).size.width * .6,
|
||||||
|
),
|
||||||
|
title: Text(title),
|
||||||
|
content: LoadingWidget(
|
||||||
|
onLoadData: _getContent,
|
||||||
|
childBuilder: (BuildContext context, String data) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 12, right: 12),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: makeMarkdownView(data),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
FilledButton(
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
||||||
|
child: Text("关闭"),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
})
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> _getContent() async {
|
||||||
|
final r = await RSHttp.getText(url);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,8 @@ import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
|||||||
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
import 'home_countdown_dialog_ui.dart';
|
import 'dialogs/home_countdown_dialog_ui.dart';
|
||||||
|
import 'dialogs/home_md_content_dialog_ui.dart';
|
||||||
import 'home_ui_model.dart';
|
import 'home_ui_model.dart';
|
||||||
|
|
||||||
class HomeUI extends HookConsumerWidget {
|
class HomeUI extends HookConsumerWidget {
|
||||||
@ -729,14 +730,14 @@ class HomeUI extends HookConsumerWidget {
|
|||||||
launchUrlString(homeState.appPlacardData?.link);
|
launchUrlString(homeState.appPlacardData?.link);
|
||||||
return;
|
return;
|
||||||
case "doc":
|
case "doc":
|
||||||
// showDialog(
|
showDialog(
|
||||||
// context: context,
|
context: context,
|
||||||
// builder: (context) {
|
builder: (context) {
|
||||||
// return BaseUIContainer(
|
return HomeMdContentDialogUI(
|
||||||
// uiCreate: () => MDContentDialogUI(),
|
title: homeState.appPlacardData?.title ?? "公告详情",
|
||||||
// modelCreate: () => MDContentDialogUIModel(
|
url: homeState.appPlacardData?.link,
|
||||||
// appPlacardData?.title ?? "公告详情", appPlacardData?.link));
|
);
|
||||||
// });
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,20 +176,6 @@ class HomeUIModel extends _$HomeUIModel {
|
|||||||
appVersionData: appGlobalState.networkVersionData!,
|
appVersionData: appGlobalState.networkVersionData!,
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (await File(
|
|
||||||
// "${AppConf.applicationSupportDir}\\webview_data\\enable_webview_localization_capture")
|
|
||||||
// .exists()) {
|
|
||||||
// webViewModel.enableCapture = true;
|
|
||||||
// BaseUIContainer(
|
|
||||||
// uiCreate: () => WebviewLocalizationCaptureUI(),
|
|
||||||
// modelCreate: () =>
|
|
||||||
// WebviewLocalizationCaptureUIModel(webViewModel))
|
|
||||||
// .push(context!)
|
|
||||||
// .then((_) {
|
|
||||||
// webViewModel.enableCapture = false;
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
await webViewModel.launch(url, appGlobalState.networkVersionData!);
|
await webViewModel.launch(url, appGlobalState.networkVersionData!);
|
||||||
}
|
}
|
||||||
@ -264,9 +250,10 @@ class HomeUIModel extends _$HomeUIModel {
|
|||||||
|
|
||||||
Future _loadRRS() async {
|
Future _loadRRS() async {
|
||||||
try {
|
try {
|
||||||
|
final rssVideoItems = await RSSApi.getRssVideo();
|
||||||
|
final rssTextItems = await RSSApi.getRssText();
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
rssVideoItems: await RSSApi.getRssVideo(),
|
rssVideoItems: rssVideoItems, rssTextItems: rssTextItems);
|
||||||
rssTextItems: await RSSApi.getRssText());
|
|
||||||
dPrint("RSS update Success !");
|
dPrint("RSS update Success !");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dPrint("_loadRRS Error:$e");
|
dPrint("_loadRRS Error:$e");
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:fluent_ui/fluent_ui.dart';
|
import 'package:fluent_ui/fluent_ui.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:markdown_widget/config/all.dart';
|
import 'package:markdown_widget/config/all.dart';
|
||||||
@ -141,3 +143,49 @@ CustomTransitionPage<T> myPageBuilder<T>(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LoadingWidget<T> extends HookConsumerWidget {
|
||||||
|
final T? data;
|
||||||
|
final Future<T?> Function()? onLoadData;
|
||||||
|
final Widget Function(BuildContext context, T data) childBuilder;
|
||||||
|
|
||||||
|
const LoadingWidget(
|
||||||
|
{super.key, this.data, required this.childBuilder, this.onLoadData});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final dataState = useState<T?>(null);
|
||||||
|
final errorMsg = useState("");
|
||||||
|
useEffect(() {
|
||||||
|
if (data == null && onLoadData != null) {
|
||||||
|
_loadData(dataState, errorMsg);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}, const []);
|
||||||
|
|
||||||
|
if (errorMsg.value.isNotEmpty) {
|
||||||
|
return Button(
|
||||||
|
onPressed: () {
|
||||||
|
_loadData(dataState, errorMsg);
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: Text(errorMsg.value),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (dataState.value == null && data == null) return makeLoading(context);
|
||||||
|
return childBuilder(context, (data ?? dataState.value) as T);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _loadData(
|
||||||
|
ValueNotifier<T?> dataState, ValueNotifier<String> errorMsg) async {
|
||||||
|
errorMsg.value = "";
|
||||||
|
try {
|
||||||
|
final r = await onLoadData!();
|
||||||
|
dataState.value = r;
|
||||||
|
} catch (e) {
|
||||||
|
errorMsg.value = e.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -94,7 +94,7 @@ fn _reade_resp_header(r_header: &HeaderMap) -> HashMap<String, String> {
|
|||||||
for ele in r_header {
|
for ele in r_header {
|
||||||
resp_headers.insert(
|
resp_headers.insert(
|
||||||
ele.0.as_str().to_string(),
|
ele.0.as_str().to_string(),
|
||||||
ele.1.to_str().unwrap().to_string(),
|
ele.1.to_str().unwrap_or("").to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
resp_headers
|
resp_headers
|
||||||
|
Loading…
Reference in New Issue
Block a user