#54 run multiple snippets

This commit is contained in:
lollipopkit
2023-07-08 00:12:15 +08:00
parent cb16b3a8b6
commit fefd3f9701
25 changed files with 326 additions and 116 deletions

View File

@@ -360,7 +360,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 369; CURRENT_PROJECT_VERSION = 372;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -368,7 +368,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.369; MARKETING_VERSION = 1.0.372;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -491,7 +491,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 369; CURRENT_PROJECT_VERSION = 372;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -499,7 +499,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.369; MARKETING_VERSION = 1.0.372;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -516,7 +516,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 369; CURRENT_PROJECT_VERSION = 372;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
@@ -524,7 +524,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.369; MARKETING_VERSION = 1.0.372;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View File

@@ -63,6 +63,7 @@ Future<T?> showRoundDialog<T>({
title: title, title: title,
content: child, content: child,
actions: actions, actions: actions,
actionsPadding: const EdgeInsets.all(17),
); );
}, },
); );

View File

@@ -276,11 +276,11 @@ class ServerProvider extends BusyProvider {
} }
} }
Future<String?> runSnippet(String id, Snippet snippet) async { Future<String?> runSnippets(String id, List<Snippet> snippets) async {
final client = _servers[id]?.client; final client = _servers[id]?.client;
if (client == null) { if (client == null) {
return null; return null;
} }
return await client.run(snippet.script).string; return await client.run(snippets.map((e) => e.script).join('&&')).string;
} }
} }

View File

