TreemapColorMapper.value constructor

const TreemapColorMapper.value({
  1. required String? value,
  2. required Color color,
})

Applies the color to the tiles which is equal to the given TreemapColorMapper.value. The TreemapColorMapper.value must not be null.

Applies this TreemapColorMapper.color value to the tiles which are in the given TreemapColorMapper.value. The legend item color and text are based on the TreemapColorMapper.color and TreemapColorMapper.value.

late List<SocialMediaUsers> _socialMediaUsersData;
late List<TreemapColorMapper> _colorMappers;

  @override
  void initState() {
    _socialMediaUsersData = <SocialMediaUsers>[
      SocialMediaUsers('India', 'Facebook', 280),
      SocialMediaUsers('India', 'Instagram', 88),
      SocialMediaUsers('USA', 'Facebook', 190),
      SocialMediaUsers('USA', 'Instagram', 120),
      SocialMediaUsers('Japan', 'Twitter', 48),
      SocialMediaUsers('Japan', 'Instagram', 31),
    ];
    _colorMappers = <TreemapColorMapper>[
      TreemapColorMapper.value(value: 'India', color: Colors.green),
      TreemapColorMapper.value(value: 'USA', color: Colors.blue),
      TreemapColorMapper.value(value: 'Japan', color: Colors.red),
    ];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SfTreemap(
        dataCount: _socialMediaUsersData.length,
        weightValueMapper: (int index) {
          return _socialMediaUsersData[index].usersInMillions;
        },
        colorMappers: _colorMappers,
        levels: [
          TreemapLevel(
              groupMapper: (int index) {
                return _socialMediaUsersData[index].country;
              },
              colorValueMapper: (TreemapTile tile) => tile.group,
          ),
        ],
      ),
    );
  }

class SocialMediaUsers {
  const SocialMediaUsers(
    this.country,
    this.socialMedia,
    this.usersInMillions,
  );
  final String country;
  final String socialMedia;
  final double usersInMillions;
}

See also:

Implementation

const TreemapColorMapper.value({required this.value, required this.color})
    : from = null,
      to = null,
      minSaturation = null,
      maxSaturation = null,
      name = null;