avatarBoxConstraints property

  1. @override
BoxConstraints? avatarBoxConstraints
final

Optional size constraints for the avatar.

When unspecified, defaults to a minimum size of chip height or label height (whichever is greater) and a padding of 8.0 pixels on all sides.

The default constraints ensure that the avatar is accessible. Specifying this parameter enables creation of avatar smaller than the minimum size, but it is not recommended.

This sample shows how to use avatarBoxConstraints to adjust avatar size constraints

To see it in action, copy and run this code snippet on DartPad.

import 'package:material_ui/material_ui.dart';

/// Flutter code sample for [ChipAttributes.avatarBoxConstraints].

void main() => runApp(const AvatarBoxConstraintsApp());

class AvatarBoxConstraintsApp extends StatelessWidget {
  const AvatarBoxConstraintsApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(body: Center(child: AvatarBoxConstraintsExample())),
    );
  }
}

class AvatarBoxConstraintsExample extends StatelessWidget {
  const AvatarBoxConstraintsExample({super.key});

  @override
  Widget build(BuildContext context) {
    return const Column(
      mainAxisAlignment: .center,
      children: <Widget>[
        RawChip(
          avatarBoxConstraints: BoxConstraints.tightForFinite(),
          avatar: Icon(Icons.star),
          label: SizedBox(
            width: 150,
            child: Text('One line text.', maxLines: 3, overflow: .ellipsis),
          ),
        ),
        SizedBox(height: 10),
        RawChip(
          avatarBoxConstraints: BoxConstraints.tightForFinite(),
          avatar: Icon(Icons.star),
          label: SizedBox(
            width: 150,
            child: Text(
              'This text will wrap into two lines.',
              maxLines: 3,
              overflow: .ellipsis,
            ),
          ),
        ),
        SizedBox(height: 10),
        RawChip(
          avatarBoxConstraints: BoxConstraints.tightForFinite(),
          avatar: Icon(Icons.star),
          label: SizedBox(
            width: 150,
            child: Text(
              'This is a very long text that will wrap into three lines.',
              maxLines: 3,
              overflow: .ellipsis,
            ),
          ),
        ),
      ],
    );
  }
}

Implementation

@override
final BoxConstraints? avatarBoxConstraints;