Dart: Calculating the Average of Data in a List

July 28, 2022 A Goodman

This practical, succinct article walks you through two examples of calculating the average of numerical data in a given list. The first example works with a simple list that contains only numbers, while the second one…

Flutter: How to Fully Print a Long String/List/Map

July 18, 2022 A Goodman

If you’re running a Flutter with an iOS simulator or an Android emulator by using the following command: Then you’ll notice that whenever you print out a long string, list, map, or JSON data to the…

Dart: Sorting Entries of a Map by Its Values

July 4, 2022 A Goodman

Imagine your boss gives you a Dart map like so: And then he asks you to sort the map in the ascending/descending order of the map’s values. How do you solve this problem and make him…

How to Reverse/Shuffle a List in Dart

July 4, 2022 A Goodman

The two examples below show you how to reverse and shuffle a given list in Dart. Reversing a Dart list The code: Output: Shuffling a Dart list We can shuffle a list randomly by using the…

Dart: Calculate the Sum of all Values in a Map

July 4, 2022 A Goodman

This short article shows you a few ways to find the sum of all values in a given map in Dart (presume that all the values are numbers). Using a For/In loop Example: Output: Using Reduce()…

How to Reverse a String in Dart (3 Approaches)

June 22, 2022 A Goodman

The three examples below show you three different ways to reverse a given string in Dart (e.g. turn ABC to CBA). Example 1 Output: Example 2 Output: Example 3 Output: Futher reading: How to Subtract two…

How to Subtract two Dates in Flutter & Dart

May 28, 2022 A Goodman

In Flutter and Dart, you can subtract two dates by using the DateTime.difference method. The result is a duration. Example: Output: The DateTime class also has a method named subtract. However, this one isn’t used for…

Dart & Flutter: Convert a Duration to HH:mm:ss format

May 28, 2022 A Goodman

When working with Dart and Flutter, there might be cases where you want to turn a Duration into a string of HH:mm:ss format: mm: minutes as 2 digits from 00 to 59 ss: seconds as 2…

Flutter & Dart: How to Check if a String is Null/Empty

May 11, 2022 Napoleon

When working with Flutter and Dart, there might be cases where you have to check whether a given string is null or empty. Suppose that our app’s functionality only continues when the string is neither null…

Dart: Using Async and Await in Loops

April 20, 2022 Pennywise

In Dart (and Flutter as well), you can perform synchronous operations sequentially in loops by using Future.forEach. The example program below will print the numbers from 1 to 10. Every time it finishes printing a number,…

Dart: Converting a List to a Set and vice versa

March 20, 2022 Pennywise

In Dart, a list is an indexable collection of objects with a length while a set is a collection of objects where each object can occur only once. This short article shows you how to convert…

Flutter & Dart: Count Occurrences of each Element in a List

March 16, 2022 Pennywise

When working with Dart and Flutter, there might be cases where you want to count the occurrences of each element in a given list. The simple example below will demonstrate how to do that: Output: That’s…

1 2 3 6