diff --git a/lib/ui/home/input_method/input_method_dialog_ui.dart b/lib/ui/home/input_method/input_method_dialog_ui.dart index 2516dc9..a8ea16e 100644 --- a/lib/ui/home/input_method/input_method_dialog_ui.dart +++ b/lib/ui/home/input_method/input_method_dialog_ui.dart @@ -139,7 +139,7 @@ class InputMethodDialogUI extends HookConsumerWidget { context.pop(); }), const SizedBox(width: 12), - Text("社区输入法"), + Text("社区输入法(实验性)"), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.end, @@ -183,7 +183,7 @@ class InputMethodDialogUI extends HookConsumerWidget { // ignore: use_build_context_synchronously await serverModel.startServer().unwrap(context: context); if (!context.mounted) return; - showDialog( + await showDialog( context: context, builder: (BuildContext context) => ServerQrDialogUI(), ); diff --git a/lib/ui/home/input_method/input_method_dialog_ui_model.g.dart b/lib/ui/home/input_method/input_method_dialog_ui_model.g.dart index 1141aa9..931b70e 100644 --- a/lib/ui/home/input_method/input_method_dialog_ui_model.g.dart +++ b/lib/ui/home/input_method/input_method_dialog_ui_model.g.dart @@ -7,7 +7,7 @@ part of 'input_method_dialog_ui_model.dart'; // ************************************************************************** String _$inputMethodDialogUIModelHash() => - r'93440d8f9c5372d5350ceaa8cb00a1b0d3b0046e'; + r'1c7193891c609715b2c7ee1b34f67aa26b18d303'; /// See also [InputMethodDialogUIModel]. @ProviderFor(InputMethodDialogUIModel) diff --git a/lib/ui/home/input_method/server.dart b/lib/ui/home/input_method/server.dart index 1c571b8..124de71 100644 --- a/lib/ui/home/input_method/server.dart +++ b/lib/ui/home/input_method/server.dart @@ -9,6 +9,7 @@ import 'package:shelf/shelf.dart'; import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:starcitizen_doctor/common/conf/const_conf.dart'; import 'package:starcitizen_doctor/common/utils/log.dart'; +import 'package:starcitizen_doctor/ui/home/input_method/server_qr_dialog_ui.dart'; import 'package:starcitizen_doctor/ui/home/localization/localization_ui_model.dart'; import 'input_method_dialog_ui_model.dart'; @@ -57,7 +58,6 @@ class InputMethodServer extends _$InputMethodServer { Future startServer() async { dPrint("[InputMethodServer] startServer"); - var handler = const Pipeline().addMiddleware(logRequests()).addHandler(_onHandler); @@ -166,6 +166,10 @@ class InputMethodServer extends _$InputMethodServer { Future _onHandlerApi(Request request) async { final path = request.url.path; if (path == "api") { + if (ref.exists(serverQrStateProvider)) { + // ignore: avoid_manual_providers_as_generated_provider_dependency + ref.read(serverQrStateProvider.notifier).popDialog(); + } return Response.ok(json.encode({ "status": "ok", "appVersion": ConstConf.appVersion, diff --git a/lib/ui/home/input_method/server.g.dart b/lib/ui/home/input_method/server.g.dart index cbdba8c..9fcf5f2 100644 --- a/lib/ui/home/input_method/server.g.dart +++ b/lib/ui/home/input_method/server.g.dart @@ -6,7 +6,7 @@ part of 'server.dart'; // RiverpodGenerator // ************************************************************************** -String _$inputMethodServerHash() => r'4ea07de4bca3268933b78335b670c09e6fac61bc'; +String _$inputMethodServerHash() => r'227e0e32cd7b8895f3b108505cd524680afc4126'; /// See also [InputMethodServer]. @ProviderFor(InputMethodServer) diff --git a/lib/ui/home/input_method/server_qr_dialog_ui.dart b/lib/ui/home/input_method/server_qr_dialog_ui.dart index b04c01f..39c87ee 100644 --- a/lib/ui/home/input_method/server_qr_dialog_ui.dart +++ b/lib/ui/home/input_method/server_qr_dialog_ui.dart @@ -3,9 +3,32 @@ import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:qr_flutter/qr_flutter.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'server.dart'; +part 'server_qr_dialog_ui.g.dart'; + + +@riverpod +class ServerQrState extends _$ServerQrState { + @override + bool build() { + return true; + } + + BuildContext? _context; + + // ignore: avoid_build_context_in_providers + void setupContext(BuildContext context) { + _context = context; + } + + popDialog() { + _context?.pop(); + } +} + class ServerQrDialogUI extends HookConsumerWidget { const ServerQrDialogUI({super.key}); @@ -19,6 +42,10 @@ class ServerQrDialogUI extends HookConsumerWidget { final index = useState(0); + final model = ref.watch(serverQrStateProvider.notifier); + + model.setupContext(context); + return ContentDialog( constraints: BoxConstraints( maxWidth: MediaQuery.of(context).size.width * .4, @@ -67,7 +94,7 @@ class ServerQrDialogUI extends HookConsumerWidget { SizedBox(height: 12), Text( hasMultipleUrls - ? "(${index.value + 1} / ${urls.length})" + ? "${urls[index.value]} (${index.value + 1} / ${urls.length})" : urls[index.value], style: TextStyle(fontSize: 13, color: Colors.white.withOpacity(.6)), ), diff --git a/lib/ui/home/input_method/server_qr_dialog_ui.g.dart b/lib/ui/home/input_method/server_qr_dialog_ui.g.dart new file mode 100644 index 0000000..6de2f99 --- /dev/null +++ b/lib/ui/home/input_method/server_qr_dialog_ui.g.dart @@ -0,0 +1,26 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'server_qr_dialog_ui.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$serverQrStateHash() => r'06f5ab53e1d6718f2a6eb0078a1adc3778787ed0'; + +/// See also [ServerQrState]. +@ProviderFor(ServerQrState) +final serverQrStateProvider = + AutoDisposeNotifierProvider.internal( + ServerQrState.new, + name: r'serverQrStateProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$serverQrStateHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$ServerQrState = AutoDisposeNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package