#73 opt.: reorderable

This commit is contained in:
lollipopkit
2023-07-21 15:05:09 +08:00
parent aac556f769
commit 262b4486e4
4 changed files with 99 additions and 83 deletions

View File

@@ -88,40 +88,13 @@ class _SnippetListPageState extends State<SnippetListPage> {
all: _s.all,
width: _media.size.width,
),
buildDefaultDragHandles: false,
itemBuilder: (context, idx) {
final snippet = filtered.elementAt(idx);
return RoundRectCard(
ListTile(
contentPadding: const EdgeInsets.only(left: 23, right: 17),
title: Text(
snippet.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
subtitle: Text(
snippet.script,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: grey,
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () => AppRoute(
SnippetEditPage(snippet: snippet),
'snippet edit page',
).go(context),
icon: const Icon(Icons.edit),
),
IconButton(
onPressed: () => _runSnippet(snippet),
icon: const Icon(Icons.play_arrow),
),
],
),
),
return ReorderableDelayedDragStartListener(
key: ValueKey(snippet.name),
index: idx,
child: _buildSnippetItem(snippet),
);
},
);
@@ -129,6 +102,41 @@ class _SnippetListPageState extends State<SnippetListPage> {
);
}
Widget _buildSnippetItem(Snippet snippet) {
return RoundRectCard(
ListTile(
contentPadding: const EdgeInsets.only(left: 23, right: 17),
title: Text(
snippet.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
subtitle: Text(
snippet.script,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: grey,
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () => AppRoute(
SnippetEditPage(snippet: snippet),
'snippet edit page',
).go(context),
icon: const Icon(Icons.edit),
),
IconButton(
onPressed: () => _runSnippet(snippet),
icon: const Icon(Icons.play_arrow),
),
],
),
),
);
}
Future<void> _runSnippet(Snippet snippet) async {
final provider = locator<ServerProvider>();
final servers = await showDialog<List<Server>>(