TreemapColorMapper.value constructor Null safety

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;

  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:,
      TreemapColorMapper.value(value: 'USA', color:,
      TreemapColorMapper.value(value: 'Japan', color:,

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

class SocialMediaUsers {
  const SocialMediaUsers(,
  final String country;
  final String socialMedia;
  final double usersInMillions;

See also:


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