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



我使用的是Flutter的material_tag_editor包,它使用逗号作为默认分隔符。

我还试图让用户使用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);
});
},

相关内容

  • 没有找到相关文章

最新更新