mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
#54 new: grouped snippet & tab snippet
This commit is contained in:
@@ -44,6 +44,9 @@ class _ConvertPageState extends State<ConvertPage>
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_s.convert),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7),
|
||||
controller: ScrollController(),
|
||||
|
||||
@@ -29,14 +29,14 @@ import 'setting.dart';
|
||||
import 'sftp/downloaded.dart';
|
||||
import 'snippet/list.dart';
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({Key? key}) : super(key: key);
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>
|
||||
class _HomePageState extends State<HomePage>
|
||||
with
|
||||
AutomaticKeepAliveClientMixin,
|
||||
AfterLayoutMixin,
|
||||
@@ -122,7 +122,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
});
|
||||
},
|
||||
children: const [ServerPage(), ConvertPage(), PingPage()],
|
||||
children: const [ServerPage(), SnippetListPage(), PingPage()],
|
||||
),
|
||||
bottomNavigationBar: _buildBottomBar(context),
|
||||
);
|
||||
@@ -151,12 +151,14 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
selectedIcon: const Icon(Icons.cloud),
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: const Icon(Icons.code),
|
||||
label: _s.convert,
|
||||
icon: const Icon(Icons.snippet_folder_outlined),
|
||||
label: _s.snippet,
|
||||
selectedIcon: const Icon(Icons.snippet_folder),
|
||||
),
|
||||
const NavigationDestination(
|
||||
icon: Icon(Icons.leak_add),
|
||||
icon: Icon(Icons.network_check_outlined),
|
||||
label: 'Ping',
|
||||
selectedIcon: Icon(Icons.network_check),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -221,11 +223,11 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
).go(context),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.snippet_folder),
|
||||
title: Text(_s.snippet),
|
||||
leading: const Icon(Icons.code),
|
||||
title: Text(_s.convert),
|
||||
onTap: () => AppRoute(
|
||||
const SnippetListPage(),
|
||||
'snippet list',
|
||||
const ConvertPage(),
|
||||
'convert page',
|
||||
).go(context),
|
||||
),
|
||||
ListTile(
|
||||
|
||||
@@ -291,7 +291,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
.map(
|
||||
(e) => PopupMenuItem(
|
||||
value: e.index,
|
||||
child: Text(tabTitleName(context, e.index)),
|
||||
child: Text(tabTitleName(context, e)),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
@@ -316,7 +316,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: _media.size.width * 0.35),
|
||||
child: Text(
|
||||
tabTitleName(context, _launchPageIdx),
|
||||
tabTitleName(context, AppTab.values[_launchPageIdx]),
|
||||
textAlign: TextAlign.right,
|
||||
style: textSize15,
|
||||
),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/view/widget/input_field.dart';
|
||||
import 'package:toolbox/view/widget/tag.dart';
|
||||
|
||||
import '../../../core/utils/ui.dart';
|
||||
import '../../../data/model/server/snippet.dart';
|
||||
@@ -28,6 +29,8 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
late SnippetProvider _provider;
|
||||
late S _s;
|
||||
|
||||
var _tags = <String>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -53,7 +56,8 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
context.pop();
|
||||
},
|
||||
tooltip: _s.delete,
|
||||
icon: const Icon(Icons.delete))
|
||||
icon: const Icon(Icons.delete),
|
||||
)
|
||||
: placeholder
|
||||
],
|
||||
),
|
||||
@@ -72,7 +76,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
showSnackBar(context, Text(_s.fieldMustNotEmpty));
|
||||
return;
|
||||
}
|
||||
final snippet = Snippet(name, script);
|
||||
final snippet = Snippet(name, script, tags: _tags);
|
||||
if (widget.snippet != null) {
|
||||
_provider.update(widget.snippet!, snippet);
|
||||
} else {
|
||||
@@ -103,6 +107,12 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
label: _s.snippet,
|
||||
icon: Icons.code,
|
||||
),
|
||||
TagEditor(
|
||||
tags: widget.snippet?.tags ?? [],
|
||||
onChanged: (p0) => setState(() {
|
||||
_tags = p0;
|
||||
}),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -112,6 +122,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
if (widget.snippet != null) {
|
||||
_nameController.text = widget.snippet!.name;
|
||||
_scriptController.text = widget.snippet!.script;
|
||||
_tags = widget.snippet!.tags ?? [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../data/res/ui.dart';
|
||||
import '/core/route.dart';
|
||||
import '/data/provider/snippet.dart';
|
||||
import 'edit.dart';
|
||||
@@ -27,9 +26,6 @@ class _SnippetListPageState extends State<SnippetListPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_s.snippet, style: textSize18),
|
||||
),
|
||||
body: _buildBody(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.add),
|
||||
@@ -41,8 +37,8 @@ class _SnippetListPageState extends State<SnippetListPage> {
|
||||
|
||||
Widget _buildBody() {
|
||||
return Consumer<SnippetProvider>(
|
||||
builder: (_, key, __) {
|
||||
if (key.snippets.isEmpty) {
|
||||
builder: (_, provider, __) {
|
||||
if (provider.snippets.isEmpty) {
|
||||
return Center(
|
||||
child: Text(_s.noSavedSnippet),
|
||||
);
|
||||
@@ -50,19 +46,22 @@ class _SnippetListPageState extends State<SnippetListPage> {
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(13),
|
||||
itemCount: key.snippets.length,
|
||||
itemCount: provider.snippets.length,
|
||||
itemBuilder: (context, idx) {
|
||||
return RoundRectCard(
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.only(left: 23, right: 17),
|
||||
title: Text(
|
||||
key.snippets[idx].name,
|
||||
provider.snippets[idx].name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
trailing: TextButton(
|
||||
trailing: IconButton(
|
||||
onPressed: () => AppRoute(
|
||||
SnippetEditPage(snippet: key.snippets[idx]),
|
||||
SnippetEditPage(snippet: provider.snippets[idx]),
|
||||
'snippet edit page')
|
||||
.go(context),
|
||||
child: Text(_s.edit),
|
||||
icon: const Icon(Icons.edit),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user