segmentSize property
Customizes the size of the bar segments.
Defaults to Size(80.0, 12.0).
late List<SocialMediaUsers> _source;
late List<TreemapColorMapper> _colorMappers;
@override
void initState() {
_source = <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.range(
from: 0, to: 10, color: Colors.red, name: '10'),
TreemapColorMapper.range(
from: 11, to: 20, color: Colors.green, name: '20'),
TreemapColorMapper.range(
from: 21, to: 30, color: Colors.blue, name: '30'),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SfTreemap(
dataCount: _source.length,
weightValueMapper: (int index) {
return _source[index].usersInMillions;
},
levels: [
TreemapLevel(
groupMapper: (int index) {
return _source[index].country;
},
),
],
colorMappers: _colorMappers,
legend: TreemapLegend.bar(
segmentSize: Size(60, 18),
),
),
);
}
class SocialMediaUsers {
const SocialMediaUsers(
this.country,
this.socialMedia,
this.usersInMillions,
);
final String country;
final String socialMedia;
final double usersInMillions;
}
Implementation
final Size? segmentSize;