@@ -18,17 +18,19 @@ class SnippetProvider extends BusyProvider {
void loadData() { void loadData() {
_snippets = _store.fetch(); _snippets = _store.fetch();
_updateTags();
} }
void _updateTags() { void _updateTags() {
_tags.clear(); _tags.clear();
final tags = <String>{};
for (final s in _snippets) { for (final s in _snippets) {
if (s.tags?.isEmpty ?? true) { if (s.tags?.isEmpty ?? true) {
continue; continue;
} }
_tags.addAll(s.tags!); tags.addAll(s.tags!);
} }
_tags.toSet().toList(); _tags.addAll(tags);
} }
void add(Snippet snippet) { void add(Snippet snippet) {

View File

@@ -2,8 +2,8 @@
class BuildData { class BuildData {
static const String name = "ServerBox"; static const String name = "ServerBox";
static const int build = 369; static const int build = 372;
static const String engine = "3.10.3"; static const String engine = "3.10.5";
static const String buildAt = "2023-06-27 14:47:02.701644"; static const String buildAt = "2023-07-07 21:09:39.978447";
static const int modifications = 5; static const int modifications = 2;
} }

View File

@@ -147,6 +147,7 @@ class BackupPage extends StatelessWidget {
await showRoundDialog( await showRoundDialog(
context: context, context: context,
title: Text(s.restore),
child: Text(s.restoreSureWithDate(backup.date)), child: Text(s.restoreSureWithDate(backup.date)),
actions: [ actions: [
TextButton( TextButton(
@@ -170,6 +171,7 @@ class BackupPage extends StatelessWidget {
context.pop(); context.pop();
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(s.restore),
child: Text(s.restoreSuccess), child: Text(s.restoreSuccess),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -180,6 +180,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
if (_textController.text == '') { if (_textController.text == '') {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.fieldMustNotEmpty), child: Text(_s.fieldMustNotEmpty),
actions: [ actions: [
TextButton( TextButton(
@@ -286,6 +287,7 @@ class _DockerManagePageState extends State<DockerManagePage> {
onPressed: () async { onPressed: () async {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.sureDelete(e.repo)), child: Text(_s.sureDelete(e.repo)),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -89,6 +89,7 @@ class _PingPageState extends State<PingPage>
} catch (e) { } catch (e) {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.error),
child: Text(e.toString()), child: Text(e.toString()),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -88,6 +88,7 @@ class _PkgManagePageState extends State<PkgManagePage>
if (_textController.text == '') { if (_textController.text == '') {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.fieldMustNotEmpty), child: Text(_s.fieldMustNotEmpty),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -90,6 +90,7 @@ class _ProcessPageState extends State<ProcessPage> {
icon: const Icon(Icons.error), icon: const Icon(Icons.error),
onPressed: () => showRoundDialog( onPressed: () => showRoundDialog(
context: context, context: context,
title: Text(_s.error),
child: Text(_result.error!), child: Text(_result.error!),
), ),
)); ));

View File

@@ -15,7 +15,7 @@ import '../../../data/provider/server.dart';
import '../../../data/res/ui.dart'; import '../../../data/res/ui.dart';
import '../../../data/store/private_key.dart'; import '../../../data/store/private_key.dart';
import '../../../locator.dart'; import '../../../locator.dart';
import '../../widget/tag_editor.dart'; import '../../widget/tag/editor.dart';
import '../private_key/edit.dart'; import '../private_key/edit.dart';
class ServerEditPage extends StatefulWidget { class ServerEditPage extends StatefulWidget {
@@ -239,6 +239,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
if (!usePublicKey && _passwordController.text == '') { if (!usePublicKey && _passwordController.text == '') {
final cancel = await showRoundDialog<bool>( final cancel = await showRoundDialog<bool>(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.sureNoPwd), child: Text(_s.sureNoPwd),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -5,11 +5,13 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:nil/nil.dart'; import 'package:nil/nil.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/core/extension/order.dart'; import 'package:toolbox/core/extension/order.dart';
import 'package:toolbox/core/utils/misc.dart'; import 'package:toolbox/core/utils/misc.dart';
import 'package:toolbox/data/model/server/snippet.dart';
import 'package:toolbox/data/provider/snippet.dart';
import 'package:toolbox/view/page/process.dart'; import 'package:toolbox/view/page/process.dart';
import 'package:toolbox/view/widget/tag_switcher.dart'; import 'package:toolbox/view/widget/tag/picker.dart';
import 'package:toolbox/view/widget/tag/switcher.dart';
import '../../../core/route.dart'; import '../../../core/route.dart';
import '../../../core/utils/ui.dart'; import '../../../core/utils/ui.dart';
@@ -273,7 +275,7 @@ class _ServerPageState extends State<ServerPage>
Widget _buildMoreBtn(ServerPrivateInfo spi) { Widget _buildMoreBtn(ServerPrivateInfo spi) {
return PopupMenu( return PopupMenu(
items: ServerTabMenuType.values.map((e) => e.build(_s)).toList(), items: ServerTabMenuType.values.map((e) => e.build(_s)).toList(),
onSelected: (ServerTabMenuType value) { onSelected: (ServerTabMenuType value) async {
switch (value) { switch (value) {
case ServerTabMenuType.pkg: case ServerTabMenuType.pkg:
AppRoute(PkgManagePage(spi), 'pkg manage').go(context); AppRoute(PkgManagePage(spi), 'pkg manage').go(context);
@@ -282,19 +284,33 @@ class _ServerPageState extends State<ServerPage>
AppRoute(SFTPPage(spi), 'SFTP').go(context); AppRoute(SFTPPage(spi), 'SFTP').go(context);
break; break;
case ServerTabMenuType.snippet: case ServerTabMenuType.snippet:
showSnippetDialog(context, _s, (s) async { final provider = locator<SnippetProvider>();
final result = await _serverProvider.runSnippet(spi.id, s); final snippets = await showDialog<List<Snippet>>(
context: context,
builder: (_) => TagPicker<Snippet>(
items: provider.snippets,
containsTag: (t, tag) => t.tags?.contains(tag) ?? false,
tags: provider.tags.toSet(),
name: (t) => t.name,
),
);
if (snippets == null) {
return;
}
final result = await _serverProvider.runSnippets(spi.id, snippets);
if (result != null && result.isNotEmpty) {
showRoundDialog( showRoundDialog(
context: context, context: context,
child: Text(result ?? _s.error, style: textSize13), title: Text(_s.result),
child: Text(result),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => context.pop(), onPressed: () => copy2Clipboard(result),
child: Text(_s.ok), child: Text(_s.copy),
) )
], ],
); );
}); }
break; break;
case ServerTabMenuType.edit: case ServerTabMenuType.edit:
AppRoute(ServerEditPage(spi: spi), 'Edit server info').go(context); AppRoute(ServerEditPage(spi: spi), 'Edit server info').go(context);
@@ -303,13 +319,6 @@ class _ServerPageState extends State<ServerPage>
AppRoute(DockerManagePage(spi), 'Docker manage').go(context); AppRoute(DockerManagePage(spi), 'Docker manage').go(context);
break; break;
case ServerTabMenuType.process: case ServerTabMenuType.process:
// AppRoute(
// SSHPage(
// spi: spi,
// initCmd: 'sh $shellPath -${shellFuncProcess.flag}',
// ),
// 'ssh page (process)',
// ).go(context);
AppRoute(ProcessPage(spi: spi), 'process page').go(context); AppRoute(ProcessPage(spi: spi), 'process page').go(context);
break; break;
} }

View File

@@ -272,6 +272,9 @@ class _SettingPageState extends State<SettingPage> {
await showRoundDialog( await showRoundDialog(
context: context, context: context,
title: Text(_s.primaryColor), title: Text(_s.primaryColor),
child: SizedBox(
height: 211,
child: Center(
child: MaterialColorPicker( child: MaterialColorPicker(
shrinkWrap: true, shrinkWrap: true,
allowShades: true, allowShades: true,
@@ -280,6 +283,8 @@ class _SettingPageState extends State<SettingPage> {
}, },
selectedColor: primaryColor, selectedColor: primaryColor,
), ),
),
),
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () {
@@ -557,7 +562,11 @@ class _SettingPageState extends State<SettingPage> {
context.pop(); context.pop();
final fontSize = double.tryParse(ctrller.text); final fontSize = double.tryParse(ctrller.text);
if (fontSize == null) { if (fontSize == null) {
showRoundDialog(context: context, child: Text(_s.failed)); showRoundDialog(
context: context,
title: Text(_s.failed),
child: Text('Parsed failed: ${ctrller.text}'),
);
return; return;
} }
_fontSize.value = fontSize; _fontSize.value = fontSize;

View File

@@ -178,6 +178,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
if (stat.size > editorMaxSize) { if (stat.size > editorMaxSize) {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.fileTooLarge(fileName, stat.size, '1m')), child: Text(_s.fileTooLarge(fileName, stat.size, '1m')),
); );
return; return;
@@ -223,6 +224,7 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
context.pop(); context.pop();
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.delete),
child: Text(_s.sureDelete(fileName)), child: Text(_s.sureDelete(fileName)),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -134,6 +134,7 @@ class _SFTPPageState extends State<SFTPPage> {
onPressed: () async { onPressed: () async {
final idx = await showRoundDialog( final idx = await showRoundDialog(
context: context, context: context,
title: Text(_s.choose),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@@ -517,6 +518,7 @@ class _SFTPPageState extends State<SFTPPage> {
if (textController.text == '') { if (textController.text == '') {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.fieldMustNotEmpty), child: Text(_s.fieldMustNotEmpty),
actions: [ actions: [
TextButton( TextButton(
@@ -559,6 +561,7 @@ class _SFTPPageState extends State<SFTPPage> {
if (textController.text == '') { if (textController.text == '') {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.fieldMustNotEmpty), child: Text(_s.fieldMustNotEmpty),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -9,7 +9,7 @@ import '../../../data/model/server/snippet.dart';
import '../../../data/provider/snippet.dart'; import '../../../data/provider/snippet.dart';
import '../../../data/res/ui.dart'; import '../../../data/res/ui.dart';
import '../../../locator.dart'; import '../../../locator.dart';
import '../../widget/tag_editor.dart'; import '../../widget/tag/editor.dart';
class SnippetEditPage extends StatefulWidget { class SnippetEditPage extends StatefulWidget {
const SnippetEditPage({Key? key, this.snippet}) : super(key: key); const SnippetEditPage({Key? key, this.snippet}) : super(key: key);

View File

@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/order.dart'; import 'package:toolbox/core/extension/order.dart';
import 'package:toolbox/view/widget/tag_switcher.dart'; import 'package:toolbox/view/widget/tag/switcher.dart';
import '../../../data/store/setting.dart'; import '../../../data/store/setting.dart';
import '../../../locator.dart'; import '../../../locator.dart';

View File

@@ -259,6 +259,7 @@ class _SSHPageState extends State<SSHPage> {
if (initPath.isEmpty || !initPath.startsWith('/')) { if (initPath.isEmpty || !initPath.startsWith('/')) {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.error),
child: const Text('Failed to get current path'), child: const Text('Failed to get current path'),
); );
return; return;

View File

@@ -0,0 +1,42 @@
import 'package:flutter/material.dart';
import '../../../data/res/color.dart';
class TagBtn extends StatelessWidget {
final String content;
final void Function() onTap;
final bool isEnable;
const TagBtn({
super.key,
required this.onTap,
required this.isEnable,
required this.content,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 4, right: 5, bottom: 9),
child: GestureDetector(
onTap: onTap,
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(
content,
style: TextStyle(
color: isEnable ? null : Colors.grey,
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
)),
),
);
}
}

View File

@@ -4,8 +4,8 @@ import 'package:toolbox/view/widget/input_field.dart';
import 'package:toolbox/view/widget/round_rect_card.dart'; import 'package:toolbox/view/widget/round_rect_card.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../core/utils/ui.dart'; import '../../../core/utils/ui.dart';
import '../../data/res/color.dart'; import '../../../data/res/color.dart';
class TagEditor extends StatelessWidget { class TagEditor extends StatelessWidget {
final List<String> tags; final List<String> tags;

View File

@@ -0,0 +1,125 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/data/res/ui.dart';
import 'package:toolbox/view/widget/tag/btn.dart';
class TagPicker<T> extends StatefulWidget {
final List<T> items;
final bool Function(T, String?) containsTag;
final String Function(T) name;
final Set<String> tags;
const TagPicker({
Key? key,
required this.items,
required this.containsTag,
required this.name,
required this.tags,
}) : super(key: key);
@override
_TagPickerState<T> createState() => _TagPickerState<T>();
}
class _TagPickerState<T> extends State<TagPicker<T>> {
late S _s;
late MediaQueryData _media;
final List<T> _selected = [];
@override
void didChangeDependencies() {
super.didChangeDependencies();
_s = S.of(context)!;
_media = MediaQuery.of(context);
}
@override
Widget build(BuildContext context) {
final child = widget.tags.isEmpty
? Text(_s.noSavedSnippet)
: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(_s.tag),
height13,
SizedBox(
height: 37,
width: _media.size.width * 0.7,
child: _buildTags(),
),
Text(_s.all),
height13,
SizedBox(
height: 37,
width: _media.size.width * 0.7,
child: _buildItems(),
),
],
);
return AlertDialog(
title: Text(_s.choose),
content: child,
actions: [
TextButton(
onPressed: () {
context.pop(_selected);
},
child: Text(_s.ok),
),
],
);
}
Widget _buildTags() {
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: widget.tags.length,
itemBuilder: (_, idx) {
final item = widget.tags.elementAt(idx);
final isEnable =
widget.items.where((ele) => widget.containsTag(ele, item)).every(
(element) => _selected.contains(element),
);
return TagBtn(
isEnable: isEnable,
onTap: () {
if (isEnable) {
_selected.removeWhere(
(element) => widget.containsTag(element, item),
);
} else {
_selected.addAll(widget.items.where(
(ele) => widget.containsTag(ele, item),
));
}
setState(() {});
},
content: item,
);
},
);
}
Widget _buildItems() {
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: widget.items.length,
itemBuilder: (context, index) {
final e = widget.items[index];
return TagBtn(
isEnable: _selected.contains(e),
onTap: () {
if (_selected.contains(e)) {
_selected.remove(e);
} else {
_selected.add(e);
}
setState(() {});
},
content: widget.name(e),
);
},
);
}
}

View File

@@ -0,0 +1,49 @@
import 'package:flutter/material.dart';
import 'package:nil/nil.dart';
import 'package:toolbox/view/widget/tag/view.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) {
final item = items[index];
return TagView(
tag: item,
initTag: initTag,
all: all,
onTap: onTagChanged,
);
},
itemCount: items.length,
),
);
}
}

View File

@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:toolbox/view/widget/tag/btn.dart';
class TagView extends StatelessWidget {
final void Function(String?) onTap;
final String? tag;
final String? initTag;
final String all;
const TagView({
super.key,
required this.onTap,
this.tag,
this.initTag,
required this.all,
});
@override
Widget build(BuildContext context) {
return TagBtn(
onTap: () => onTap(tag),
isEnable: initTag == tag,
content: tag == null ? all : '#$tag',
);
}
}

View File

@@ -1,67 +0,0 @@
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,
),
),
)),
),
);
}
}

View File

@@ -475,9 +475,9 @@
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */; baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 369; CURRENT_PROJECT_VERSION = 372;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.369; MARKETING_VERSION = 1.0.372;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@@ -490,9 +490,9 @@
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */; baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 369; CURRENT_PROJECT_VERSION = 372;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.369; MARKETING_VERSION = 1.0.372;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@@ -505,9 +505,9 @@
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */; baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
buildSettings = { buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CURRENT_PROJECT_VERSION = 369; CURRENT_PROJECT_VERSION = 372;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0.369; MARKETING_VERSION = 1.0.372;
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests; PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;