Flutter中标签的替代品

4zcjmb1e  于 2023-04-13  发布在  Flutter
关注(0)|答案(1)|浏览(126)

这是一个应用程序的旧版本。我在该应用程序中使用了标签部件。但现在标签不支持空安全和过时。你能建议我替代和使用替代包编写相同的功能代码吗?

import 'package:flutter_tags/flutter_tags.dart';

List<Items> _newArrivalsItems = [];
  List<Items> _selectedNewArrivalsItems = [];
  List<String> _selectedNewArrivalsItemCodes = [];

Widget _buildFilter() {
    List<String> added = [];

    return Container(
      child: Tags(
        runSpacing: 5,
        spacing: 5,
        itemCount: _newArrivalsItems.length,
        itemBuilder: (index) {
          final obj = _newArrivalsItems[index];
          if (added.contains(obj.iGRPCODE)) {
            return Container();
          }
          added.add(obj.iGRPCODE);
          return ItemTags(
            index: index,
            title: obj.iGRPDESC,

            active: true,
            removeButton: ItemTagsRemoveButton(
              onRemoved: () {
                // Remove the item from the data source.
                setState(() {
                  // required
                  _selectedNewArrivalsItemCodes.remove(obj.iGRPCODE);
                  setState(() {});
                });
                //required
                return true;
              },
            ), // OR null,
            onPressed: (item) {
              final value = _selectedNewArrivalsItemCodes.remove(obj.iGRPCODE);
              if (!value) _selectedNewArrivalsItemCodes.add(obj.iGRPCODE);
              setState(() {});
            },
            onLongPressed: (item) => print(item),
          );
        },
      ),
    );
  }
hm2xizp9

hm2xizp91#

有一个预发布版本具有null安全性

dependencies:
  flutter_tags: "^1.0.0-nullsafety.1"

如果您对此不感兴趣,可以使用Chip小部件自己创建自定义标记
More here

相关问题