opt. for tag

This commit is contained in:
lollipopkit
2023-05-31 17:19:56 +08:00
parent 472a441c8e
commit d24fe5ff5d
3 changed files with 61 additions and 48 deletions

View File

@@ -73,6 +73,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
onPressed: () { onPressed: () {
showRoundDialog( showRoundDialog(
context: context, context: context,
title: Text(_s.attention),
child: Text(_s.sureToDeleteServer(widget.spi!.name)), child: Text(_s.sureToDeleteServer(widget.spi!.name)),
actions: [ actions: [
TextButton( TextButton(
@@ -151,6 +152,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
_tags = p0; _tags = p0;
}), }),
s: _s, s: _s,
tagSuggestions: [..._serverProvider.tags],
), ),
width7, width7,
Row( Row(

View File

@@ -96,6 +96,8 @@ class _SSHPageState extends State<SSHPage> {
} }
Widget _buildBody() { Widget _buildBody() {
final keyboardType =
isIOS ? TextInputType.emailAddress : TextInputType.visiblePassword;
return SizedBox( return SizedBox(
height: _media.size.height - height: _media.size.height -
_virtualKeyboardHeight - _virtualKeyboardHeight -
@@ -104,6 +106,7 @@ class _SSHPageState extends State<SSHPage> {
child: TerminalView( child: TerminalView(
_terminal, _terminal,
controller: _terminalController, controller: _terminalController,
keyboardType: keyboardType,
textStyle: _terminalStyle, textStyle: _terminalStyle,
theme: _terminalTheme, theme: _terminalTheme,
deleteDetection: isIOS, deleteDetection: isIOS,

View File

@@ -10,22 +10,23 @@ class TagEditor extends StatelessWidget {
final List<String> tags; final List<String> tags;
final S s; final S s;
final void Function(List<String>)? onChanged; final void Function(List<String>)? onChanged;
final void Function(String)? onTapTag;
final List<String>? tagSuggestions;
const TagEditor({ const TagEditor({
super.key, super.key,
required this.tags, required this.tags,
this.onChanged,
required this.s, required this.s,
this.onChanged,
this.onTapTag,
this.tagSuggestions,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RoundRectCard(ListTile( return RoundRectCard(ListTile(
leading: const Icon(Icons.tag), leading: const Icon(Icons.tag),
title: _buildTags( title: _buildTags(tags),
tags,
_onTapDelete,
),
trailing: InkWell( trailing: InkWell(
child: const Icon(Icons.add), child: const Icon(Icons.add),
onTap: () { onTap: () {
@@ -35,29 +36,30 @@ class TagEditor extends StatelessWidget {
)); ));
} }
void _onTapDelete(String tag) { Widget _buildTags(List<String> tags) {
tags.remove(tag); tagSuggestions?.removeWhere((element) => tags.contains(element));
onChanged?.call(tags); final suggestionLen = tagSuggestions?.length ?? 0;
} final counts = tags.length + suggestionLen + (suggestionLen == 0 ? 0 : 1);
if (counts == 0) return Text(s.tag);
Widget _buildTags( return ConstrainedBox(constraints: BoxConstraints(maxHeight: 27), child: ListView.builder(
List<String> tags,
Function(String) onTagDelete,
) {
if (tags.isEmpty) return Text(s.tag);
return SingleChildScrollView(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
child: Row( itemBuilder: (context, index) {
mainAxisAlignment: MainAxisAlignment.end, if (index < tags.length) {
crossAxisAlignment: CrossAxisAlignment.center, return _buildTagItem(tags[index], false);
children: tags.map((e) => _buildTagItem(e, onTagDelete)).toList(), } else if (index > tags.length) {
), return _buildTagItem(tagSuggestions![index - tags.length - 1], true);
); }
return const VerticalDivider();
},
itemCount: counts,
),);
} }
Widget _buildTagItem(String tag, Function(String) onTagDelete) { Widget _buildTagItem(String tag, bool isAdd) {
return Padding( return Padding(
padding: const EdgeInsets.only(right: 7), padding: const EdgeInsets.symmetric(horizontal: 3),
child: GestureDetector(
onTap: () => onTapTag?.call(tag),
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(20.0)), borderRadius: const BorderRadius.all(Radius.circular(20.0)),
@@ -73,18 +75,24 @@ class TagEditor extends StatelessWidget {
), ),
const SizedBox(width: 4.0), const SizedBox(width: 4.0),
InkWell( InkWell(
child: const Icon( child: Icon(
Icons.cancel, isAdd ? Icons.add_circle : Icons.cancel,
size: 14.0, size: 14.0,
color: Colors.white, color: Colors.white,
), ),
onTap: () { onTap: () {
onTagDelete(tag); if (isAdd) {
tags.add(tag);
} else {
tags.remove(tag);
}
onChanged?.call(tags);
}, },
) )
], ],
), ),
), ),
),
); );
} }