我正在尝试在颤振中实现相同的布局我该如何实现它,我已经尝试使用 wrap 小部件但是 Textfield 获得全宽并根据内容动态更改文本字段宽度是不可能的
问问题
855 次
1 回答
0
我不知道这是否为时已晚。但是这个库正是你所需要的。你有网站上的所有步骤。
这是一个名为 Flutter Chips 的库。有步骤,我也会把图书馆的链接放上去。
https://pub.dev/packages/flutter_chips_input
首先安装库:
dependencies:
flutter_chips_input: ^1.9.4
这是代码部分:
ChipsInput(
initialValue: [
AppProfile('John Doe', 'jdoe@flutter.io', 'https://d2gg9evh47fn9z.cloudfront.net/800px_COLOURBOX4057996.jpg')
],
decoration: InputDecoration(
labelText: "Select People",
),
maxChips: 3,
findSuggestions: (String query) {
if (query.length != 0) {
var lowercaseQuery = query.toLowerCase();
return mockResults.where((profile) {
return profile.name.toLowerCase().contains(query.toLowerCase()) || profile.email.toLowerCase().contains(query.toLowerCase());
}).toList(growable: false)
..sort((a, b) => a.name
.toLowerCase()
.indexOf(lowercaseQuery)
.compareTo(b.name.toLowerCase().indexOf(lowercaseQuery)));
} else {
return const <AppProfile>[];
}
},
onChanged: (data) {
print(data);
},
chipBuilder: (context, state, profile) {
return InputChip(
key: ObjectKey(profile),
label: Text(profile.name),
avatar: CircleAvatar(
backgroundImage: NetworkImage(profile.imageUrl),
),
onDeleted: () => state.deleteChip(profile),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
},
suggestionBuilder: (context, state, profile) {
return ListTile(
key: ObjectKey(profile),
leading: CircleAvatar(
backgroundImage: NetworkImage(profile.imageUrl),
),
title: Text(profile.name),
subtitle: Text(profile.email),
onTap: () => state.selectSuggestion(profile),
);
},
)
于 2020-11-06T08:35:30.230 回答