Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust the size of a chip in flutter

Tags:

flutter

dart

I want to display a large number of chips in my view with text inside it. Since the count is big I want to decrease the size of the chip to the minimum. Specifically the height of the chip. How can this be done?

for (EPDiaryTarget target in widget.item.targetList) {
    Chip chip = new Chip(
      label: new Text(
        target.name,
        overflow: TextOverflow.ellipsis,
        style: new TextStyle(color: Colors.white),
      ),
      backgroundColor: const Color(0xFFa3bdc4),
    );
    studentsChips.add(chip);
  }

I've given padding: new EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0), for the chip but its default size is not reduced. Can a custom shape with required size be given to a chip? If so, How can it be done? Thanks in advance folks.

like image 582
Febin K R Avatar asked Jul 20 '18 10:07

Febin K R


People also ask

How do you change the chip shape in flutter?

You can use shape property of the Chip widget. In that property you can pass RoundedRectangleBorder() and mention borderRadius inside of the RoundedRectangleBorder(). There are other ShapeBorders like BeveledRectangleBorder(), StadiumBorder(),OutlineInputBorder(),ContinuousRectangleBorder() and so on.

How do you pick chips in flutter?

To create a choice chip in flutter we have to use the constructor of ChoieChip class provided by flutter. There are two required property for ChoiceChip widget which are label and selected.

How can I build a chip input field in flutter?

Creating InputChip The constructor of InputChip only requires you to at least pass a Widget as label property. However, as you can see on the above result, the chip is disabled. To make it enabled, you need to pass onPressed callback (and not setting isEnabled to false ).


4 Answers

You can wrap the chip in a Transform widget and scale it as follows:

    Transform(
      transform: new Matrix4.identity()..scale(0.8),
      child: new Chip(
        label: new Text(
          "Chip",
          overflow: TextOverflow.ellipsis,
          style: new TextStyle(color: Colors.white),
        ),
        backgroundColor: const Color(0xFFa3bdc4),
      ),
    ),
like image 146
chemamolins Avatar answered Sep 28 '22 05:09

chemamolins


Wrap label: Text('chip') in Container or SizedBox.

Chip(
    label: Container(
        width: 100,
        height: 40,
        child: Text('chip'),
    ),
)
like image 34
Alex.Marynovskyi Avatar answered Sep 28 '22 05:09

Alex.Marynovskyi


You need to set materialTapTargetSize. Default value is MaterialTapTargetSize.padded, which sets minHeight of 48px for the chip. Set it to MaterialTapTargetSize.shrinkWrap to remove the extra space.

Chip( ..., materialTapTargetSize: MaterialTapTargetSize.shrinkWrap )

like image 29
Awanish Raj Avatar answered Sep 28 '22 04:09

Awanish Raj


Now you can use VisualDensity (https://api.flutter.dev/flutter/material/VisualDensity-class.html) which is a double that can be between -4 and 4 ([VisualDensity.minimumDensity], [VisualDensity.maximumDensity])

like image 11
Arnaud Delubac Avatar answered Sep 28 '22 06:09

Arnaud Delubac