Kinda Code
Home/Dart/Page 7

Dart

2 ways to remove duplicate items from a list in Dart

2 ways to remove duplicate items from a list in Dart

Updated: Feb 03, 2023
This article shows you a couple of different ways to remove duplicate items from a list in Dart (and Flutter, of course). The first one works well for a list of primitive data types. The second one is a little bit more complex but works......
Dart: Convert Class Instances (Objects) to Maps and Vice Versa

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

Updated: Jan 13, 2023
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 and long-term memory.......
Flutter & Dart: Check if a date is between 2 other dates

Flutter & Dart: Check if a date is between 2 other dates

Updated: Jan 08, 2023
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 import 'package:flutter/foundation.dart'; DateTime dateA = DateTime(1900, 9,......
2 ways to convert DateTime to time ago in Flutter

2 ways to convert DateTime to time ago in Flutter

Updated: Jan 08, 2023
This article shows you 2 approaches to convert DateTime to time ago format in Flutter (and Dart, too), for example, 5 minutes ago, 1 day ago, 2 days ago… The first one uses the difference() method provided by the DateTime class,......
Dart: Convert Timestamp to DateTime and vice versa

Dart: Convert Timestamp to DateTime and vice versa

Updated: Oct 06, 2022
The examples below show you how to convert timestamp (also known as Unix time or Epoch time) to DateTime and vice versa in Dart (and Flutter as well). We can archive our goal without using any third-party plugins. DateTime to......
How to Flatten a Nested List in Dart

How to Flatten a Nested List in Dart

Updated: Oct 06, 2022
In Dart, you can use the expand() method is to look for nested collections inside your collection and flatten them into a single list. Example: // https://www.kindacode.com // main.dart void main() { final matrix = [ ......
Inheritance in Dart: A Quick Example

Inheritance in Dart: A Quick Example

Updated: Oct 06, 2022
In Dart, you can use the extends keyword with any class when you want to extend the superclass’s functionality. A class can only extend one class since Dart does not support multiple inheritances. Below is a quick example of......
Flutter & Dart: 3 Ways to Generate Random Strings

Flutter & Dart: 3 Ways to Generate Random Strings

Updated: Oct 04, 2022
This article shows you 3 different approaches to generating random strings in Dart (and Flutter as well). Without any further ado, let’s dive into the code. Joining Random Alphabet Letters and Numbers The example below......
Dart: Get Host, Path, and Query Params from a URL

Dart: Get Host, Path, and Query Params from a URL

Updated: Aug 22, 2022
In Dart, you can extract useful information from a given URL string by following the steps below: 1. Construct a Uri object from your URL string: const url = "..."; const uri = Uri.parse(url); 2. Now, you can get what you want......
Flutter & Dart: Displaying Large Numbers with Digit Grouping

Flutter & Dart: Displaying Large Numbers with Digit Grouping

Updated: Aug 19, 2022
Displaying large numbers with commas as thousands separators will increase the readability. This short article will show you how to do so in Dart (and Flutter as well) with the help of the NumberFormat class from the intl package......
Using Static Methods in Dart and Flutter

Using Static Methods in Dart and Flutter

Updated: Aug 19, 2022
In Dart and Flutter, a static method (or a static function) is a method defined as a member of a class but can be directly called without creating an object instance via the constructor. In other words, a static method is a port of a......
Prevent VS Code from Auto Formatting Flutter/Dart Code

Prevent VS Code from Auto Formatting Flutter/Dart Code

Updated: Aug 19, 2022
By default, VS Code (Visual Studio Code) will automatically format your code when you save a Dart file. In general, this feature is useful and automatically makes your code cleaner, and has a consistent arrangement. However, there might......