new: pick dialog support tags

This commit is contained in:
lollipopkit
2024-02-20 16:13:36 +08:00
parent 1a64dc5cba
commit ba564a886b
9 changed files with 125 additions and 40 deletions

View File

@@ -122,11 +122,18 @@ void _onTapMoreBtns(
);
break;
case ServerFuncBtn.snippet:
final snippet = await context.showPickSingleDialog<Snippet>(
items: Pros.snippet.snippets,
final snippets = await context.showPickWithTagDialog<Snippet>(
tags: Pros.snippet.tags,
itemsBuilder: (e) {
if (e == null) return Pros.snippet.snippets;
return Pros.snippet.snippets
.where((element) => element.tags?.contains(e) ?? false)
.toList();
},
name: (e) => e.name,
);
if (snippet == null) return;
if (snippets == null || snippets.isEmpty) return;
final snippet = snippets.first;
AppRoute.ssh(spi: spi, initCmd: snippet.fmtWith(spi)).checkGo(
context: context,

View File

@@ -184,14 +184,12 @@ class TagSwitcher extends StatelessWidget implements PreferredSizeWidget {
final double width;
final void Function(String?) onTagChanged;
final String? initTag;
final String all;
const TagSwitcher({
super.key,
required this.tags,
required this.width,
required this.onTagChanged,
required this.all,
this.initTag,
});
@@ -213,7 +211,7 @@ class TagSwitcher extends StatelessWidget implements PreferredSizeWidget {
itemBuilder: (context, index) {
final item = items[index];
return TagBtn(
content: item == null ? all : '#$item',
content: item == null ? l10n.all : '#$item',
isEnable: initTag == item,
onTap: () => onTagChanged(item),
);