mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-01-31 13:25:10 +01:00
Simply implement snippet running.
This commit is contained in:
@@ -13,7 +13,7 @@ import 'package:toolbox/data/res/url.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/convert.dart';
|
||||
import 'package:toolbox/view/page/debug.dart';
|
||||
import 'package:toolbox/view/page/private_key/stored.dart';
|
||||
import 'package:toolbox/view/page/private_key/list.dart';
|
||||
import 'package:toolbox/view/page/server/tab.dart';
|
||||
import 'package:toolbox/view/page/setting.dart';
|
||||
import 'package:toolbox/view/page/snippet/list.dart';
|
||||
@@ -92,8 +92,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
leading: const Icon(Icons.snippet_folder),
|
||||
title: const Text('Snippet'),
|
||||
onTap: () =>
|
||||
AppRoute(const SnippetListPage(), 'snippet list')
|
||||
.go(context),
|
||||
AppRoute(const SnippetListPage(), 'snippet list').go(context),
|
||||
),
|
||||
AboutListTile(
|
||||
icon: const Icon(Icons.text_snippet),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:after_layout/after_layout.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/model/server/private_key_info.dart';
|
||||
import 'package:toolbox/data/provider/private_key.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
@@ -70,8 +71,15 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.send),
|
||||
onPressed: () {
|
||||
final info = PrivateKeyInfo(
|
||||
nameController.text, keyController.text, pwdController.text);
|
||||
final name = nameController.text;
|
||||
final key = keyController.text;
|
||||
final pwd = pwdController.text;
|
||||
if (name.isEmpty || key.isEmpty || pwd.isEmpty) {
|
||||
showSnackBar(
|
||||
context, const Text('Three fields must not be empty.'));
|
||||
return;
|
||||
}
|
||||
final info = PrivateKeyInfo(name, key, pwd);
|
||||
if (widget.info != null) {
|
||||
_provider.updateInfo(widget.info!, info);
|
||||
} else {
|
||||
|
||||
@@ -44,12 +44,16 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(si.info.name),
|
||||
actions: [IconButton(onPressed: () => AppRoute(
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context), icon: const Icon(Icons.edit))],
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => AppRoute(
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context),
|
||||
icon: const Icon(Icons.edit))
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(17),
|
||||
|
||||
@@ -59,6 +59,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
onPressed: () {
|
||||
_serverProvider.delServer(widget.spi!);
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text(
|
||||
'Yes',
|
||||
|
||||
@@ -91,11 +91,11 @@ class _ServerPageState extends State<ServerPage>
|
||||
return Card(
|
||||
child: InkWell(
|
||||
onLongPress: () => AppRoute(
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context),
|
||||
ServerEditPage(
|
||||
spi: si.info,
|
||||
),
|
||||
'Edit server info page')
|
||||
.go(context),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(13),
|
||||
child:
|
||||
|
||||
@@ -66,10 +66,14 @@ class _SettingPageState extends State<SettingPage> {
|
||||
display = 'Current: v1.0.${BuildData.build}';
|
||||
}
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
title: Text(display, style: textStyle,
|
||||
textAlign: TextAlign.start,), onTap: () => doUpdate(context, force: true));
|
||||
contentPadding: EdgeInsets.zero,
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
title: Text(
|
||||
display,
|
||||
style: textStyle,
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
onTap: () => doUpdate(context, force: true));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,91 @@
|
||||
import 'package:after_layout/after_layout.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
import 'package:toolbox/data/provider/snippet.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/widget/input_decoration.dart';
|
||||
|
||||
class SnippetEditPage extends StatefulWidget {
|
||||
const SnippetEditPage({Key? key}) : super(key: key);
|
||||
const SnippetEditPage({Key? key, this.snippet}) : super(key: key);
|
||||
|
||||
final Snippet? snippet;
|
||||
|
||||
@override
|
||||
_SnippetEditPageState createState() => _SnippetEditPageState();
|
||||
}
|
||||
|
||||
class _SnippetEditPageState extends State<SnippetEditPage> {
|
||||
class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
with AfterLayoutMixin {
|
||||
final nameController = TextEditingController();
|
||||
final scriptController = TextEditingController();
|
||||
|
||||
late SnippetProvider _provider;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_provider = locator<SnippetProvider>();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(appBar: AppBar(title: const Text('Snippet Edit'),), body: const Center(child: Text('Developing'),),);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Edit'), actions: [
|
||||
widget.snippet != null
|
||||
? IconButton(
|
||||
onPressed: () {
|
||||
_provider.delInfo(widget.snippet!);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
icon: const Icon(Icons.delete))
|
||||
: const SizedBox()
|
||||
]),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(13),
|
||||
children: [
|
||||
TextField(
|
||||
controller: nameController,
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: buildDecoration('Name', icon: Icons.info),
|
||||
),
|
||||
TextField(
|
||||
controller: scriptController,
|
||||
autocorrect: false,
|
||||
minLines: 3,
|
||||
maxLines: 10,
|
||||
keyboardType: TextInputType.text,
|
||||
enableSuggestions: false,
|
||||
decoration: buildDecoration('Snippet', icon: Icons.code),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.send),
|
||||
onPressed: () {
|
||||
final name = nameController.text;
|
||||
final script = scriptController.text;
|
||||
if (name.isEmpty || script.isEmpty) {
|
||||
showSnackBar(context, const Text('Two fields must not be empty.'));
|
||||
return;
|
||||
}
|
||||
final snippet = Snippet(name, script);
|
||||
if (widget.snippet != null) {
|
||||
_provider.updateInfo(widget.snippet!, snippet);
|
||||
} else {
|
||||
_provider.addInfo(snippet);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void afterFirstLayout(BuildContext context) {
|
||||
if (widget.snippet != null) {
|
||||
nameController.text = widget.snippet!.name;
|
||||
scriptController.text = widget.snippet!.script;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
import 'package:toolbox/data/provider/server.dart';
|
||||
import 'package:toolbox/data/provider/snippet.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/snippet/edit.dart';
|
||||
import 'package:toolbox/view/widget/round_rect_card.dart';
|
||||
|
||||
class SnippetListPage extends StatefulWidget {
|
||||
const SnippetListPage({Key? key}) : super(key: key);
|
||||
@@ -8,8 +18,121 @@ class SnippetListPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SnippetListPageState extends State<SnippetListPage> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
final _textStyle = TextStyle(color: primaryColor);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(appBar: AppBar(title: const Text('Snippet List'),), body: const Center(child: Text('Developing'),),);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Snippet List'),
|
||||
),
|
||||
body: _buildBody(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () =>
|
||||
AppRoute(const SnippetEditPage(), 'snippet edit page').go(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return Consumer<SnippetProvider>(
|
||||
builder: (_, key, __) {
|
||||
return key.snippets.isNotEmpty
|
||||
? ListView.builder(
|
||||
padding: const EdgeInsets.all(13),
|
||||
itemCount: key.snippets.length,
|
||||
itemExtent: 57,
|
||||
itemBuilder: (context, idx) {
|
||||
return RoundRectCard(Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
key.snippets[idx].name,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Row(children: [
|
||||
TextButton(
|
||||
onPressed: () => AppRoute(
|
||||
SnippetEditPage(snippet: key.snippets[idx]),
|
||||
'snippet edit page')
|
||||
.go(context),
|
||||
child: Text(
|
||||
'Edit',
|
||||
style: _textStyle,
|
||||
)),
|
||||
TextButton(
|
||||
onPressed: () => _showRunDialog(key.snippets[idx]),
|
||||
child: Text(
|
||||
'Run',
|
||||
style: _textStyle,
|
||||
))
|
||||
])
|
||||
],
|
||||
));
|
||||
})
|
||||
: const Center(child: Text('No saved snippets.'));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showRunDialog(Snippet snippet) {
|
||||
showRoundDialog(context, 'Choose destination',
|
||||
Consumer<ServerProvider>(builder: (_, provider, __) {
|
||||
if (provider.servers.isEmpty) {
|
||||
return const Text('No server available');
|
||||
}
|
||||
return SizedBox(
|
||||
height: 111,
|
||||
child: Stack(children: [
|
||||
Positioned(
|
||||
child: Container(
|
||||
height: 37,
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(7)),
|
||||
color: Colors.black12,
|
||||
),
|
||||
),
|
||||
top: 36,
|
||||
bottom: 36,
|
||||
left: 0,
|
||||
right: 0,
|
||||
),
|
||||
ListWheelScrollView.useDelegate(
|
||||
itemExtent: 37,
|
||||
diameterRatio: 1.2,
|
||||
controller: FixedExtentScrollController(initialItem: 0),
|
||||
onSelectedItemChanged: (idx) => _selectedIndex = idx,
|
||||
physics: const FixedExtentScrollPhysics(),
|
||||
childDelegate: ListWheelChildBuilderDelegate(
|
||||
builder: (context, index) => Center(
|
||||
child: Text(
|
||||
provider.servers[index].info.name,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
childCount: provider.servers.length),
|
||||
)
|
||||
]));
|
||||
}), [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final result = await locator<ServerProvider>()
|
||||
.runSnippet(_selectedIndex, snippet);
|
||||
if (result != null) {
|
||||
showRoundDialog(context, 'Result', Text(result), [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Close'))
|
||||
]);
|
||||
}
|
||||
},
|
||||
child: const Text('Run')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel')),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user