{

Learn free dart tutorials


Dart| Flutter How to: Read pubspec.yaml attributes (version) with examples

April 30, 2022 ·  1 min read

This tutorials explains about how to read pubspec.yaml file in example. pubspec.yaml file contains following things name: dartapp description: >- dart example application. version: 1.0.0 environment: sdk: '>=2.10.0 <3.0.0' dependencies: ini: ^2.1.0 jiffy: ^5.0.0 quiver: 3.0.1+1 yaml: ^3.1.0 yaml_writer: 1.0.1 image: any mime: any path: any package_info: any dev_dependencies: intl: any How to read pubspec.yaml file in Dart This tutorials is about to read puspect.yaml file and print the content....


How to Create and build a Singleton Class Dart or Flutter example| Dart By Example

April 29, 2022 ·  2 min read

Singleton is a basic design pattern. It is used to create a single object instance for a class in Dart. Singleton features Lazily created an instance of a class Only one instance is created Object can be created only with a static method Private constructor Dart singleton example There are multiple ways we can create a singleton instance always for a given class Create a Singleton class Create a final static compile-time constants for an instance of the Singleton class Create a named private constructor that starts with an underscore(_) Create an empty constructor, and adds the factory keyword to it....


What is the difference between var and dynamic and final in dart?| Flutter By Example

April 29, 2022 ·  2 min read

This tutorial shows you the usage of var, dynamic and final keywords in the dart, see the between var vs dynamic vs final in the dart. Difference between var, dynamic, and final in dart? These three keywords are used to declare the variables in Dart. let’s see the difference between them. var keyword var is used to declare and assign multiple values. Following are var keyword features variable declared with var only change its value...


How to: Check if Phone number is valid or not in Dart| Flutter By Example

April 28, 2022 ·  2 min read

This program checks how to validate the phone number validation. Dart provides a RegExp class for matching strings with regular expression. Following are the rules for valid phone numbers. phone number only contains numerical numbers and Optional symbol(+) only letters are not allowed Optional + or zero with beginning followed by digits from 1 to 9 Phone number can contain 10 or 12 digits Valid phone numbers are +9166666666666 and Invalid emails are abc, 123....


Dart| Flutter How to read an image from a disk and resize a file

April 27, 2022 ·  1 min read

Sometimes, We want to read an image from a disk folder and resize it and display the image. You can use the resized image in flutter widgets to display it This tutorial explains how to read and resize it. How to read images in dart? First import the image library as a dependency in pubspec.yaml name: dartapp description: >- dart example application. version: 1.0.0 environment: sdk: '>=2.10.0 <3.0.0' dependencies: image: any import dart:io and image package in the application create a File object with the given file path Decode the image using file object using decodeImage, and convert to a byte in synchronous operation using the readAsBytesSync() method change the image size with copyResize and returns the image object File convert image object, save the object Here is an example program for reading, resize, and outputting image...


Dart/Flutter: How to write setter and getter fields or members variables in a class with Example

April 26, 2022 ·  2 min read

Setters and Getter allow you to read and update the data of a class object. It uses to achieve encapsulation Dart setter and getter examples In classes, Getters provide an access to read instance member variables. Setters allow you to update the instance variables of a class. Getters are called accessors, Setters are known as Mutators. In Dart, Getter and Setters are implicitly defined for every member declared in a class Still, You can customize the fields to write setters and getters...


Dart| Flutter How to get extension name and MIME type of a file with example

April 26, 2022 ·  2 min read

This tutorial explains about below program How to get the MIME type of a file How to find the extension of a given file How to get the MIME type of a file? This program explains about to get mime types of a file. mime package provides lookupMimeType function, that returns MIME type. It parses the path of a file, returns extension, extension is checked against MIME types, and returns the MIME-type...


Dart| Flutter How to: Create a private variable with example

April 25, 2022 ·  2 min read

This tutorial shows how to write and declare private variables in Dart. Dart Private Variables There is no private keyword or private variables in Dart. In dart, you can declare a variable name with an underscore(_) as a private variable. Private variables are accessed inside the same class, not outside the classes or files. In Dart, you can declare private variables in the classes class Employee { int _privateVariable = 0; int id = 11; displayMessage() { print('$_privateVariable'); // 0 print('$id'); // 11 } } void main() { Employee employee = Employee(); print(employee....


Dart| Flutter How to: multiple ways to Remove an element or object from a List with Example

April 25, 2022 ·  3 min read

This tutorial shows you multiple ways to remove elements from a list with examples in dart Dart List remove element examples List class inbuilt methods remove use remove method: List class has a remove method, that removes elements with given input elements. It decreases the size of the list. bool remove(Object? value) It accepts an element. It removes an element, returns true, if the element is removed from the list, else false is returned....


Dart| Flutter How to: Insert an element at beginning of a List with Example

April 24, 2022 ·  1 min read

This tutorial shows how to insert the data at beginning of a list with examples in dart List inserts the elements in the insertion order. In the below program, add method inserts the elements to the end of a List. void main() { List wordsList = ['one', 'two', 'three']; wordsList.add("five"); print(wordsList); } Output: [one, two, three, five] Dart List insert at the beginning with examples List insert method provides inserting an element at the index position....


How to find integer numbers length in Dart?| Flutter By Example

April 24, 2022 ·  1 min read

This tutorial shows you how to find integer number lengths in Dart. For example, if the given number is 12345, Then the length of a number is 5. How to find the length of a number string in Dart? There are many ways to find the length of an integer in a dart The below program explains about The first way, Convert the integer to a string using the toString() method Call length property to return the length of a string....



How to use double dot operator- Cascade operator in Dart| Flutter

April 23, 2022 ·  2 min read

cascade operator is used to call sequence of methods on the objects using .. double dot operator. For example, you have a list object and want to call the same add method for multiple values. You will call as below List list = []; list.add(1); list.add(2); list.add(3); list.add(4); The object name list is repeatedly called to do the same operation. You can also do multiple operations on the same object. Cascade operator (....


Dart| Flutter: How to initialize a final class variable in a constructor? | Flutter By Example

April 22, 2022 ·  2 min read

This tutorial explains how to initialize the final class variable in the constructor. final variables are initialized only once, used only to initialize a variable at runtime. You can use static const for compile-time initialization values Let’s declare the final class field, and initialize the field with the value in the constructor. The below program gives Error: Final field ‘id’ is not initialized and Error: The setter ‘id’ isn’t defined for the class ‘Employee’....


How to Check given number is an integer or whole number or decimal number in dart | Flutter By Example

April 22, 2022 ·  2 min read

In Dart, We have two numerical types - int, double int represents whole numbers, that contain no fractional or decimal digits double stores the floating numbers that contain decimal values. how to check given number is int or double? There are multiple ways we can check using is Operator dart is the operator used to check the variable of a given type or not Syntax: variable is datatype Returns true if the variable of a given datatype else returns false....


Dart| Flutter How to check element exists in Array

April 20, 2022 ·  1 min read

This tutorial shows how to check element exists in array or list Dart or Flutter List In dart, Array and List stores the same type of collections, Arrays are fixed, List are dynamic in nature. Let’s see how to check an element exists in array or list How do Check value exist in a Array or List of dart/flutter? dart list provides multiple ways to check the sub list contains in the list of elements....


Multiple ways to the private constructor in Dart | Flutter with examples

April 20, 2022 ·  2 min read

This tutorial shows how to create a private constructor in Dart and Flutter. There is no keyword private in Dart language. you can check another post on declaring private variables in Dart language. How do you make a private constructor in dart classes? Generally, a Private constructor allows you not to create an object or instance of a class. Private constructors are useful to create a Singleton pattern. Dart Private constructor A constructor can be added with private using named constructor with underscore (_) syntax...


How to Comparing only dates of DateTimes in Dart or Flutter Programming| Dart by Example

April 19, 2022 ·  2 min read

In Dart, the DateTime object stores Date and Time data. Suppose if you want to compare the dates of two DateTime objects, The month, day, and year of two dates are equal. How to Compare only dates of DateTimes in Dart? Create three Date time objects, First object date1 is using now() - 2022-04-10 20:48:56.354 Second object date2 created by adding duration of 10 seconds - 2022-04-10 20:49:06.354 Third object date3 created by adding duration of 10 days - 2022-04-20 20:48:56....


How to get the name of the days of the week in Dart| Flutter by Example

April 19, 2022 ·  2 min read

DateTime.weekday returns integer number from 1 to 7 , Monday represents 1 and Sunday represents 7. void main() { DateTime date = DateTime.now(); print(date); //2022-04-10 20:48:56.354 and sunday print(date.weekday); // 7 } How to print the weekname such as Monday in Dart. How to get the name of days of a week for a date in Dart? There is no direct way to get with the In-built DateTime class and methods to get the name of the week....


How to Add/subtract years, months, days, hours, minutes, or seconds to a DateTime Dart or Flutter

April 18, 2022 ·  2 min read

In this tutorial, You will find multiple ways to add or subtract years, months, days, hours, minutes, or seconds. How to add year months days, hours minutes or seconds milliseconds and microseconds to date in Dart First Create a Date object for the Current Date and time Date class contains add the method that accepts Duration object DateTime add(Duration duration) Duration can be passed with days, hours, minutes, seconds, mill, and microseconds....


Multiple ways to convert String to DateTime in dart with examples| Flutter By Example

April 18, 2022 ·  2 min read

This tutorial shows how to convert the String of date and time into a DateTime class object in dart and flutter. How to convert String into DateTime in Dart For example, a String contains a date formatted string - 2022-05-20 00:00:00.000. DateTime.parse() method creates DateTime object using formatted string DateTime parse(String formattedString) formattedString is an ISO string format. Here is an example program void main() { var strDate = '2022-05-20 00:00:00....


Dart| Flutter: How to Convert timestamp string from 24 hours to 12 hour format| Flutter By Example

April 17, 2022 ·  1 min read

By Default, the DateTime object returns the date and time, time contains a 24-hour format. This tutorial shows how to convert the String of date and time into a DateTime class object in dart and flutter. How to convert time string from 24 hours to 12 hour format in Dart For example, a String contains a date formatted string - 2022-05-20 23:12:20.000. DateTime.parse() method creates DateTime object using formatted string....


How to display greeting message on user time in Dart| Flutter by Example

April 17, 2022 ·  1 min read

In this article, You’ll find how to display greeting messages such as Good Morning, afternoon, or evening based on the user’s time in dart and flutter. Following are steps to print the greeting message. First, Get an hour of user time in dart if user time is less than or equal to 12, Display Good Morning. if user time is greater than 12 and less than 16, Display Good Afternoon....


Dart| Flutter: How to Convert timestamp epoch to DateTime local and UTC| Flutter By Example

April 14, 2022 ·  2 min read

Timestamp alias Epoch timestamp or Unix timestamp is a long number that represents the number of milliseconds since 1970-01-01 PST. It is a Count of milliseconds elapsed since 1970-01-01 PST. Sometimes, you need to convert timestamp to DateTime object in dart and flutter You can check how to get Current Timestamp epcho How to Convert Timestamp to DateTime in Dart and Flutter? This example converts timestamp in milli and microseconds to DateTime...


How to get Last Day of a Week, month, and year in Dart| Flutter by Example

April 14, 2022 ·  2 min read

This tutorial shows you multiple ways to get the Last Day of a Month and Year in Dart and Flutter. How to get the Last Day of a month in Dart and Flutter The first way, Using Datetime.day property Construct the DateTime object using the constructor with month always considered as value -1. For example, Object using DateTime(2013, 3, 0); created with Feb 2013 data. void main() { DateTime now = DateTime....


How to do Integer division in dart | Flutter By Example

April 13, 2022 ·  2 min read

In Dart, the Division operator / is used to divide the numbers. For example, two integer numbers are divided with the / operator, and the result is stored into an integer. void main() { int first = 10; int second = 2; int result; result = first / second; } The above code throws compilation error Error: A value of type ‘double’ can’t be assigned to a variable of type ‘int’....


How to Format a currency Dart or Flutter | Dart By Example

April 13, 2022 ·  2 min read

In Dart, You have a class NumberFormat that formats numbers with currency formats of a different locale. For example, if a given number is 100000, Some countries allow you to format a number as 100,000 and 100,000.00. Dart NumberFormat example Numberformat is a class in the intl package. First, define dependency in pubspec.yaml dev_dependencies: intl: any Next, Install dependency using the dart pub get command in the terminal or It automatically downloads in the Visual studio terminal...


Dart| Flutter: How to check installed version| SDK version

April 12, 2022 ·  1 min read

Sometimes, We want to find the installed version of Dart and SDK version. This tutorial shows check the install version of flutter and the SDK version How to Check the installed version of Dart? Type dart --version command in terminal gives dart SDK version PS A:\work\dart> dart --version Dart SDK version: 2.16.1 (stable) (Tue Feb 8 12:02:33 2022 +0100) on "windows_x64" if you want to find the location of the dart SDK location you can type the where dart command in Linux....


How to Find the number of days and years between two dates Dart or Flutter | Dart by Example

April 12, 2022 ·  1 min read

This tutorial shows multiple ways to find the number of days between two dates. There are multiple ways we can do How to find the number of days between two dates in dart First Created two dates with DateTime constructor and now() Next, find the difference between two dates using the difference() method. It returns the Duration object which returns the number of days using the inDays property. Syntax Duration difference(DateTime other) Similarly, you can call Duration....


How to read input arguments from console Dart| Read a string from the console command line from a program

April 11, 2022 ·  2 min read

This tutorial shows multiple ways to read the console arguments or input parameters from a user in the Dart program. How to read input arguments from Console Command in Dart? dart:io package provides two classes. stdout - contains methods to print the string to console stdin - Contains methods to read input from the console stdin.readLineSync() method read the input from the stdin console. It returns an optional String, which can be null and read as a String until Enter key is pressed....


How to: Check if email is valid or not in Dart| Flutter By Example

April 11, 2022 ·  2 min read

This program checks how to validate the email address. Dart provides a RegExp class for matching strings with regular expression Following are the rules for a valid email address. Email has different valid parts - sender name,@ symbol, and domain name recipient and domain names may contain lower and upper case numbers domain name contains an extension separated by a dot(.) special characters are allowed in the sender’s name sender name length is 64 characters domain name is 256 characters Valid emails are abc@ch....


How to Get current Unix timestamp or milliseconds since epoch Dart or Flutter Programming| Flutter by Example

April 10, 2022 ·  1 min read

This article, Shows how to get the Current Timestamp or Unix Timestamp or epoch timestamp in Dart and Flutter. We will use DateTime.milliseconds since epoch and DateTime.microsecondsSinceEpoch methods to return milli and macro seconds. Epoch timestamp or Unix timestamp is a long number in milliseconds to refer to a time of a day. It is Count of milli seconds elapsed since 1970-01-01 PST. How to get Current Epoch Timestamp in Dart/Flutter Dart provides the DateTime class to provide Date and Time-related functions....


Multiple ways to delay code execution in sync and asynchronous way in dart?| Flutter

April 10, 2022 ·  2 min read

This tutorial solves the below problems. How to run code after some delay in Flutter? Sleep code for specific time in dart? Sometimes you want to sleep or delay code execution for a duration time. In dart, You can do it in multiple ways. Code execution can be delayed using asynchronous and synchronous way way In asynchronous code execution, you can use use Future.delayed, Stream periodic or Timer class In Synchronous execution, you can use the Sleep method to execute sequentially....


Dart Example to count the number of digits in a number| Decimals Count in Dart

April 9, 2022 ·  2 min read

This example covers two programs in dart. the first program finds the count of a number of digits in an integer number The length of a number is to find the count of the number of digits. For example, 129 number digits count is 3. The second program finds the count of a decimal of a double number For example, 129.1234 number, decimal digit count is 4....


Dart| Flutter How to: remove all whitespaces or trim in a string

April 9, 2022 ·  2 min read

This tutorial shows multiple ways to remove whitespace characters from a given string How to trim leading and trailing whitespace characters in dart string The dart string trim method removes the lead and trail whitespace characters. Syntax: String trim() Here is an example to remove the start and end whitespace characters from the string void main() { String name = ' Hello Welcome '; print(name); print(name.trim()); } Output: Hello Welcome Hello Welcome It removes any whitespace symbols if string contains new line (\n) or tab(\t) characters,...


Dart| Flutter How to: Multiple ways to get the First and last letter of a string

April 8, 2022 ·  2 min read

This tutorial shows you multiple ways to get the First and Last Letters of a Given input string. The string is a group of characters enclosed in single or double quotes. How to get the First Letter of a string in Dart and Flutter There are multiple ways we can get the first letter of a string. using index syntax: index in string always starts with zero and end index is a string....


How to convert decimal to/from a binary number in Dart

April 8, 2022 ·  2 min read

A binary number is a number based on base 2. It contains either zero or one digit. Each digit is called a bit. Example binary numbers are 1011. Numbers with a base of ten, or numbers ranging from 0 to 9, are known as Decimal Numbers. 45 is an example of a decimal number. Learn how to convert decimal to Binary in a dart in this quick tutorial. How to convert decimal numbers to Binary numbers in Dart?...


Dart Example - Program to check Leap year or not

April 7, 2022 ·  2 min read

In this blog post, We will write a program to check a given year is a leap year or not in dart and flutter. How do you check if the year is a leap year or not? if the year is divisible by 4, check step 2, else go to step 5 if the year is divisible by 100, check step 3 else go to step 4 if the year is divisible by 400, check step 4, else go to step 5 Then the year is leap year which has 366 days This is not leap year which has 365 days Finally, if the year meets all the above conditions, Then it is Leap year....


How to concatenate two strings in a dart?| Flutter By Example

April 7, 2022 ·  2 min read

Learn how to concatenate two strings in Dart and flutter programming with examples. In Java languages, you can use the + symbol or the append method used to append strings. Since String is an immutable object. There are multiple ways we can append strings. String concatenate or append in dart For example, if given strings(str1=Hello, Str2=John) are appended, then the output is hello John`. -using + operator...


Dart/Flutter: How to Sort Map Key and Values with examples

April 6, 2022 ·  2 min read

Map is an data structure with key and values in unordered way. This tutorials shows multiple ways to sort map by key and values in Dart and Flutter. One of the way is using collections package contains SplayTreeMap class to store items in sorted order. How to sort Map by Values in dart and flutter? There are multiple ways to sort keys in a Map SplayTreeMap class provides named constructor using from method that accepts map and function....


How to convert decimal to/from an Octal number in Dart

April 6, 2022 ·  2 min read

An Octal Number is a number with eight digits. The Base 8 numbering system, often known as Octal numerals, is used. Octal numerals in Dart contain decimal numbers (0-9) such as 0,1,2,3,4,5,6,7. 42 or 3,3 are examples of Octal numbers. Decimal Numbers are numbers having a base of 10, or numbers spanning from 0 to 9. 45 is an example of a decimal number. Learn how to convert decimal to Octal in a dart in this quick tutorial....


How to print dollar symbol in string dart?| Flutter By Example

April 5, 2022 ·  1 min read

You can append any string with another string using the plus operator or interpolation syntax. Similarly, You can add a dollar symbol to a string in multiple ways. How to print the dollar symbol in Dart and Flutter? There are multiple ways The string contains normal text or raw text which is interpreted with interpolation syntax. interpolation syntax uses the $ symbol to print the variable value. For example, if you interpolate syntax, You can use $price to print the variable value....


How to: How to get Hostname in Dart| Flutter By Example

April 5, 2022 ·  1 min read

Sometimes, We need to get the hostname of a running application in the current environment in the dart and flutter application This post shows multiple ways to get a hostname in the dart and flutter project. How to get Hostname in dart application dart:io package provides platform class that provides information of an running environment. Platform class has a static method localHostname that returns the hostname of a system. static String get localHostname => _localHostname; Here is an example program to get hostname in dart...


Dart| Flutter How to: Convert Map to Query String with example

April 4, 2022 ·  2 min read

This tutorial, Shows you multiple ways to convert a Map of values into URL Query String and Query String into the map. This works in Flutter also. Query String is a key and value appended to URL separated by &. How to Convert Map to Query String in dart and flutter Sometimes, We have a map of keys and values in Dart var employee = {"email": "abc@abc.com", "id": "1"}; you want to output...


How to convert decimal to/from a hexadecimal number in Dart

April 4, 2022 ·  2 min read

A ‘Hexadecimal number,’ often known as a Hexa number, is a 16-digit number. It is based on the Base 16 numbering system, also known as hexadecimal. In Dart, hexadecimal numerals include decimal numbers (0-9) and six alphabets ranging from A to F, i.e. 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. 42E or 4C,4B, are hexadecimal numbers examples. Numbers with a base of ten, or numbers ranging from 0 to 9, are known as ‘Decimal Numbers.’ 45 is an example of a decimal number....


Dart/Flutter How to Check string contains alphabetic number

April 3, 2022 ·  3 min read

Dart String characters Examples The string is a group of characters enclosed in single or double-quotes. Characters can be any of the following types alphabetic characters: Each character contains a letter from lowercase - a to z and uppercase - A to Z. `alphanumeric characters: contain alphabetic and numeric characters. Special characters: a character is like %,# ..etc excluding alphabetic and numeric characters. numbers: a character is like numbers are called numeric characters....


Dart| Flutter How to: Function Return a function

April 2, 2022 ·  2 min read

This tutorial shows multiple ways to execute a function repeatedly with a delay timer in dart and flutter programming. Functions declare a return type and return values. In Dart Function also returns functions, which means Function is also typing like primitive type. And type is Function. How to Return a function in Dart The below examples show that Functions return the Function type. Function Declaration contains Return type as Function....


Dart| Flutter How to: Run a function repeatedly with a delay

April 2, 2022 ·  2 min read

This tutorial shows multiple ways to execute a function repeatedly with a delay timer in dart and flutter programming. How to execute function repeatedly with delay timer There are multiple ways we can execute a code function periodically with delay time. use the Timer Periodic method Timer.Periodic() method allows you to create a timer. Timer Timer.periodic(Duration duration, void Function(Timer) callback) It accepts Duration and Callback function parameters....


Dart| Flutter How to: Check sublist contains all elements in List

April 1, 2022 ·  1 min read

This tutorial shows how to check sublist exists in Dart or Flutter List How do Check sub lists exist in a list of dart/flutter? dart list provides multiple ways to check the sub list contains in the list of elements. First Convert list into set using Set.of() method Check sub list exists in Set using Set.containsAll() method Here is an example code void main() { var list = [1, 4, 5, 2, 8]; var sublist = [1, 4]; var set = Set....


Dart| Flutter How to: Find an object implements interface

April 1, 2022 ·  2 min read

In Dart, Class extends only one parent class and implements multiple interfaces. Below are operators to check a class of a given object. is checks a given object implements or extends interface or class, It checks parent class hierarchy and returns true if it follows inheritance. runtimeType: Returns the class of an object and gives the only current class of an object not the inheritance tree class checking if an object implements interface in dart?...


How to: Convert Future String to String vice versa in Dart| Flutter By Example

March 31, 2022 ·  2 min read

This tutorial shows you how to Convert Future<String> to String in Dart and Flutter programming. Asynchronous programming is supported through the async and await keywords in Dart and Flutter. When retrieving data from the backend, data load it asynchronously before displaying it in the frontend. Future class uses for asynchronous operations in the Dart application. It stores the various types of values returned by async operations. Its value is always a future value that awaits the completion of the function....


How to: Generate Random String in Dart| Flutter By Example

March 31, 2022 ·  2 min read

Random Generator is used to generate a unique value for every invocation. This talks about multiple ways to generate a random string for example. Dart/Flutter Random String generate example This example generates a Random String with values. Following are steps to follow. First, create a constant Character Array of alphabets and special characters. Find the Random number between zero to character array length Create a List of random Unicode numbers using the Iterable....


Dart| Flutter How to: Convert String into an array

March 30, 2022 ·  1 min read

This tutorial shows multiple ways to convert a String into an array or list in dart and flutter programming. Since Array does not support in Dart. We will show you to convert to List onlly. Convert String int List or Array of character String. split() method split the string with the delimiter. The default delimiter is an empty character. Here is an example Convert String into a List of string characters...


Dart| Flutter How to: String replace method

March 30, 2022 ·  2 min read

The string is an immutable class. There is no method such as setCharAt() with an index like in java. We can do multiple ways to replace a character or substring in a String String replace a letter using substring in dart example This example, Replaces the one the character with a new character in a given string. str.substring(0, 2) returns the substring with the start and end index. str.substring(3): returns the substring start index to the remaining string...


Dart| Flutter How to encode and decode a string base64 with example

March 29, 2022 ·  1 min read

Sometimes, need to send the string data in base64, So we need to know how to send encode a string and decode a string. There are multiple ways we can do it. Dart provides an inbuilt dart:convert library to encode and decode various objects in UTF8 formats. How to encode a string in base64 format in dart dart:convert library provides base64 class. This example converts the string into an encoded base64 string....


Dart| Flutter How to reverse a string example

March 29, 2022 ·  2 min read

In this article, learn how to reverse a string in multiple ways. It also includes reversing a string with Unicode utf-8 characters. There are multiple ways we can do it. Dart provides an inbuilt dart:convert library to encode and decode various objects in UTF8 formats. How to do string in reverse order in dart This example takes the input string and converts the string in reverse order. First, the Given string is split into characters using the split() method....


Dart| Flutter How to calculate the collection numbers sum example

March 28, 2022 ·  3 min read

The collection is a collection of elements in dart. For example, a List is one of the collections of items to store with insertion order. Dart Collection of the sum of numbers example There are multiple ways we can do the sum for the collection of numbers. use List reduce method List. reduce() method reduces the collection of elements with the iteration of elements and applies the function....


Dart| Flutter How to calculate the collection numbers sum example

March 28, 2022 ·  2 min read

Functions in Dart return only a single value. There are multiple ways to return multiple values wrapped with the below types Array or List Create an object of a Class Set Tuple class How to return multiple values from a Function in Dart Following are multiple ways to pass multiple data from a function create a class and pass the object with values from a function In this example, the function wants to return multiples of different types, So Wrap those values in the object of a class and return from a function....


How to: Convert List to List in Dart| Flutter By Example

March 28, 2022 ·  2 min read

This tutorial shows you how to Convert Future<List> to List in Dart and Flutter programming. Dart and flutter provide async and await keywords for asynchronous. When you are retrieving the data from the backend, loaded in asynchronous and display it in frontend. Future are classes for asynchronous operations in the Dart application. It holds the values of different types returned from async operations. Its value always returns status uncompleted and completed....


Dart/Flutter:How to Compare two Sets for equal Example

March 27, 2022 ·  3 min read

This tutorial shows multiple examples of how to compare two Sets in Dart and Flutter programming. Two sets are equal if it matches below criteria Length of two sets are equal Order of elements is not important If element is an object, The key and values of an objects in both sets should matched. Check if two sets are equal or not In dart, quiver package a library for collection utility reusable functions...


Dart| Flutter How to: Find Set is Empty or not

March 26, 2022 ·  3 min read

This tutorial shows different ways to determine whether or not a set is empty in Dart or Flutter. This post talks about the below things. How to test whether a given Set is null or not and whether its length is zero. Determine whether the Set is empty or blank. Verify that the Set contains Zero elements Set is one of the data structures to store the collection of elements without duplicates....


How to convert List to Set or vice-versa in Dart| Flutter By Example

March 26, 2022 ·  1 min read

This tutorial shows multiple ways to convert List to Set in Dart or flutter programming. The List is a dynamic collection of objects in Dart, elements are inserted on insertion order and allow duplicate objects. The Set is a data structure to store a collection of elements, does not allow duplicates. Both are different types in Dart or Flutter, and We have to write a code to convert from one type into another....


Dart/Flutter: How to Convert Map to/from List of Objects

March 25, 2022 ·  4 min read

In Dart or Flutter Maps and List are predefined data structure types used to store collections. The map contains key and value pairs of elements The list contains a collection of elements. Automatic conversion is not possible from Map to List or List to Map. We have to manually convert from Map to List or vice versa. There are multiple ways to convert from Map to List. For example, Let’s create an Employee Class...


Dart| Flutter: Convert List of Dynamic into List of String examples

March 25, 2022 ·  2 min read

In Dart and flutter, this tutorial explains how to convert List<Dynamic> to List<String> and vice versa. A dynamic type is a primitive type that may hold any dynamic value, such as an integer, a string, or a double. Because a string is a primitive type that stores a collection of characters, automated conversion to/from dynamic is not possible. You can check on How to convert dynamic to string vice versa or vice versa in Dart and flutter....


How to convert List to Map or vice-versa in Dart| Flutter By Example

March 25, 2022 ·  2 min read

This tutorial shows multiple ways to convert List to Map in Dart or flutter programming. The List is a dynamic collection of objects in Dart. The map is a data structure to store key and value pairs. Both are different types in Dart or Flutter, and We have to write a code to convert from one type into another. How to convert List to Map in Dart or Flutter programming List....


Dart/Flutter:How to Check two Maps for equal or not

March 24, 2022 ·  4 min read

This tutorial shows multiple examples of how to compare two maps for equal or not in Dart and Flutter programming. Compare Two maps equal in dart and flutter Check for equal comparison of nested maps in dart and flutter The map contains key and value pairs. If two maps are equal, then it should satisfy the below things key and value pairs in both maps are equal Length of both maps are equal Order of keys and values is also not important....


Dart| Flutter How to: Create an Empty Set

March 24, 2022 ·  2 min read

This tutorial shows multiple ways to create an empty Set in Dart or Flutter An empty Set is a Set data structure that contains no elements, and a Set has a length of zero. In Flutter, an API or service method may return an empty set instead of null to improve null safety handling. How to create an Empty Set in Flutter or dart? An empty Set can be created in multiple ways....


Dart| Flutter How to: Check Map is or empty or not Example

March 23, 2022 ·  3 min read

This tutorial shows different ways to check whether a map is empty or not in Dart or Flutter. This post talks about the below things. How to check if a given map is null or not and length is zero Find the map is empty or blank. Check map contains no elements In dart, what is an empty map? An empty map has no elements and is blank....


Dart| Flutter How to: Create an Empty Map

March 23, 2022 ·  2 min read

This tutorial shows multiple ways to create an empty Map in Dart or Flutter An empty Map is a Map data structure that lacks a key and value pair of elements, and a Map has a length of zero. In Flutter, an API or service method may return an empty Map instead of null to improve null safety handling. How to create an Empty Map in Flutter or dart?...


Dart/Flutter:How to Compare two lists for equal Example

March 22, 2022 ·  3 min read

This tutorial shows multiple examples of how to compare two lists in Dart and Flutter programming. Compare lists for equal Check for equal comparison of the list of strings how to compare a list with a string in a flutter How to check if the given list is equal or not in Dart? In dart, quiver package a library for collection utility reusable functions It has a listsEqual function that compares two lists and returns true if equal else not equal....


Dart| Flutter: Convert List of Strings into List<int> examples

March 22, 2022 ·  2 min read

This tutorial shows multiple ways to Convert List<String> into List<int> in Dart and flutter. String and int types are different primitive and store different values, So automatic conversion are not possible. You can check on How to convert String to int or vice versa in Dart and flutter. How to Convert List of String into List of Int type in Dart This example converts a list of string into a list of int in dart and flutter....


Dart| Flutter How to: Flatten a List with examples

March 21, 2022 ·  2 min read

List contains a list of sub lists or a Map i.e two dimensions list. Flatten list is to output a single list from a two-dimension list. Let’s create a list of sub-list or two-dimensional lists in dart. var list = [ [1, 2, 3], [4, 5, 6], [7, 8] ]; A two-dimensional list contains the list of elements, where each element is again a list. After flatting the list, the result is...


Dart| Flutter How to: Multiple ways to clone or copy a List with examples

March 21, 2022 ·  4 min read

A clone is a copy of an object. In general, Clone is of two types. Let’s create a list in dart. List original = [1, 2, 3]; It does the following things during list object creation. Create a variable for the list i.e. object list data is stored in memory location Object(original) has a reference to memory location Shallow Clone: In this copy process, data exists in the same memory location, but creates two references pointing to the same memory location....


Dart| Flutter How to: Check List is empty or not Example

March 20, 2022 ·  2 min read

This tutorial shows multiple ways how to find if the list is empty or not in Dart or Flutter. This post talks about the below things. How to check if a given list length is zero Find list is empty or blank. Check List contains nil elements What is an empty list in dart? An empty list is a list with no elements and is blank....


Dart| Flutter How to: Create an Empty List

March 20, 2022 ·  2 min read

This tutorial shows multiple ways to create an empty list in Dart or Flutter List An empty list is a list without an element and the size of a list is zero. Sometimes, In Flutter, API or service method returns an empty list instead of null to have better handling of null safety. How to create an Empty List in Flutter or dart? An empty list can be created in multiple....


Dart| Flutter How to: List Filter search with examples

March 19, 2022 ·  3 min read

This tutorial shows multiple examples on filtering List with some logic in Dart and flutter Dart/flutter multiple ways to filter a list or array of objects Following are multiple ways we can filter a list of objects In both the examples below, we have a list of objects, Where each object contains salary and name. Filter the list of objects based on salary conditions and output the result....


How to generate Unique Id UUID in Dart or Flutter Programming| Dart or Flutter by Example

March 19, 2022 ·  2 min read

This example shows Learn how to generate Unique ID - GUID, UUID in Dart programming language with examples. Related posts: javascript UUID example how to generate GUID in java React GUID generate Vuejs GUID Example This tutorial uses uuid package in dart and flutter. UUID is a 16-Byte unique id with every 4 digits separated by a hyphen(-). Install uuid packages in flutter and dart First, Add the package to pubspec....


Dart| Flutter: Different ways to check differences of two lists with example

March 18, 2022 ·  2 min read

The list contains a growable collection of data. Sometimes you want to find the difference between the two lists. For example, You have two declared lists List list1 = [1,5,10,20,25,30,35]; List list2 = [1,5,7,25,29,30]; What is the difference between the above list? The difference is a common element that is repeated in both lists is called a difference of the lists. And the output This example shows you multiple ways to find the difference between two lists....


Dart| Flutter: How to check the variable type is a String or not| Flutter By Example

March 18, 2022 ·  1 min read

This is a simple post to check variable is of a String type. The ‘is’ operator in Dart checks the type of a variable at runtime and returns true or false depending on whether the variable has a predefined type. String data in dart can be created with variables of type String or dynamic type. stringvariable is String returns true if the variable is a string. How to check given variable type is a String in Dart/Flutter void main() { var str = "abc"; print(str is String); //true if (str is String) { print(str); //eric } } Output:...


Dart| Flutter: How to check the type of an variable is list| Flutter By Example

March 17, 2022 ·  2 min read

This is a simple post to check variable is of a specific or Generic List type. Dart provides an is operator that checks the type of a variable at runtime and returns true for a given variable with a predefined type or not. How to check if a variable is a List in Dart This is operator provides a variable and List type and returns true if a given variable of type List....


Flutter/Dart How to: Different ways to iterate a list of elements

March 17, 2022 ·  2 min read

List in a dart programming is the growable list of elements. It is a data structure, that adds, removes and iterates the list of elements in the insertion order. This post shows you multiple ways of iterating a list of objects in Dart and flutter programming. Dart List Iteration examples There are multiple ways to iterate a List in Dart. For loop with index This is a basic normal for loop, which every programming language provides....


Dart| Flutter: Convert List into String examples

March 16, 2022 ·  2 min read

This tutorial shows multiple ways to create an immutable list. Sometimes, You need to Convert List<String> into a Single String. How to Convert Listto String in Dart? There are multiple ways we can do use join() method List has a join method that returns the string with an optional separator. default optional parameter is empty. It iterates each element and calls the element.toString() append the result with a separator....


Dart| Flutter: Multiple ways to create immutable List with examples

March 16, 2022 ·  2 min read

This tutorial shows multiple ways to create an immutable list. The list is a mutable list in a dart that allows adding, removing, and updating operations. Immutable lists do not allow to add or update operations and allow only read operations. Due to reading operations, Immutable List is best in performance compared with List. Sometimes, We want to return APIs or methods to return immutable List only. For example, Normal List allows adding, updating, and removing operations as given below....


Dart| Flutter How to: Check strings are equal or not Example

March 15, 2022 ·  2 min read

This tutorial shows how to compare two strings are equal or not Dart or Flutter. Dart does not provide the isEquals (java) method to compare methods for equality. `String equals compare the same characters in the order of both strings are equal. Since, String are immutable objects, Once you create a string object, does not allow you to modify the string, However, if you append to an existing string, it creates a new string with result, the Original string also exists in memory....


Dart| Flutter How to: get First and Last Element from a List with Example

March 15, 2022 ·  3 min read

This tutorial shows how to get the first and last element from a Dart or Flutter List dart programming provides multiple ways to retrieve the first and last element from a list. How to get the First element in dart/flutter? dart list provides multiple ways to retrieve the first element. List.first property Returns the first element from a given list, if the list is not empty. if the list is empty, It throws an error Uncaught Error: Bad state: No element import 'dart:async'; void main() async { List list = []; print(list);//[] print(list....


Dart/Flutter: Check if String is Empty, Null, or Blank example

March 14, 2022 ·  3 min read

The string is the data type applied to variables. And, String variables stores a group of characters enclosed in double("") and single('') quotes. The default value is null if it does not assign a string value in Dart and Flutter. There is a difference between null, empty, and blank Strings in Dart and Flutter. null string is variable is declared, but not assigned with a value. An example is String value; and the value is null....


Flutter/Dart Difference between the const and final keyword in Dart?

March 13, 2022 ·  3 min read

final and final are keywords applied to variables. Dart and Flutter provide constant values assigned to variables using final and const keywords. const variables know the value at compile time. final variables know the value at Run time. let’s see the sample example of usage of this. const date=“2021-01-01” // compile time constants final date=CalculateDateFunction();// Runtime time constants Let’s see more comparisons with examples Compile-time vs runtime constants Both const and final values are assigned only once....


Flutter/Dart How to: Different ways to add leading trailing zeroes to number| Dart By Example

March 12, 2022 ·  2 min read

This tutorial shows multiple ways to add leading zeroes to an integer number in Dart/Flutter programming. This talks about multiple examples of the below things. How to add left and right pad zeroes to integer numbers? prefix and suffix zeroes to number in dart leading and trailing zeroes to a number How to add lead zeroes to Integer Number Leading zero is a zero added to integer number with a given specific length on the left side or right side of a given number digits...


How to: Enum to String in Dart | Print Enum name as String in Flutter By Example

March 12, 2022 ·  2 min read

This tutorial shows multiple ways to get Enum Name as String. It Converts the enum constant into String in Dart and Flutter programming. Consider Enum declaration enum WEEK { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } void main() { WEEK thursday = WEEK.THURSDAY; print(WEEK.MONDAY.toString()); //WEEK.MONDAY print(WEEK.MONDAY.index); // zero print(WEEK.MONDAY.runtimeType); // WEEK } From the above example, Printing Enum values return value itself of type Enum. For example, WEEK....


How to Sort List of numbers or String in ascending and descending in Dart or Flutter example

March 11, 2022 ·  2 min read

This tutorial shows multiple ways to sort a list or array of numbers or strings in ascending and descending order. We can use either Array or List data structured used to sort numbers. How to sort List of Numbers in natural and reverse order. Let us say We have a set of numbers in a list. var numbers = [33, 3, 31, 4, 40]; This sort of List of numbers in dart and flutter...


How to Sort List of objects - int string date properties in ascending and descending in Dart or Flutter example

March 11, 2022 ·  5 min read

This tutorial shows multiple ways to sort a list or array of numbers or strings in ascending and descending order. We can use either Array or List data structured used to sort numbers. Consider the Employee Class which contains int, string, DateTime properties as given. Employee class contains fields - id, name, salary and joinDate toJson() method returns JSON of an object. class Employee { final int id; final String name; final int salary; final DateTime joinDate; Employee(this....


Different ways to print an object in Dart and Flutter| Dart By Example

March 10, 2022 ·  3 min read

This tutorial shows multiple ways to print a class object in Dart and flutter In this post, you will learn multiple things How to print Class objects How to print Class object using toString() method How to fully dump and print object variables to console? Print object properties of an instance How to show data from a class Print object variable into JSOn format. Dart class contains properties and functions, It is a blueprint for an instance of the object created....


How to find min and max value in Dart List? Flutter List| Dart By Example

March 10, 2022 ·  3 min read

List contains multiple values, sometimes you need to get the minimum and maximum values from the given list. Let’s see some programs to find the min and max value in different ways. How to find the maximum and minimum value of a List of Numbers in the Dart program? use Sort the list and get the first and last Element in Dart In this example, First sort the list of numbers using the sort() method....


How to convert Double to Integer or Integer to double in Dart| Flutter By Example

March 9, 2022 ·  3 min read

This tutorial shows multiple ways to Convert Double to Int and Int to double in Dart and Flutter programming. Int is a primitive type that stores numeric numbers arbitrary-precision signed integer without decimals, Examples Int types values are 1,5. Double is a primitive type that stores IEEE-754 double-precision floating numbers. Example double type values are 1.34,1.0. Int and Double are different types and hold different values. Automatic conversion does not happen in the Dart compiler....


Flutter runtimeType and is operator| Flutter runtime type of an object

March 8, 2022 ·  2 min read

This tutorial shows multiple ways how to check a runtime of an object. In Dart programming, there are two ways we can know the type of an object or a variable. runtimeType is operator This checks dynamic and static types and helps developer to find the following things Check a runtime type of an object Object is assignable to another type using is operator. Check type of an variable declared in Dart or Flutter....


How to convert Double to String or String to double in Dart| Flutter By Example

March 8, 2022 ·  4 min read

This tutorial shows multiple ways to convert double to String or string to double in Dart and flutter programming language. The string is a string of numbers or characters enclosed in double quotes or single quotes. A double is a primitive type of floating-point number in Dart programming Both are of different types, Automatic conversions are not possible. So, We have to manually Convert String into double or double to String with examples...


How to convert Enum to number or integer to Enum in dart?| Flutter By Example

March 8, 2022 ·  2 min read

In these tutorials, you will learn how to convert enum to int or int to enum in dart and flutter programming. Enum is a custom class type to store the constant values. the values can be strings or numbers. Int is a predefined type in Dart or flutter that holds numeric values. Automatic conversion is not possible due to different types of data. Let’s declare Enum constants in Dart or Flutter...


Find the number of days between two dates in dart?| Flutter By Example

March 7, 2022 ·  2 min read

In this tutorial, We will see how to get several days between two dates in Flutter programming. To calculate the number of days between two days, We can use the difference of the DateTime object and call the Duration.inDays method Sometimes, We need to calculate the number of days between the date of birth and the current date. Number of Days between two Dates using DateTime.Difference() method Two DateTime variables are created, one is the date of birth, other is the current Date using DateTime....


How to capitalize the first letter of a string in dart?| Flutter By Example

March 6, 2022 ·  1 min read

In these examples, Learn how to capitalize the first letter of a string or statement in Dart programming with examples. The string contains a group of words separated by spaces and enclosed in single or double-quotes. For example, if the string contains ‘hello world’, capitalize of a string is ‘Hello world’. How to capitalize the first letter of a string in Dart In this example, Written capitalizeFirstLetter function...


How to create a sequence number in a list in Dart or Flutter | Dart By Example

March 6, 2022 ·  2 min read

Sometimes, We need to generate a fixed list with a sequence of numbers from 0 to N. This article, Shows multiple ways to create a list of 0 to n numbers. How to create a sequence of numbers list for a given number in Dart or Flutter There are multiple ways we can create a sequence of numbers in a list use list generate function generate() function in a list creates a list with values generated with a given function....


How to delete duplicates in a Dart List? Flutter List| Dart By Example

March 6, 2022 ·  1 min read

List contains multiple values, sometimes you need to delete the duplicate from the list. In this post, We are going to learn how to delete duplicates from List in Dart or flutter. Dart list allows duplicate values, if you store the same value multiple values, It stores the value as a different element. How to delete duplicate items from a list in Dart or Flutter? There are multiple ways we can do...


How to Generate Random Number and range of numbers in Dart or Flutter Programming with example

March 4, 2022 ·  2 min read

This tutorial shows multiple ways to Generate Random Numbers in the Dart programming language. A random number is a unique number generated between a minimum and maximum value for multiple requests The returned number is always between the ranges of values provided. Dart random Number Generator example Dart provides dart:math that contains Random class to provide a random generator. It provides the nextInt method takes a maximum value and returns a random number....


How to Get Current Date in Dart or Flutter Programming| Dart by Example

March 4, 2022 ·  2 min read

This example shows how to get the Current Date and time in the Dart or Flutter programming language. How to get the Current Date and time in Dart Dart provides the DateTime class to process Date and Time-related functions. now() method returns the current date and time. Here is an example to get Current Date and time main() { DateTime dateTime = DateTime.now(); print(dateTime.toString()); //2022-03-04 12:35:38.997 int currentYear = dateTime....


How to convert Integer to String or String to Integer in Dart or Flutter | Dart By Example

March 3, 2022 ·  3 min read

This tutorial shows multiple ways to convert integer to String in Dart or Flutter programming language The string is a string of numbers enclosed in double quotes An integer is a primitive type of a number Both represent different types, Automatic conversions are not possible. So, We have to manually Convert String into Int or Int to String with examples It is easy to parse String to Int in Dart with inbuilt methods...




Subscribe
You'll get a notification every time a post gets published here.