title: Flutter Pie Chart labelAccessorFn is not working
body: <p>Note: I used this answer <a href="https://stackoverflow.com/a/51845779/10464368">How to add label to pieChart flutter</a> as a reference to implement labelAccessorFn.</p>
  
  <p>I am using <em>charts_flutter</em> package to display charts in my flutter app, as far as I know, we use labelAccessorFn to show labels in Pie Chart but it's not working in my case.</p>
  
  <p><strong>App Overview:</strong>
  It's a mood checker app where user chose its mood every day using one of 5 emojis and in charts, we display data of emoji vs num of days it's been chosen.</p>
  
  <p><strong>chart file</strong>(labelAccessorFn is defined in addChartData method):</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:charts_flutter/flutter.dart' as charts;
  import '../models/mood_db.dart';
  import 'dart:async';
  
  class Mood {
    String _emoji;
    int _numOfDays; // this has to int bcz charts can't take future&lt;int&gt;
    charts.Color _color;
  
    Mood(this._emoji, this._numOfDays, this._color);
  }
  
  class MoodChart extends StatefulWidget {
    @override
    _MoodChartState createState() =&gt; _MoodChartState();
  }
  
  class _MoodChartState extends State&lt;MoodChart&gt; {
    DatabaseHelper _databaseHelper = DatabaseHelper();
    List&lt;Mood&gt; _data;
    var isDataFilled;
    List&lt;charts.Series&lt;Mood, String&gt;&gt; _chartData;
  
    //returns a Future with a list of results.
    Future&lt;List&lt;int&gt;&gt; numOfDaysFn(List&lt;int&gt; emojiID) async {
      return Future.wait(emojiID.map((d) =&gt; _databaseHelper.numOfMoodDays(d)));
    }
  
    void initData(List&lt;int&gt; emojiIds, List&lt;int&gt; days) {
      _chartData = List&lt;charts.Series&lt;Mood, String&gt;&gt;();
      setState(() {
        addData(days);
        addChartData();
      });
    }
  
    void addData(days) {
      _data = &lt;Mood&gt;[
        Mood(allMoods[0], days[0], charts.MaterialPalette.red.shadeDefault),
        Mood(allMoods[1], days[1], charts.MaterialPalette.blue.shadeDefault),
        Mood(allMoods[2], days[2], charts.MaterialPalette.gray.shadeDefault),
        Mood(allMoods[3], days[3], charts.MaterialPalette.indigo.shadeDefault),
        Mood(allMoods[4], days[4], charts.MaterialPalette.green.shadeDefault),
      ];
    }
  
    void addChartData() {
      _chartData.add(charts.Series(
          id: 'Mood',
          data: _data,
          colorFn: (Mood mood, _) =&gt; mood._color,
          domainFn: (Mood mood, _) =&gt; mood._emoji,
          measureFn: (Mood mood, _) =&gt; mood._numOfDays, //No longer a futures
          // I don't know what's wrong with this:
          labelAccessorFn: (Mood mood, _) =&gt; '${mood._emoji}'));
    }
  
    @override
    void initState() {
      super.initState();
      var emojiID = [1, 2, 3, 4, 5];
      numOfDaysFn(emojiID).then((days) {
        initData(emojiID, days);
      });
    }
  
    @override
    Widget build(BuildContext context) {
      if (_chartData != null) {
        return ListView(
          children: &lt;Widget&gt;[
            Container(
              height: 450,
              child: Card(
                elevation: 5.0,
                child: charts.PieChart(_chartData,
                    animate: true,
                    defaultRenderer: charts.ArcRendererConfig(arcWidth: 120)),
              ),
            ),
          ],
        );
      } else {
        return Center(child: CircularProgressIndicator()); //Added a loading icon
      }
    }
  }
  
  List allMoods = ['Disgusting', 'Bad', 'Ok', 'Good', 'Amazing'];
  </code></pre>
  
  <p><strong>DataBase file</strong>:</p>
  
  <pre><code>import 'package:path/path.dart';
  import 'dart:async';
  import 'package:path_provider/path_provider.dart';
  import 'package:sqflite/sqflite.dart';
  import 'dart:io';
  
  import '../models/mood_model.dart';
  
  class DatabaseHelper {
    static final DatabaseHelper _instance = new DatabaseHelper.internal();
    factory DatabaseHelper() =&gt; _instance;
    bool dataFilled = false;
  
    final String tableName = "moodTable";
    final String colMoodId = "moodId";
    final String colEmojiId = "emojiId";
    final String colActId = "actId";
    final String colMoodDay = "moodDay";
    final String colMoodMonth = "moodMonth";
    final String colMoodYear = "moodYear";
  
    static Database _db;
  
    Future&lt;Database&gt; get db async {
      if (_db == null) {
        return initDb();
      }
      return _db;
    }
  
    DatabaseHelper.internal();
  
    Future&lt;Database&gt; initDb() async {
      Directory documentDirectory = await getApplicationDocumentsDirectory();
      String path = join(documentDirectory.path, "mood.db");
      var ourDb = await openDatabase(path, version: 1, onCreate: _onCreate);
      return ourDb;
    }
  
    void _onCreate(Database db, int version) async {
      await db.execute(
          "CREATE TABLE moodTable (moodId INTEGER PRIMARY KEY, emojiId INTEGER, actId INTEGER, moodDay INTEGER, moodMonth INTEGER, moodYear INTEGER)");
      print("Table Created");
    }
  
    // insert
    Future&lt;int&gt; saveMood(Mood mood) async {
      // if (mood.moodDay == DateTime.now().day &amp;&amp;
      //     mood.moodMonth == DateTime.now().month &amp;&amp;
      //     mood.moodYear == DateTime.now().year) {
      //   var dbClient = await db;
      //   print('Updated');
      //   return await dbClient.update("$tableName", mood.toMap(),
      //       where: "$colMoodId = ?", whereArgs: [mood.moodID]);
      // } else {
      var dbClient = await this.db;
      int result = await dbClient.insert("$tableName", mood.toMap());
      dataFilled = true;
      return result;
      // }
    }
  
    // // update
    // Future&lt;int&gt; updateMood(Mood mood) async {
  
    // }
  
    // to get number of mood days
    Future&lt;List&lt;Map&lt;String, dynamic&gt;&gt;&gt; listOfMoods() async {
      Database db = await this.db;
      var result = await db.query(tableName, orderBy: '$colMoodId ASC');
      return result;
    }
  
    Future&lt;int&gt; numOfMoodDays(int emojiID) async {
      Database db = await this.db;
      var result = await db.query(tableName,
          orderBy: '$colMoodId ASC',
          where: '$colEmojiId = ?',
          whereArgs: [emojiID]);
  
      return result.length;
    }
  
    Future&lt;int&gt; actData(int actID, int emojiID) async {
      Database db = await this.db;
      var result = await db.rawQuery(
          'SELECT * FROM $tableName WHERE $colActId = $actID AND $colEmojiId = $emojiID ');
      return result.length;
    }
  
    Future&lt;bool&gt; isDataFilled() async {
      Database db = await this.db;
      var result = await db.query(
        tableName,
        orderBy: '$colMoodId ASC',
      );
      if (result.length &gt; 0) {
        return true;
      } else {
        return false;
      }
    }
  
    // close db
    Future close() async {
      var dbClient = await db;
      return dbClient.close();
    }
  }
  </code></pre>