Flutter: How to Fully Print a Long String/List/Map
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
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
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
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)
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
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
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
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
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
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
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
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,…