prismutils

A Collection of tools and utilities handcrafted by Codeprism Technologies Inc. with ease of Flutter developers in mind.

FrequencyTracker

A utility tool to keep track of frequency of an item in a list. Can be used to keep track most frequently / least frequently added items.

Usage:

  • Install the package. Add to pubspec.yaml

    • prismutils: 0.0.1;
  • Import the package

    • import 'package:prismutils/prismutils.dart';
  • Create reference point, requires two parameters -- List of identifiers and List of items

      List<String> identifier = ['name', 'defValue'];
      FrequencyGenerator fr =
          new FrequencyGenerator(identifier, itemList);
    
    • Identifier List contains the parameters of nesting in your model, if any
  • Available methods:

    • registerItem(dynamic item) // Takes an item as parameter

      • Add new item to the frequency list. If item already exists, updates the count of the item. Else, adds it to the list
            Ex: fr.registerItem(itemList[itemList.length - 1]);
      
    • getFrequencyByValue(dynamic value) // Takes a parameter value

      • Get frequency of a particular item in the sorted list. Returns back an integer value, corresponding to the frequency of the item in the list
        Ex: int frequency = fr.getFrequencyByValue(itemList[0]);
      
    • getSortedList(bool reverse) // Takes a boolean parameter

      • Returns back the list, sorted based on preference. True indicates descending sort, false indicates ascending.
        Ex: List sr = fr.getSortedList(false);
         sr.forEach((element) {
         print('${element['name']['defValue']} - ${element['freq']}')
      

Libraries

prismutils