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

How to use 'Enter' as a delimiter in Flutter's material_tag_editor

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

我也试图让用户使用 enter (unicode = 2386) 或 return 作为分隔符,但似乎没有任何效果。我试过 '\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);
          });
        },