mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
#54 snippet group
This commit is contained in:
@@ -74,7 +74,11 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
left: 13, right: 13, top: 13, bottom: _media.padding.bottom),
|
||||
onReorder: (int oldIndex, int newIndex) {
|
||||
setState(() {
|
||||
_cardsOrder.move(oldIndex, newIndex, _setting.detailCardOrder);
|
||||
_cardsOrder.move(
|
||||
oldIndex,
|
||||
newIndex,
|
||||
property: _setting.detailCardOrder,
|
||||
);
|
||||
});
|
||||
},
|
||||
footer: height13,
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/core/extension/order.dart';
|
||||
import 'package:toolbox/core/utils/misc.dart';
|
||||
import 'package:toolbox/view/page/process.dart';
|
||||
import 'package:toolbox/view/widget/tag_switcher.dart';
|
||||
|
||||
import '../../../core/route.dart';
|
||||
import '../../../core/utils/ui.dart';
|
||||
@@ -103,13 +104,21 @@ class _ServerPageState extends State<ServerPage>
|
||||
(pro.servers[e]?.spi.tags?.contains(_tag) ?? false))
|
||||
.toList();
|
||||
return ReorderableListView.builder(
|
||||
header: _buildTagsSwitcher(pro.tags),
|
||||
header: TagSwitcher(
|
||||
tags: pro.tags,
|
||||
width: _media.size.width,
|
||||
onTagChanged: (p0) => setState(() {
|
||||
_tag = p0;
|
||||
}),
|
||||
initTag: _tag,
|
||||
all: _s.all,
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(7, 10, 7, 7),
|
||||
onReorder: (oldIndex, newIndex) => setState(() {
|
||||
pro.serverOrder.moveById(
|
||||
filtered[oldIndex],
|
||||
filtered[newIndex],
|
||||
_settingStore.serverOrder,
|
||||
property: _settingStore.serverOrder,
|
||||
);
|
||||
}),
|
||||
itemBuilder: (_, index) => _buildEachServerCard(
|
||||
@@ -122,51 +131,6 @@ class _ServerPageState extends State<ServerPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagsSwitcher(List<String> tags) {
|
||||
if (tags.isEmpty) return nil;
|
||||
final items = <String?>[null, ...tags];
|
||||
return Container(
|
||||
height: 37,
|
||||
width: _media.size.width,
|
||||
alignment: Alignment.center,
|
||||
color: Colors.transparent,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemBuilder: (context, index) => _buildTagItem(items[index]),
|
||||
itemCount: items.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagItem(String? tag) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 4, right: 5, bottom: 9),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_tag = tag;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20.0)),
|
||||
color: primaryColor.withAlpha(20),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 2.7),
|
||||
child: Center(
|
||||
child: Text(
|
||||
tag == null ? _s.all : '#$tag',
|
||||
style: TextStyle(
|
||||
color: _tag == tag ? null : _theme.disabledColor,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEachServerCard(Server? si) {
|
||||
if (si == null) {
|
||||
return nil;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:after_layout/after_layout.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:nil/nil.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
|
||||
@@ -10,6 +9,7 @@ import '../../../data/model/server/snippet.dart';
|
||||
import '../../../data/provider/snippet.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../../widget/tag_editor.dart';
|
||||
|
||||
class SnippetEditPage extends StatefulWidget {
|
||||
const SnippetEditPage({Key? key, this.snippet}) : super(key: key);
|
||||
@@ -29,6 +29,8 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
late SnippetProvider _provider;
|
||||
late S _s;
|
||||
|
||||
List<String> _tags = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -46,24 +48,29 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_s.edit, style: textSize18),
|
||||
actions: [
|
||||
widget.snippet != null
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
_provider.del(widget.snippet!);
|
||||
context.pop();
|
||||
},
|
||||
tooltip: _s.delete,
|
||||
icon: const Icon(Icons.delete),
|
||||
)
|
||||
: nil
|
||||
],
|
||||
actions: _buildAppBarActions(),
|
||||
),
|
||||
body: _buildBody(),
|
||||
floatingActionButton: _buildFAB(),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget>? _buildAppBarActions() {
|
||||
if (widget.snippet == null) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
_provider.del(widget.snippet!);
|
||||
context.pop();
|
||||
},
|
||||
tooltip: _s.delete,
|
||||
icon: const Icon(Icons.delete),
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildFAB() {
|
||||
return FloatingActionButton(
|
||||
heroTag: 'snippet',
|
||||
@@ -75,7 +82,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
showSnackBar(context, Text(_s.fieldMustNotEmpty));
|
||||
return;
|
||||
}
|
||||
final snippet = Snippet(name, script);
|
||||
final snippet = Snippet(name, script, _tags);
|
||||
if (widget.snippet != null) {
|
||||
_provider.update(widget.snippet!, snippet);
|
||||
} else {
|
||||
@@ -106,6 +113,15 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
label: _s.snippet,
|
||||
icon: Icons.code,
|
||||
),
|
||||
TagEditor(
|
||||
tags: _tags,
|
||||
onChanged: (p0) => setState(() {
|
||||
_tags = p0;
|
||||
}),
|
||||
s: _s,
|
||||
tagSuggestions: [..._provider.tags],
|
||||
onRenameTag: _provider.renameTag,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/extension/order.dart';
|
||||
import 'package:toolbox/view/widget/tag_switcher.dart';
|
||||
|
||||
import '../../../data/store/setting.dart';
|
||||
import '../../../locator.dart';
|
||||
import '/core/route.dart';
|
||||
import '/data/provider/snippet.dart';
|
||||
import 'edit.dart';
|
||||
@@ -16,11 +20,17 @@ class SnippetListPage extends StatefulWidget {
|
||||
|
||||
class _SnippetListPageState extends State<SnippetListPage> {
|
||||
late S _s;
|
||||
late MediaQueryData _media;
|
||||
|
||||
final _settingStore = locator<SettingStore>();
|
||||
|
||||
String? _tag;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_s = S.of(context)!;
|
||||
_media = MediaQuery.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -47,26 +57,48 @@ class _SnippetListPageState extends State<SnippetListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
final filtered = provider.snippets
|
||||
.where((e) => _tag == null || (e.tags?.contains(_tag) ?? false))
|
||||
.toList();
|
||||
|
||||
return ReorderableListView.builder(
|
||||
padding: const EdgeInsets.all(13),
|
||||
itemCount: provider.snippets.length,
|
||||
itemCount: filtered.length,
|
||||
onReorder: (oldIdx, newIdx) => setState(() {
|
||||
provider.snippets.moveById(
|
||||
filtered[oldIdx],
|
||||
filtered[newIdx],
|
||||
onMove: (p0) {
|
||||
_settingStore.snippetOrder.put(p0.map((e) => e.name).toList());
|
||||
},
|
||||
);
|
||||
}),
|
||||
header: TagSwitcher(
|
||||
tags: provider.tags,
|
||||
onTagChanged: (tag) => setState(() => _tag = tag),
|
||||
initTag: _tag,
|
||||
all: _s.all,
|
||||
width: _media.size.width,
|
||||
),
|
||||
itemBuilder: (context, idx) {
|
||||
final snippet = filtered[idx];
|
||||
return RoundRectCard(
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.only(left: 23, right: 17),
|
||||
title: Text(
|
||||
provider.snippets[idx].name,
|
||||
snippet.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
trailing: IconButton(
|
||||
onPressed: () => AppRoute(
|
||||
SnippetEditPage(snippet: provider.snippets[idx]),
|
||||
'snippet edit page')
|
||||
.go(context),
|
||||
SnippetEditPage(snippet: snippet),
|
||||
'snippet edit page',
|
||||
).go(context),
|
||||
icon: const Icon(Icons.edit),
|
||||
),
|
||||
),
|
||||
key: ValueKey(snippet.name),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -58,7 +58,7 @@ class _SSHVirtKeySettingPageState extends State<SSHVirtKeySettingPage> {
|
||||
showSnackBar(context, Text(_s.disabled));
|
||||
return;
|
||||
}
|
||||
keys.moveById(keys[o], keys[n], _setting.sshVirtKeys);
|
||||
keys.moveById(keys[o], keys[n], property: _setting.sshVirtKeys);
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
|
||||
67
lib/view/widget/tag_switcher.dart
Normal file
67
lib/view/widget/tag_switcher.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nil/nil.dart';
|
||||
|
||||
import '../../data/res/color.dart';
|
||||
|
||||
class TagSwitcher extends StatelessWidget {
|
||||
final List<String> tags;
|
||||
final double width;
|
||||
final void Function(String?) onTagChanged;
|
||||
final String? initTag;
|
||||
final String all;
|
||||
|
||||
const TagSwitcher({
|
||||
Key? key,
|
||||
required this.tags,
|
||||
required this.width,
|
||||
required this.onTagChanged,
|
||||
required this.all,
|
||||
this.initTag,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _buildTagsSwitcher(tags);
|
||||
}
|
||||
|
||||
Widget _buildTagsSwitcher(List<String> tags) {
|
||||
if (tags.isEmpty) return nil;
|
||||
final items = <String?>[null, ...tags];
|
||||
return Container(
|
||||
height: 37,
|
||||
width: width,
|
||||
alignment: Alignment.center,
|
||||
color: Colors.transparent,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemBuilder: (context, index) => _buildTagItem(items[index]),
|
||||
itemCount: items.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagItem(String? tag) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 4, right: 5, bottom: 9),
|
||||
child: GestureDetector(
|
||||
onTap: () => onTagChanged(tag),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20.0)),
|
||||
color: primaryColor.withAlpha(20),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 11, vertical: 2.7),
|
||||
child: Center(
|
||||
child: Text(
|
||||
tag == null ? all : '#$tag',
|
||||
style: TextStyle(
|
||||
color: initTag == tag ? null : Colors.grey,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user