How to convert String to DateTime in Flutter and Dart
Updated: Feb 14, 2023
Overview The DateTime class of the dart:core library provides 2 methods that can help you convert a string to DateTime: DateTime.parse(String input): Constructs a new DateTime instance if the input is valid. Otherwise, throws a......
Flutter FormatException: Unexpected character (at character 1)
Updated: Feb 14, 2023
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: Flutter FormatException: Unexpected character (at character 1) This error is......
How to Iterate through a Map in Flutter & Dart
Updated: Feb 14, 2023
This succinct, practical article shows you 2 different ways to iterate through a map in Flutter and Dart. Using forEach Sample code: import 'package:flutter/foundation.dart'; final Map product = { 'id': 1, 'name': 'Fry......
How to encode/decode JSON in Flutter
Updated: Feb 14, 2023
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: import 'dart:convert'; 2. Use: json.encode() or jsonEncode() for......
How to add/remove a duration to/from a date in Dart
Updated: Feb 08, 2023
In Dart (and Flutter), you can add or subtract a duration (days, hours, etc.) to or from a DateTime object by using the add() and subtract() methods, respectively. Here’re some real-world use cases of doing this: Calculating......
Flutter & Dart: Conditional remove elements from List
Updated: Feb 06, 2023
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 prices are higher than......
How to remove items from a list in Dart
Updated: Feb 06, 2023
One of the most common tasks you encounter while working with a list in Dart is removing its items. Similar to other popular programming languages, Dart has some built-in list methods that help us get this matter done quickly.......
How to Merge 2 Lists in Dart
Updated: Feb 06, 2023
This article shows you a couple of different ways to join 2 lists in Dart. You will learn each method through an example. Using Addition (+) Operator Example: void main() { final List list1 = [1, 2, 3]; final List......
How to round a number in Dart
Updated: Feb 06, 2023
In order to round a float number to an integer in Dart, we can use the round() method. This method returns the closest integer to the input number. If cannot determine the closest integer (e.g. 0.5, -2.5, 3.5, etc), rounds away from......
Flutter & Dart: every() method examples
Updated: Feb 06, 2023
A few examples of using the every() method (of the Iterable class) in Dart (and Flutter as well). The purpose of this method is to check if every element of a given iterable satisfies one or multiple conditions (with a test......
Flutter & Dart: reduce() examples
Updated: Feb 06, 2023
In Dart, the reduce() method (of the Iterable class), as its name describes itself, executes a “reducer” callback function (provided by you) on each element of the collection, in order, passing in the return value from the calculation......
Working with For loop in Dart (and Flutter)
Updated: Feb 06, 2023
The for loop is one of the most important features in many programming languages including Dart. 1. For-in syntax Example: void main() { final myList = [1, 2, 3, 4, 5, 6, 7, 8, 9]; for (var item in myList) { ......