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…

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

March 7, 2022 Pennywise

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

Dart: Extract a substring from a given string (advanced)

March 7, 2022 Pennywise

This article is about extracting a substring from a given string in Dart (and Flutter as well). We’ll cover the fundamentals, write a simple program, then walks through a few advanced use cases. Without any further…

Dart: Check whether a string starts/ends with a substring

March 7, 2022 A Goodman

To check if a string starts with or ends with a given substring in Dart (and Flutter as well), you can use the startsWith() method and the endsWith() method, respectively: These methods are case-sensitive (distinguish between…

Dart: Convert Class Instances (Objects) to Maps and Vice Versa

January 13, 2023 A Goodman

This article walks you through a few examples of converting a class instance (object) into a map and vice versa in Dart (and Flutter as well). Learning through examples is the best way to deepen understanding…

1 2 3 4 7