Viktor Sinelnikov
Viktor Sinelnikov

Reputation: 1631

Analog for TagView in flutter

I want to have UI like this: enter image description here With native Android it can be done with libraries like https://github.com/whilu/AndroidTagView, how can it be done with flutter?

Upvotes: 1

Views: 2264

Answers (2)

Raouf Rahiche
Raouf Rahiche

Reputation: 31356

you can make the same UI by combining the Wrap and Chip widget as @wasyl montioned . but this is a full example about what you need

Notes :

  • you can adjust the space between the chips inside the Wrap widget using spacing
  • the deleteIcon is only in the right but you can use the avatar to show an icon in the left
  • you can set the Chip Border Color and width using the Shape property

enter image description here

 new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new Wrap(
            children: <Widget>[
              Chip(
                label: new Text("Java"),
                onDeleted: () {},
                labelPadding: EdgeInsets.all(2.0),
                deleteIcon: Icon(Icons.clear),
              ),
              Chip(
                label: new Text("C++"),
                onDeleted: () {},
                labelPadding: EdgeInsets.all(2.0),
                deleteIcon: Icon(Icons.clear),
              ),
              Chip(
                label: new Text("Python"),
                onDeleted: () {},
                labelPadding: EdgeInsets.all(2.0),
                deleteIcon: Icon(Icons.clear),
              ),
            ],
          ),
          new SizedBox(
            height: 10.0,
          ),
          new Wrap(
            spacing: 5.0,
            children: <Widget>[
              Chip(
                label: new Text("China"),
                backgroundColor: Colors.pinkAccent,
              ),
              Chip(
                label: new Text("USA"),
                backgroundColor: Colors.greenAccent,
              ),
              Chip(
                label: new Text("Austria"),
                backgroundColor: Colors.purpleAccent,
              ),
            ],
          ),
          new SizedBox(
            height: 10.0,
          ),
          new Wrap(
            textDirection: TextDirection.rtl,
            spacing: 5.0,
            children: <Widget>[
              Chip(
                  label: new Text("نجربة"),
                  avatar: Icon(Icons.clear),
                  backgroundColor: Colors.transparent,
                  shape: new BeveledRectangleBorder(side: BorderSide(color: Colors.grey))),
              Chip(
                  label: new Text("كتابة"),
                  avatar: Icon(Icons.clear),
                  backgroundColor: Colors.transparent,
                  shape: new BeveledRectangleBorder(side: BorderSide(color: Colors.grey))),
              Chip(
                  label: new Text("مختلفة"),
                  avatar: Icon(Icons.clear),
                  backgroundColor: Colors.transparent,
                  shape: new BeveledRectangleBorder(side: BorderSide(color: Colors.grey))),
            ],
          ),
        ],
      ),

Upvotes: 5

wasyl
wasyl

Reputation: 3506

You will want to use:

  • a Wrap widget to have your chips (tags) be positioned one by one, overflowing to the next row
  • a Chip widget for a material-design chip with text, optional delete button, delete callback etc.

Seems like the border width can't be easily set for a Chip, though, but the overall functionality is readily available

Upvotes: 2

Related Questions