From d24fe5ff5d36b8418fc5f13536d676d195048a1b Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Wed, 31 May 2023 17:19:56 +0800 Subject: [PATCH] opt. for `tag` --- lib/view/page/server/edit.dart | 2 + lib/view/page/ssh.dart | 3 + lib/view/widget/tag.dart | 104 ++++++++++++++++++--------------- 3 files changed, 61 insertions(+), 48 deletions(-) diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index e2159621..497720f2 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -73,6 +73,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { onPressed: () { showRoundDialog( context: context, + title: Text(_s.attention), child: Text(_s.sureToDeleteServer(widget.spi!.name)), actions: [ TextButton( @@ -151,6 +152,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { _tags = p0; }), s: _s, + tagSuggestions: [..._serverProvider.tags], ), width7, Row( diff --git a/lib/view/page/ssh.dart b/lib/view/page/ssh.dart index 842d54f4..6263ac40 100644 --- a/lib/view/page/ssh.dart +++ b/lib/view/page/ssh.dart @@ -96,6 +96,8 @@ class _SSHPageState extends State { } Widget _buildBody() { + final keyboardType = + isIOS ? TextInputType.emailAddress : TextInputType.visiblePassword; return SizedBox( height: _media.size.height - _virtualKeyboardHeight - @@ -104,6 +106,7 @@ class _SSHPageState extends State { child: TerminalView( _terminal, controller: _terminalController, + keyboardType: keyboardType, textStyle: _terminalStyle, theme: _terminalTheme, deleteDetection: isIOS, diff --git a/lib/view/widget/tag.dart b/lib/view/widget/tag.dart index 8fd40d3e..0546e921 100644 --- a/lib/view/widget/tag.dart +++ b/lib/view/widget/tag.dart @@ -10,22 +10,23 @@ class TagEditor extends StatelessWidget { final List tags; final S s; final void Function(List)? onChanged; + final void Function(String)? onTapTag; + final List? tagSuggestions; const TagEditor({ super.key, required this.tags, - this.onChanged, required this.s, + this.onChanged, + this.onTapTag, + this.tagSuggestions, }); @override Widget build(BuildContext context) { return RoundRectCard(ListTile( leading: const Icon(Icons.tag), - title: _buildTags( - tags, - _onTapDelete, - ), + title: _buildTags(tags), trailing: InkWell( child: const Icon(Icons.add), onTap: () { @@ -35,54 +36,61 @@ class TagEditor extends StatelessWidget { )); } - void _onTapDelete(String tag) { - tags.remove(tag); - onChanged?.call(tags); - } - - Widget _buildTags( - List tags, - Function(String) onTagDelete, - ) { - if (tags.isEmpty) return Text(s.tag); - return SingleChildScrollView( + Widget _buildTags(List tags) { + tagSuggestions?.removeWhere((element) => tags.contains(element)); + final suggestionLen = tagSuggestions?.length ?? 0; + final counts = tags.length + suggestionLen + (suggestionLen == 0 ? 0 : 1); + if (counts == 0) return Text(s.tag); + return ConstrainedBox(constraints: BoxConstraints(maxHeight: 27), child: ListView.builder( scrollDirection: Axis.horizontal, - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.center, - children: tags.map((e) => _buildTagItem(e, onTagDelete)).toList(), - ), - ); + itemBuilder: (context, index) { + if (index < tags.length) { + return _buildTagItem(tags[index], false); + } 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( - padding: const EdgeInsets.only(right: 7), - child: Container( - decoration: BoxDecoration( - borderRadius: const BorderRadius.all(Radius.circular(20.0)), - color: primaryColor, - ), - padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 3), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - '#$tag', - style: const TextStyle(color: Colors.white), - ), - const SizedBox(width: 4.0), - InkWell( - child: const Icon( - Icons.cancel, - size: 14.0, - color: Colors.white, + padding: const EdgeInsets.symmetric(horizontal: 3), + child: GestureDetector( + onTap: () => onTapTag?.call(tag), + child: Container( + decoration: BoxDecoration( + borderRadius: const BorderRadius.all(Radius.circular(20.0)), + color: primaryColor, + ), + padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 3), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '#$tag', + style: const TextStyle(color: Colors.white), ), - onTap: () { - onTagDelete(tag); - }, - ) - ], + const SizedBox(width: 4.0), + InkWell( + child: Icon( + isAdd ? Icons.add_circle : Icons.cancel, + size: 14.0, + color: Colors.white, + ), + onTap: () { + if (isAdd) { + tags.add(tag); + } else { + tags.remove(tag); + } + onChanged?.call(tags); + }, + ) + ], + ), ), ), );