KindaCode

Dart

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

Updated: Mar 31, 2023

In Flutter and Dart, you can turn a given string into a list (with string elements) by using the split() method. Example: // main.dart void main() { const String s = "blue red orange amber green yellow purple pink brown......

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

Updated: Mar 31, 2023

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: bool x = myString.startsWith(mySubString); bool y =......

Flutter & Dart: How to Trim Leading and Trailing Whitespace

Updated: Feb 18, 2023

When using your app, users may unintentionally include leading or trailing whitespace when inputting data, which can result in inconsistent data. Trimming the whitespace ensures that the data is consistent and easier to work with. In......

Dart: 5 Ways to Calculate the Sum of a List

Updated: Feb 18, 2023

This practical, example-centric article walks you through 5 different approaches to calculating the sum of a list of numbers in Dart (and Flutter as well). No need to delay, let’s start right away and write some code. Using......

Dart: How to Remove or Replace Substrings in a String

Updated: Feb 15, 2023

In Dart (and Flutter as well), you can replace one or multiple substrings in a parent string by using the following built-in methods: replaceAll() replaceAllMapped() replaceFirst() replaceFirstMapped()......

Dart: Calculating Variance and Standard Deviation

Updated: Feb 15, 2023

Variance is a statistical measure that quantifies the amount of variability or spread in a set of data. It is calculated as the average of the squared differences from the mean of the data. Standard deviation is the square root of......

How to check numeric strings in Flutter and Dart

Updated: Feb 14, 2023

A numeric string is a string that represents a number. Numeric strings can contain digits (0-9) and may also include a decimal point, a minus sign (for negative numbers), and an optional exponential notation (for very large or small......

Dart regex to validate US/CA phone numbers

Updated: Feb 14, 2023

Image source: Pixabay Validating phone numbers is a common task when making Flutter applications. Before sending an SMS with a verification code (that usually costs real money), we should implement some basic checks. In this......

Dart regular expressions to check people’s names

Updated: Feb 14, 2023

The name of a person (in common languages) usually contains the letters A through Z (lowercase or uppercase), spaces, periods (in abbreviations), and may contain dashes. Examples of human names: Donand J. Trump Geogre W.......

Base64 encoding and decoding in Dart (and Flutter)

Updated: Feb 14, 2023

What are the points? To encode or decode Base64 in Dart, you can import and use the dart:convert library: import 'dart:convert'; For base64 decoding, use one of these 2 methods: String base64.encode(List<int> bytes) ......

How to clone a List or Map in Flutter/Dart (4 methods)

Updated: Feb 14, 2023

In Dart, cloning a list or a map means creating a new instance of the list or map that has the same elements or key-value pairs as the original but is a separate, distinct object. When you clone a list or a map, changes made to the......