chore: release client-v1.0.67
Deploy Client / build-client-web (push) Successful in 41s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / build-macos (push) Successful in 2m33s
Deploy Client / build-android (push) Successful in 1m6s
Deploy Client / build-ios (push) Successful in 2m42s
Deploy Client / release-deploy-client (push) Successful in 1m27s
Deploy Client / build-client-web (push) Successful in 41s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / build-macos (push) Successful in 2m33s
Deploy Client / build-android (push) Successful in 1m6s
Deploy Client / build-ios (push) Successful in 2m42s
Deploy Client / release-deploy-client (push) Successful in 1m27s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../core/utils/dialog_util.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../core/responsive/responsive.dart';
|
||||
@@ -41,6 +43,9 @@ class SearchableOptionField extends StatelessWidget {
|
||||
/// 创建成功返回新选项 id(自动选中),失败/取消返回 null。为空则不显示新增入口。
|
||||
final Future<int?> Function(String keyword)? onCreate;
|
||||
|
||||
/// 可选:服务端搜索。提供时搜索框输入会 debounce 调它取结果(替代本地过滤)。
|
||||
final Future<List<OptionItem>> Function(String keyword)? onSearch;
|
||||
|
||||
const SearchableOptionField({
|
||||
super.key,
|
||||
required this.options,
|
||||
@@ -51,6 +56,7 @@ class SearchableOptionField extends StatelessWidget {
|
||||
this.isRequired = false,
|
||||
this.isDense = true,
|
||||
this.onCreate,
|
||||
this.onSearch,
|
||||
});
|
||||
|
||||
String get _displayText {
|
||||
@@ -66,6 +72,7 @@ class SearchableOptionField extends StatelessWidget {
|
||||
options: options,
|
||||
selectedId: selectedId,
|
||||
onCreate: onCreate,
|
||||
onSearch: onSearch,
|
||||
),
|
||||
);
|
||||
// result == -1 means "clear selection"
|
||||
@@ -120,11 +127,13 @@ class _SearchDialog extends StatefulWidget {
|
||||
final List<OptionItem> options;
|
||||
final int? selectedId;
|
||||
final Future<int?> Function(String keyword)? onCreate;
|
||||
final Future<List<OptionItem>> Function(String keyword)? onSearch;
|
||||
const _SearchDialog({
|
||||
required this.title,
|
||||
required this.options,
|
||||
this.selectedId,
|
||||
this.onCreate,
|
||||
this.onSearch,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -135,9 +144,28 @@ class _SearchDialogState extends State<_SearchDialog> {
|
||||
final _ctrl = TextEditingController();
|
||||
String _keyword = '';
|
||||
bool _creating = false;
|
||||
List<OptionItem>? _serverItems; // 服务端搜索结果(null=尚未搜索,用 widget.options)
|
||||
bool _searching = false;
|
||||
Timer? _debounce;
|
||||
|
||||
void _onSearchChanged(String v) {
|
||||
setState(() => _keyword = v);
|
||||
if (widget.onSearch == null) return;
|
||||
_debounce?.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 300), () async {
|
||||
setState(() => _searching = true);
|
||||
try {
|
||||
final res = await widget.onSearch!(v.trim());
|
||||
if (mounted) setState(() => _serverItems = res);
|
||||
} finally {
|
||||
if (mounted) setState(() => _searching = false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -197,12 +225,14 @@ class _SearchDialogState extends State<_SearchDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final filtered = _keyword.isEmpty
|
||||
? widget.options
|
||||
: widget.options.where((o) => o.matches(_keyword)).toList();
|
||||
final filtered = widget.onSearch != null
|
||||
? (_serverItems ?? widget.options)
|
||||
: (_keyword.isEmpty
|
||||
? widget.options
|
||||
: widget.options.where((o) => o.matches(_keyword)).toList());
|
||||
final kw = _keyword.trim();
|
||||
final hasExact =
|
||||
widget.options.any((o) => o.name.toLowerCase() == kw.toLowerCase());
|
||||
filtered.any((o) => o.name.toLowerCase() == kw.toLowerCase());
|
||||
final canCreate = widget.onCreate != null && kw.isNotEmpty && !hasExact;
|
||||
|
||||
return AlertDialog(
|
||||
@@ -216,12 +246,22 @@ class _SearchDialogState extends State<_SearchDialog> {
|
||||
TextField(
|
||||
controller: _ctrl,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索...',
|
||||
prefixIcon: Icon(Icons.search, size: 18),
|
||||
prefixIcon: const Icon(Icons.search, size: 18),
|
||||
suffixIcon: _searching
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
isDense: true,
|
||||
),
|
||||
onChanged: (v) => setState(() => _keyword = v),
|
||||
onChanged: _onSearchChanged,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user