Dart

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

Updated: September 1, 2023 By: 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

Updated: March 31, 2023 By: 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 to make him…

How to Reverse/Shuffle a List in Dart

Updated: March 31, 2023 By: A Goodman

The two examples below show you how to reverse and shuffle a given list in Dart. Reversing a Dart list Reversing a list means changing the order of the elements in the list so that the…

Dart: Calculate the Sum of all Values in a Map

Updated: March 31, 2023 By: A Goodman

This short example-based 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…

How to Reverse a String in Dart (3 Approaches)

Updated: March 31, 2023 By: A Goodman

The three examples below show you three different ways to reverse a given string in Dart (e.g. turn ABC to CBA). Turn the String into an Array Example: Output: Using StringBuffer Example: Output: Using Char Code…

How to Subtract two Dates in Flutter & Dart

Updated: March 31, 2023 By: A Goodman

In Flutter and Dart, you can subtract two dates by using the DateTime.difference method. The result is a duration. Example: Output: If you want to get rid of the blue line under the print() function, you…

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

Updated: March 31, 2023 By: 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: Though Dart doesn’t provide an out-of-the-box API that can help us get the…

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

Updated: March 31, 2023 By: Napoleon

When working with Flutter and Dart, there might be cases where you have to check whether a given string is null or empty. We can define a reusable function to do the job as follows: We…

Dart: Using Async and Await in Loops

Updated: March 31, 2023 By: 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

Updated: March 31, 2023 By: 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

Updated: March 31, 2023 By: 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 best strategy to get the job done is to use a…

Flutter & Dart: Convert a String into a List and vice versa

Updated: March 31, 2023 By: Pennywise

In Flutter and Dart, you can turn a given string into a list (with string elements) by using the split() method. Example: Output: In the opposite direction, to convert a list of strings to a string,…

1 2 3 4 5 8