readd: server tags

This commit is contained in:
lollipopkit
2024-02-20 15:40:14 +08:00
parent f4bf7a4d5e
commit 1a64dc5cba
10 changed files with 76 additions and 62 deletions

View File

@@ -217,7 +217,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
TagEditor(
tags: _tags,
onChanged: (p0) => _tags = p0,
allTags: [...Pros.server.tags],
allTags: [...Pros.server.tags.value],
onRenameTag: Pros.server.renameTag,
),
_buildAuth(),

View File

@@ -81,7 +81,7 @@ class _ServerPageState extends State<ServerPage>
Widget _buildBody() {
final child = Consumer<ServerProvider>(
builder: (_, pro, __) {
if (!pro.tags.contains(_tag)) {
if (!pro.tags.value.contains(_tag)) {
_tag = null;
}
if (pro.serverOrder.isEmpty) {

View File

@@ -140,7 +140,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
onChanged: (p0) => setState(() {
_tags.value = p0;
}),
allTags: [...Pros.snippet.tags],
allTags: [...Pros.snippet.tags.value],
onRenameTag: (old, n) => setState(() {
Pros.snippet.renameTag(old, n);
}),

View File

@@ -180,7 +180,7 @@ class _TagEditorState extends State<TagEditor> {
}
class TagSwitcher extends StatelessWidget implements PreferredSizeWidget {
final List<String> tags;
final ValueNotifier<List<String>> tags;
final double width;
final void Function(String?) onTagChanged;
final String? initTag;
@@ -197,26 +197,31 @@ class TagSwitcher extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
if (tags.isEmpty) return UIs.placeholder;
final items = <String?>[null, ...tags];
return Container(
height: _kTagBtnHeight,
width: width,
padding: const EdgeInsets.symmetric(horizontal: 7),
alignment: Alignment.center,
color: Colors.transparent,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final item = items[index];
return TagBtn(
content: item == null ? all : '#$item',
isEnable: initTag == item,
onTap: () => onTagChanged(item),
);
},
itemCount: items.length,
),
return ValueListenableBuilder(
valueListenable: tags,
builder: (_, vals, __) {
if (vals.isEmpty) return UIs.placeholder;
final items = <String?>[null, ...vals];
return Container(
height: _kTagBtnHeight,
width: width,
padding: const EdgeInsets.symmetric(horizontal: 7),
alignment: Alignment.center,
color: Colors.transparent,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final item = items[index];
return TagBtn(
content: item == null ? all : '#$item',
isEnable: initTag == item,
onTap: () => onTagChanged(item),
);
},
itemCount: items.length,
),
);
},
);
}