mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
Simply implement snippet running.
This commit is contained in:
@@ -6,7 +6,10 @@ class Analysis {
|
|||||||
static const _url = 'https://countly.xuty.cc';
|
static const _url = 'https://countly.xuty.cc';
|
||||||
static const _key = '80372a2a66424b32d0ac8991bfa1ef058bd36b1f';
|
static const _key = '80372a2a66424b32d0ac8991bfa1ef058bd36b1f';
|
||||||
|
|
||||||
|
static bool _enabled = false;
|
||||||
|
|
||||||
static Future<void> init(bool debug) async {
|
static Future<void> init(bool debug) async {
|
||||||
|
_enabled = true;
|
||||||
await Countly.setLoggingEnabled(debug);
|
await Countly.setLoggingEnabled(debug);
|
||||||
await Countly.init(_url, _key);
|
await Countly.init(_url, _key);
|
||||||
await Countly.start();
|
await Countly.start();
|
||||||
@@ -15,10 +18,14 @@ class Analysis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void recordView(String view) {
|
static void recordView(String view) {
|
||||||
|
if (_enabled) {
|
||||||
Countly.recordView(view);
|
Countly.recordView(view);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void recordException(Object exception, [bool fatal = false]) {
|
static void recordException(Object exception, [bool fatal = false]) {
|
||||||
|
if (_enabled) {
|
||||||
Countly.logException(exception.toString(), !fatal, null);
|
Countly.logException(exception.toString(), !fatal, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ bool isDarkMode(BuildContext context) =>
|
|||||||
void showSnackBar(BuildContext context, Widget child) =>
|
void showSnackBar(BuildContext context, Widget child) =>
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: child));
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: child));
|
||||||
|
|
||||||
void showSnackBarWithAction(
|
void showSnackBarWithAction(BuildContext context, String content, String action,
|
||||||
BuildContext context, String content, String action, Function onTap) {
|
GestureTapCallback onTap) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text(content),
|
content: Text(content),
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
label: action,
|
label: action,
|
||||||
onPressed: () => onTap,
|
onPressed: onTap,
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,11 @@ class Memory {
|
|||||||
int shared;
|
int shared;
|
||||||
int cache;
|
int cache;
|
||||||
int avail;
|
int avail;
|
||||||
Memory({required this.total, required this.used, required this.free, required this.shared, required this.cache, required this.avail});
|
Memory(
|
||||||
|
{required this.total,
|
||||||
|
required this.used,
|
||||||
|
required this.free,
|
||||||
|
required this.shared,
|
||||||
|
required this.cache,
|
||||||
|
required this.avail});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'package:toolbox/data/model/server/disk_info.dart';
|
|||||||
import 'package:toolbox/data/model/server/server.dart';
|
import 'package:toolbox/data/model/server/server.dart';
|
||||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||||
import 'package:toolbox/data/model/server/server_status.dart';
|
import 'package:toolbox/data/model/server/server_status.dart';
|
||||||
|
import 'package:toolbox/data/model/server/snippet.dart';
|
||||||
import 'package:toolbox/data/model/server/tcp_status.dart';
|
import 'package:toolbox/data/model/server/tcp_status.dart';
|
||||||
import 'package:toolbox/data/store/server.dart';
|
import 'package:toolbox/data/store/server.dart';
|
||||||
import 'package:toolbox/data/store/setting.dart';
|
import 'package:toolbox/data/store/setting.dart';
|
||||||
@@ -290,4 +291,8 @@ class ServerProvider extends BusyProvider {
|
|||||||
}
|
}
|
||||||
return emptyMemory;
|
return emptyMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String?> runSnippet(int idx, Snippet snippet) {
|
||||||
|
return _servers[idx].client.execute(snippet.script);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
lib/data/provider/snippet.dart
Normal file
32
lib/data/provider/snippet.dart
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import 'package:toolbox/core/provider_base.dart';
|
||||||
|
import 'package:toolbox/data/model/server/snippet.dart';
|
||||||
|
import 'package:toolbox/data/store/snippet.dart';
|
||||||
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
|
class SnippetProvider extends BusyProvider {
|
||||||
|
List<Snippet> get snippets => _snippets;
|
||||||
|
late List<Snippet> _snippets;
|
||||||
|
|
||||||
|
void loadData() {
|
||||||
|
_snippets = locator<SnippetStore>().fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addInfo(Snippet snippet) {
|
||||||
|
_snippets.add(snippet);
|
||||||
|
locator<SnippetStore>().put(snippet);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void delInfo(Snippet snippet) {
|
||||||
|
_snippets.removeWhere((e) => e.name == snippet.name);
|
||||||
|
locator<SnippetStore>().delete(snippet);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateInfo(Snippet old, Snippet newOne) {
|
||||||
|
final idx = _snippets.indexWhere((e) => e.name == old.name);
|
||||||
|
_snippets[idx] = newOne;
|
||||||
|
locator<SnippetStore>().update(old, newOne);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
class BuildData {
|
class BuildData {
|
||||||
static const String name = "ToolBox";
|
static const String name = "ToolBox";
|
||||||
static const int build = 60;
|
static const int build = 61;
|
||||||
static const String engine = "Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (3 weeks ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
static const String engine =
|
||||||
static const String buildAt = "2021-11-02 20:36:41.010803";
|
"Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 18116933e7 (3 weeks ago) • 2021-10-15 10:46:35 -0700\nEngine • revision d3ea636dc5\nTools • Dart 2.14.4\n";
|
||||||
static const int modifications = 2;
|
static const String buildAt = "2021-11-05 12:58:33.427838";
|
||||||
|
static const int modifications = 15;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:toolbox/data/provider/app.dart';
|
|||||||
import 'package:toolbox/data/provider/debug.dart';
|
import 'package:toolbox/data/provider/debug.dart';
|
||||||
import 'package:toolbox/data/provider/private_key.dart';
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
|
import 'package:toolbox/data/provider/snippet.dart';
|
||||||
import 'package:toolbox/data/service/app.dart';
|
import 'package:toolbox/data/service/app.dart';
|
||||||
import 'package:toolbox/data/store/private_key.dart';
|
import 'package:toolbox/data/store/private_key.dart';
|
||||||
import 'package:toolbox/data/store/server.dart';
|
import 'package:toolbox/data/store/server.dart';
|
||||||
@@ -19,6 +20,7 @@ void setupLocatorForProviders() {
|
|||||||
locator.registerSingleton(AppProvider());
|
locator.registerSingleton(AppProvider());
|
||||||
locator.registerSingleton(DebugProvider());
|
locator.registerSingleton(DebugProvider());
|
||||||
locator.registerSingleton(ServerProvider());
|
locator.registerSingleton(ServerProvider());
|
||||||
|
locator.registerSingleton(SnippetProvider());
|
||||||
locator.registerSingleton(PrivateKeyProvider());
|
locator.registerSingleton(PrivateKeyProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import 'package:toolbox/data/provider/app.dart';
|
|||||||
import 'package:toolbox/data/provider/debug.dart';
|
import 'package:toolbox/data/provider/debug.dart';
|
||||||
import 'package:toolbox/data/provider/private_key.dart';
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/data/provider/server.dart';
|
import 'package:toolbox/data/provider/server.dart';
|
||||||
|
import 'package:toolbox/data/provider/snippet.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
|
|
||||||
Future<void> initApp() async {
|
Future<void> initApp() async {
|
||||||
await Hive.initFlutter();
|
await Hive.initFlutter();
|
||||||
await setupLocator();
|
await setupLocator();
|
||||||
|
locator<SnippetProvider>().loadData();
|
||||||
locator<PrivateKeyProvider>().loadData();
|
locator<PrivateKeyProvider>().loadData();
|
||||||
|
|
||||||
///设置Logger
|
///设置Logger
|
||||||
@@ -62,6 +64,7 @@ Future<void> main() async {
|
|||||||
ChangeNotifierProvider(create: (_) => locator<AppProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<AppProvider>()),
|
||||||
ChangeNotifierProvider(create: (_) => locator<DebugProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<DebugProvider>()),
|
||||||
ChangeNotifierProvider(create: (_) => locator<ServerProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<ServerProvider>()),
|
||||||
|
ChangeNotifierProvider(create: (_) => locator<SnippetProvider>()),
|
||||||
ChangeNotifierProvider(create: (_) => locator<PrivateKeyProvider>()),
|
ChangeNotifierProvider(create: (_) => locator<PrivateKeyProvider>()),
|
||||||
],
|
],
|
||||||
child: const MyApp(),
|
child: const MyApp(),
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import 'package:toolbox/data/res/url.dart';
|
|||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
import 'package:toolbox/view/page/convert.dart';
|
import 'package:toolbox/view/page/convert.dart';
|
||||||
import 'package:toolbox/view/page/debug.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/server/tab.dart';
|
||||||
import 'package:toolbox/view/page/setting.dart';
|
import 'package:toolbox/view/page/setting.dart';
|
||||||
import 'package:toolbox/view/page/snippet/list.dart';
|
import 'package:toolbox/view/page/snippet/list.dart';
|
||||||
@@ -92,8 +92,7 @@ class _MyHomePageState extends State<MyHomePage>
|
|||||||
leading: const Icon(Icons.snippet_folder),
|
leading: const Icon(Icons.snippet_folder),
|
||||||
title: const Text('Snippet'),
|
title: const Text('Snippet'),
|
||||||
onTap: () =>
|
onTap: () =>
|
||||||
AppRoute(const SnippetListPage(), 'snippet list')
|
AppRoute(const SnippetListPage(), 'snippet list').go(context),
|
||||||
.go(context),
|
|
||||||
),
|
),
|
||||||
AboutListTile(
|
AboutListTile(
|
||||||
icon: const Icon(Icons.text_snippet),
|
icon: const Icon(Icons.text_snippet),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:after_layout/after_layout.dart';
|
import 'package:after_layout/after_layout.dart';
|
||||||
import 'package:flutter/material.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/model/server/private_key_info.dart';
|
||||||
import 'package:toolbox/data/provider/private_key.dart';
|
import 'package:toolbox/data/provider/private_key.dart';
|
||||||
import 'package:toolbox/locator.dart';
|
import 'package:toolbox/locator.dart';
|
||||||
@@ -70,8 +71,15 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
|
|||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: const Icon(Icons.send),
|
child: const Icon(Icons.send),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final info = PrivateKeyInfo(
|
final name = nameController.text;
|
||||||
nameController.text, keyController.text, pwdController.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) {
|
if (widget.info != null) {
|
||||||
_provider.updateInfo(widget.info!, info);
|
_provider.updateInfo(widget.info!, info);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -44,12 +44,16 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(si.info.name),
|
title: Text(si.info.name),
|
||||||
actions: [IconButton(onPressed: () => AppRoute(
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => AppRoute(
|
||||||
ServerEditPage(
|
ServerEditPage(
|
||||||
spi: si.info,
|
spi: si.info,
|
||||||
),
|
),
|
||||||
'Edit server info page')
|
'Edit server info page')
|
||||||
.go(context), icon: const Icon(Icons.edit))],
|
.go(context),
|
||||||
|
icon: const Icon(Icons.edit))
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
padding: const EdgeInsets.all(17),
|
padding: const EdgeInsets.all(17),
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
_serverProvider.delServer(widget.spi!);
|
_serverProvider.delServer(widget.spi!);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Yes',
|
'Yes',
|
||||||
|
|||||||
@@ -68,8 +68,12 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||||
title: Text(display, style: textStyle,
|
title: Text(
|
||||||
textAlign: TextAlign.start,), onTap: () => doUpdate(context, force: true));
|
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: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 {
|
class SnippetEditPage extends StatefulWidget {
|
||||||
const SnippetEditPage({Key? key}) : super(key: key);
|
const SnippetEditPage({Key? key, this.snippet}) : super(key: key);
|
||||||
|
|
||||||
|
final Snippet? snippet;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SnippetEditPageState createState() => _SnippetEditPageState();
|
_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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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: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 {
|
class SnippetListPage extends StatefulWidget {
|
||||||
const SnippetListPage({Key? key}) : super(key: key);
|
const SnippetListPage({Key? key}) : super(key: key);
|
||||||
@@ -8,8 +18,121 @@ class SnippetListPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SnippetListPageState extends State<SnippetListPage> {
|
class _SnippetListPageState extends State<SnippetListPage> {
|
||||||
|
int _selectedIndex = 0;
|
||||||
|
|
||||||
|
final _textStyle = TextStyle(color: primaryColor);
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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