How to convert String to DateTime in Flutter and Dart
Overview The DateTime class of the dart:core library provides 2 methods that can help you convert a string to DateTime: What Are Accepted Strings Not all strings can be converted to DateTime. A common pitfall that…
Set Default Parameter Values for a Function in Flutter
This is a short guide to default parameter values for a function in Flutter (and Dart as well). Default function parameters allow formal parameters to be initialized with default values if no value is passed. Syntax:…
Flutter FormatException: Unexpected character (at character 1)
Problem When sending an HTTP request in Flutter, you may want to decode the JSON response. When doing so, you may encounter the following error: This error is caused by the wrong JSON format you get…
How to Iterate through a Map in Flutter & Dart
This succinct, practical article shows you 2 different ways to iterate through a map in Flutter and Dart. Using forEach Sample code: Output: Using for Sample code: Output: If you only want to iterate through map…
Examples of using Future, async, await in Flutter
A few examples of using Future, async, and await in Flutter applications. Simple Example This example simply prints “Doing…” and “Task completed!” to the console. However, the first will appear before the later 2 seconds. The…
4 ways to convert Double to Int in Flutter & Dart
This succinct, practical article walks you through 4 common ways to convert a double to an integer in Flutter and Dart. Using toInt() The toInt() method will truncate a double to an integer and return a…
How to encode/decode JSON in Flutter
A Quick Note This article shows you how to encode/decode JSON in Flutter. The steps you need to follow are: 1. Import the dart:convert library: 2. Use: The concepts are just brief. Now, it’s time for…
How to make Comments in Flutter & Dart
This is a concise article about commenting in Flutter and Dart. Single-Line Comment (Format Comment) Just put two slash symbols at the beginning of the line you want to comment out. Multi-Line Comment (Block Comment) Syntax:…
Flutter & Dart: Check if a date is between 2 other dates
To check if a date is between 2 other ones in Flutter and Dart, you can use the isBefore() and isAfter() methods of the DateTime class. Example Output: You can find more information about the DateTime…
Flutter & Dart: ENUM Example
This article shows you how to use enumerations (also known as enums or enumerated types) in Dart and Flutter. Overview An enumeration in Dart is a set of symbolic names (members) bound to unique, constant values….
Flutter & Dart: Conditional remove elements from List
To remove elements from a list based on one or many conditions, you can use the built-in removeWhere() method. Example Let’s say we have a product list, and the task is to remove all products whose…
Flutter & Dart: Regular Expression Examples
A few examples of regular expression and the RegExp class in Flutter and Dart. Example 1: Email Validation The code: Output: Example 2: IP Addresses Validation The code: Output: Example 3: URL validation The code: Output:…