### Pubspec.yaml Dependency Example Source: https://pub.dev/packages/syncfusion_flutter_treemap/install This is an example of how the syncfusion_flutter_treemap dependency will appear in your pubspec.yaml file after running the add command. ```yaml dependencies: syncfusion_flutter_treemap: ^33.2.10 ``` -------------------------------- ### Map Data Source for Flutter Treemap Source: https://pub.dev/packages/syncfusion_flutter_treemap Populate the treemap data source by setting the data count and defining group and weight mappers. This example demonstrates basic data source mapping for hierarchical treemaps. ```dart late List _source; @override void initState() { _source = [ SocialMediaUsers('India', 'Facebook', 25.4), SocialMediaUsers('USA', 'Instagram', 19.11), SocialMediaUsers('Japan', 'Facebook', 13.3), SocialMediaUsers('Germany', 'Instagram', 10.65), SocialMediaUsers('France', 'Twitter', 7.54), SocialMediaUsers('UK', 'Instagram', 4.93), ]; 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; }, ), ], ), ); } class SocialMediaUsers { const SocialMediaUsers(this.country, this.socialMedia, this.usersInMillions); final String country; final String socialMedia; final double usersInMillions; } ``` -------------------------------- ### Import Syncfusion Flutter Treemap in Dart Source: https://pub.dev/packages/syncfusion_flutter_treemap/install Import the treemap package into your Dart code to start using its widgets and functionalities. ```dart import 'package:syncfusion_flutter_treemap/treemap.dart'; ``` -------------------------------- ### Basic Treemap Implementation Source: https://pub.dev/packages/syncfusion_flutter_treemap/example This snippet shows a basic implementation of the SfTreemap widget in a Flutter application. It configures the treemap with data, defines grouping and labeling for treemap levels, and sets up tooltips for interactive data display. Ensure the SocialMediaUsers class and its data are properly defined. ```dart import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_treemap/treemap.dart'; void main() { return runApp(const TreemapApp()); } /// This widget will be the root of the application. class TreemapApp extends StatelessWidget { const TreemapApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp(title: 'Treemap Demo', home: MyHomePage()); } } /// This widget is the home page of the application. class MyHomePage extends StatefulWidget { /// Initialize the instance of the [MyHomePage] class. const MyHomePage({Key? key}) : super(key: key); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { late List _source; @override void initState() { _source = const [ SocialMediaUsers('India', 'Facebook', 25.4), SocialMediaUsers('USA', 'Instagram', 19.11), SocialMediaUsers('Japan', 'Facebook', 13.3), SocialMediaUsers('Germany', 'Instagram', 10.65), SocialMediaUsers('France', 'Twitter', 7.54), SocialMediaUsers('UK', 'Instagram', 4.93), ]; super.initState(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Treemap demo')), body: SfTreemap( dataCount: _source.length, weightValueMapper: (int index) { return _source[index].usersInMillions; }, levels: [ TreemapLevel( groupMapper: (int index) { return _source[index].country; }, labelBuilder: (BuildContext context, TreemapTile tile) { return Padding( padding: const EdgeInsets.all(2.5), child: Text( tile.group, style: const TextStyle(color: Colors.black), ), ); }, tooltipBuilder: (BuildContext context, TreemapTile tile) { return Padding( padding: const EdgeInsets.all(10), child: Text( '''Country : ${tile.group}\nSocial media : ${tile.weight}M''', style: const TextStyle(color: Colors.black), ), ); }, ), ], ), ); } } /// Represents the class for social media users. class SocialMediaUsers { /// Constructor of [SocialMediaUsers]. const SocialMediaUsers(this.country, this.socialMedia, this.usersInMillions); /// Specifies the country. final String country; /// Specifies the type of social media. final String socialMedia; /// Specifies the users count. final double usersInMillions; } ``` -------------------------------- ### Create a Basic Treemap Widget Source: https://pub.dev/packages/syncfusion_flutter_treemap Initialize the SfTreemap widget as a child of any widget within your Flutter application's widget tree. This is the fundamental step to display a treemap. ```dart @override Widget build(BuildContext context) { return Scaffold( body: Center( child: SfTreemap(), ), ); } ``` -------------------------------- ### Add Syncfusion Flutter Treemap Dependency Source: https://pub.dev/packages/syncfusion_flutter_treemap/install Run this command to add the treemap package to your Flutter project's dependencies. This command automatically updates your pubspec.yaml file. ```bash $ flutter pub add syncfusion_flutter_treemap ``` -------------------------------- ### Add Tooltip, Labels, and Legend to Flutter Treemap Source: https://pub.dev/packages/syncfusion_flutter_treemap Enhance the treemap with interactive elements by enabling tooltips, customizing labels, and configuring the legend. This snippet shows how to use `tooltipBuilder`, `labelBuilder`, and `legend` properties. ```dart late List _source; @override void initState() { _source = [ SocialMediaUsers('India', 'Facebook', 25.4), SocialMediaUsers('USA', 'Instagram', 19.11), SocialMediaUsers('Japan', 'Facebook', 13.3), SocialMediaUsers('Germany', 'Instagram', 10.65), SocialMediaUsers('France', 'Twitter', 7.54), SocialMediaUsers('UK', 'Instagram', 4.93), ]; 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; }, labelBuilder: (BuildContext context, TreemapTile tile) { return Padding( padding: const EdgeInsets.all(2.5), child: Text( '${tile.group}', style: TextStyle(color: Colors.black), ), ); }, tooltipBuilder: (BuildContext context, TreemapTile tile) { return Padding( padding: const EdgeInsets.all(10), child: Text( 'Country : ${tile.group}\nSocial media : ${tile.weight}M', style: TextStyle(color: Colors.black)), ); }, ), ], ), ); } class SocialMediaUsers { const SocialMediaUsers(this.country, this.socialMedia, this.usersInMillions); final String country; final String socialMedia; final double usersInMillions; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.