我该如何在颤抖中实现这一目标?

时间:2018-09-19 06:10:34

标签: dart flutter flutter-layout flutter-animation

我正在尝试在flutter中实现相同的布局,我该如何实现它,我已经尝试过使用wrap小部件,但是Textfield无法获得全宽并根据内容动态更改textfield宽度

1 个答案:

答案 0 :(得分: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),
    );
},
)