微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Flutter 的 material_tag_editor 中使用“Enter”作为分隔符

如何解决如何在 Flutter 的 material_tag_editor 中使用“Enter”作为分隔符

我正在使用 Flutter 的 material_tag_editor package,它使用逗号作为认分隔符。

我还试图让用户使用 enter (unicode = 2386) 或作为分隔符返回,但似乎没有任何效果。我试过 '\u2386''\u{2386}'

这是我的代码

Padding(
  padding: const EdgeInsets.only(top: 16.0),child: TagEditor(
    length: example.length,delimiters: [
      ',',' '
    ],//Also tried "return" ('\u2386',) and '\u{2386}'
    hasAddButton: true,//textInputAction: TextInputAction.next,// moves user from one field to the next!!!!
    autofocus: false,maxLines: 1,// focusedBorder: OutlineInputBorder(
    //   borderSide: BorderSide(color: Colors.lightBlue),//   borderRadius: BorderRadius.circular(20.0),// ),inputdecoration: const Inputdecoration(
      // below was "border: InputBorder.none,"
      isDense: true,border: OutlineInputBorder(
        borderRadius: const BorderRadius.all(
          const Radius.circular(20.0),),focusedBorder: OutlineInputBorder(
        borderSide: BorderSide(color: Colors.lightBlue),borderRadius: const BorderRadius.all(
          const Radius.circular(20.0),// above is per https://github.com/Flutter/Flutter/issues/5191
      ),labelText: 'separate,with,commas',labelStyle: TextStyle(
        fontStyle: FontStyle.italic,backgroundColor:
            Color(0x65dffd02),// was Color(0xffDDFDFC),color: Colors.black87,// was Color(0xffD82E6D),fontSize: 14,onTagChanged: (newValue) {
      setState(() {
        example.add(newValue);
      });
    },tagBuilder: (context,index) => _Chip(
      index: index,label: example[index],onDeleted: onDelete,

解决方法

该包提供了 onSubmit 方法和 resetTextOnSubmitted 属性,因此您可以使用它们来获得您想要的行为。这应该有效:

        resetTextOnSubmitted: true,onSubmitted: (value) {
          setState(() {
            example.add(value);
          });
        },

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。