![](/img/trans.png)
[英]How to add user-submitted tags data from “material_tag_editor” into a “Flutter Form Builder” form?
[英]How to use 'Enter' as a delimiter in Flutter's material_tag_editor
我正在使用 Flutter 的material_tag_editor 包,它使用逗號作為默認分隔符。
我還試圖讓用戶使用 enter (unicode = 2386) 或作為分隔符返回,但似乎沒有任何效果。 我試過'\⎆'
和'\\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);
});
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.