{

Learn free dart tutorials


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

March 12, 2023 ·  4 min read

This tutorial shows multiple ways to Convert Double to Int and Int to double in Dart and Flutter programming. Convert Double to Int in Dart: First Way, use double.toInt() method, For example: 3.4.toInt() returns int value 3. Second way, use double.truncate() method to remove decimals from a number.3.4.truncate() returns int value 3. Third way, use rounding methods such as round, ceil, and floor based on lower or upper value of a given number....


Perl How to: Find a Given Variable String is numeric or not

January 9, 2023 ·  2 min read

This tutorial explains How to check given string is a number or not in Perl with Code examples Scalar::Util module provides the qw(looks_like_number)function that checks given variable is a number or not. For example, looks_like_number("111") returns a boolean value, use in the conditional if statement to check as a number or not. Second, append a variable with zero, and use the result in a conditional if statement. Third, use the [Regexp::Common] module that uses a regular expression for real and integer numbers....


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

January 6, 2023 ·  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 a variable that is declared but not assigned a value. An example is String value; and the value is null....


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

January 6, 2023 ·  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(-). How to Install uuid packages in flutter and dart First, Add the package to pubspec....


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

January 6, 2023 ·  3 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 structure used to sort numbers. How to sort a 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...


Dart Enum comparison operator| Enum compareByIndex example| Flutter By Example

February 28, 2022 ·  2 min read

Comparison operators (<,>,>=,<=,==) are useful to compare the values. Enum contains constant values that represent the index starting from 0,1 onwards. enum WEEK { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } Enum Week contains constants such as MONDAY and index is 0, the second value is TUESDAY and index is 1. By default, two enum objects are equal using the == operator. void main() { WEEK sat = WEEK....


Dart Example - Program to check Leap year or not

February 28, 2022 ·  2 min read

In this blog post, We will write a program to check whether 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 a Leap year....


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

February 28, 2022 ·  2 min read

This example covers two programs in dart. the first program finds the count of several 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, in the 129.1234 number, the decimal digit count is 4. Consequently, Both are used to implement digit count for a given number....


Dart tutorial examples/ Flutter By Examples

February 28, 2022 ·  3 min read

This is a home page of Dart tutorials and examples. Dart by examples Private Constructor Multiple Constructor Private variables Round double with limit Dynamic vs Object Check Dart and Flutter Version Get Hostname initialize final variable Round to decimal places Phone number validation Setter and Getter Delay Code execution Email validation Difference between var,final and dynamic Difference between const and final Singleton Design pattern Generate UUID Custom exception and handles it Measure elapsed time execution of a function The following examples categorized based on feature...


Dart/Flutter How to Check string contains alphabetic number

February 28, 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 check if Map is null or not

February 28, 2022 ·  2 min read

This tutorial explains checking if the given map is null or not in dart and flutter programming null map in dart means if a variable is declared of Map type without initialized with the operator. For example, Let’s see an example of a Map being declared but not initialized with the operator. Map<int, String>? employees; or Map<int, String>? employees=null; employees variable is declared, but not initialized. Another example is, the map is declared with empty values literal syntax....


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

February 28, 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 they should satisfy the below things key and value pairs in both maps are equal Length of both maps is equal Order of keys and values is also not important....


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

February 28, 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 the below criteria Length of two sets is equal Order of elements is not important If the element is an object, The key and values of objects in both sets should be matched. Check if two sets are equal or not In dart, quiver package a library for collection utility reusable functions...


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

February 28, 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: How to Sort Map Key and Values with examples

February 28, 2022 ·  2 min read

The map is a data structure with keys and values in an unordered way. This tutorial shows multiple ways to sort the map by key and values in Dart and Flutter. One of the ways is using a collections package that 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 a named constructor using the from method that accepts map and function....


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

February 28, 2022 ·  2 min read

Setters and Getters 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, and 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: Multiple constructor overloading examples

February 28, 2022 ·  5 min read

In java, multiple constructors can be defined and overloaded. Constructors are used to initializing the fields of a class during object creation. Dart does not support an overload of functions and constructors and does not allow multiple functions/constructors of the same name with different arguments. A Dart class can have only one Default or unnamed constructor. Default constructor syntax: class Classname{ fields // default one construcotr Classname(fields) } default constructor Example...


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

February 28, 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 How to calculate the collection numbers sum example

February 28, 2022 ·  3 min read

Multiple ways to sum of numbers in Dart and flutter with examples List reduce method List fold method lists sum with primitive numbers Iterate list using map, and reduce to sum the object property The collection is a collection of elements in dart. For example, a List is one of the collections of items to store in insertion order. Dart Collection of the sum of numbers example There are multiple ways we can do the sum for the collection of numbers....


Dart| Flutter How to calculate the collection numbers sum example

February 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....


Dart| Flutter How to check element exists in Array

February 28, 2022 ·  1 min read

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


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

February 28, 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 a base64 class. This example converts the string into an encoded base64 string....


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

February 28, 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 file? This program explains about to get mime types of a file. The mime package provides a lookupMimeType function, that returns the 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 get File name and extension with example

February 28, 2022 ·  1 min read

The post is about how to get the name of the file in dart programming. Dart gets filename and extension There are multiple ways to get the name of the file using path package basename Import path/path.dart package into your code. Path package provides basename and basenameWithoutExtension properties to get name and extension. First, Create a file object. Pass file.path to those methods. Here is an example import 'dart:io'; import 'package:path/path....


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

February 28, 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 reverse a string example

February 28, 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: Check List is empty or not Example

February 28, 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. You can check another post, create an empty list in flutter...


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

February 28, 2022 ·  2 min read

This tutorial shows how to compare whether 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 is an immutable object, 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 the result, and the Original string also exists in memory....


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

February 28, 2022 ·  1 min read

This tutorial shows how to check if 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 the list into a set using the Set.of() method Check sub-list exists in Set using the 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: Check whether Map is empty or not Example

February 28, 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 the length is zero Find whether 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: Convert Map to Query String with example

February 28, 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. Convert Query String to Map, pass Map to queryParameters in the Uri constructor Convert Map to Query String using the Uri.splitQueryString() method 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 the Dart...


Dart| Flutter How to: Convert String into an array

February 28, 2022 ·  1 min read

This tutorial shows multiple ways to convert a String into an array or list in dart and flutter programming. Split the string into a list of characters using the String.split() method remove whitespaces using the trim method, and split using split() method Since Array does not support Dart. We will show you to convert to List only. Convert String into a list of characters List or Array of character String....


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

February 28, 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: Create an Empty List

February 28, 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: Create an Empty Map

February 28, 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 a null to improve null safety handling. How to create an Empty Map in Flutter or dart?...


Dart| Flutter How to: Create an Empty Set

February 28, 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 a 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: Filter search a list with examples

February 28, 2022 ·  3 min read

This tutorial shows multiple examples of 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. using Where predicate The List....


Dart| Flutter How to: Find a Given String is numeric or not

February 28, 2022 ·  2 min read

This tutorial explains How to check given string is a number or not. You can check my previous post, on How to Convert String to Number in dart. Dart How to check whether a String is Numeric or not This approach uses the parse method of double for floating and number for without decimals The tryParse method converts the string literal into a number. You can also use the parse method....


Dart| Flutter How to: Find an object implements interface

February 28, 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?...


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

February 28, 2022 ·  3 min read

This tutorial shows different ways to determine whether or not a set is empty in Dart or Flutter. 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 A set is one of the data structures to store the collection of elements without duplicates. You can check another post, How to create an empty Set in flutter...


Dart| Flutter How to: Flatten a List with examples

February 28, 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 a list of elements, where each element is again a list. After flatting the list, the result is...


Dart| Flutter How to: Function Return a function

February 28, 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: get First and Last Element from a List with Example

February 28, 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 How to: Insert an element at beginning of a List with Example

February 28, 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 The List insert method provides inserting an element at the index position....


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

February 28, 2022 ·  4 min read

A clone is a copy of an object. 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 the memory location Object(original) has a reference to memory location In general, Clone is of two types. Shallow Clone: In this copy process, data exists in the same location of a memory location, but creates two references pointing to the same memory location....


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

February 28, 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 a string always starts with zero and the end index is a string....


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

February 28, 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 method removeAt method removeWhere method 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, and returns true, if the element is removed from the list, else false is returned....


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

February 28, 2022 ·  1 min read

This tutorial explains how to read pubspec.yaml file in the example. pubspec.yaml file contains the 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 tutorial is about reading the puspect.yaml file and print the content....


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

February 28, 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 the string contains new line (\n) or tab(\t) characters,...


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

February 28, 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 First Create a Duration Object with one minute The 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: String replace method

February 28, 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: Convert List into String examples

February 28, 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 List to 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: Convert List of Dynamic into List of String examples

February 28, 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 and vice versa or vice versa in Dart and flutter....


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

February 28, 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 primitives 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: Difference between dynamic vs object with examples

February 28, 2022 ·  2 min read

dynamic and object are two predefined types in Dart dynamic is a dynamic type that accepts any type of value and disables type checking The object is a type that accepts any non-nullable types. This tutorial explains the difference between dynamic and object types in dart Difference between Dynamic and Object Let’s see the difference between dynamic and object with examples. Dynamic variables can be assigned with any type of value, and these variables can be assigned to any type of variable....


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

February 28, 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 and 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 add logging to an application with configuration and examples

February 28, 2022 ·  3 min read

This post explains how to add logging into dart and flutter applications. Logging is used to log different types of messages such as information, error, and debug messages, Helps developers to debug errors and issues. Currently, there are two types of popular libraries in Dart Dart logging Dart logger You can add these loggers in Dart and Flutter applications We are going to use the logging library in dart applications....


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

February 28, 2022 ·  1 min read

Sometimes, We want to find the installed version of Dart and the 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 the terminal gives the 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....


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

February 28, 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....


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

February 28, 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 the dynamic type also holds any type of data....


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

February 28, 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 the 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...


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

February 28, 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. The DateTime.parse() method creates a DateTime object using a formatted string....


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

February 28, 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’....


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

February 28, 2022 ·  2 min read

This tutorial shows multiple ways to create an immutable list in dart and flutter 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....


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

February 28, 2022 ·  3 min read

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


Enum Generics create, constrain type, and pass to a function in Dart | Flutter By Example

February 28, 2022 ·  2 min read

Enum in Dart introduced Generics to constants. Generics can be defined during enum declaration, Generics helps developer to avoid type safety errors. This tutorials explains multiple things How to create the type of a generic enum in Dart Constrain a generic type to an Enum Pass a Generic Enum argument to a method Create a Generic Type Object Enum Defined enum with generic and accepts String integer values enum EmployeeEnum<T> { name<String>(), salary<int>(); } void main() { print(EmployeeEnum....


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

February 28, 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....


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

February 28, 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 the developer to find the following things Check a runtime type of an object Object is assignable to another type using the is operator. Check the type of a variable declared in Dart or Flutter....


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

February 28, 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

February 28, 2022 ·  2 min read

This tutorial shows multiple ways to add leading zeroes to an integer number in Dart/Flutter programming. 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 an integer number with a given specific length on the left side or right side of a given number of digits...


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

February 28, 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....


How to add Methods or Values to Enums in Dart | Flutter By Example

February 28, 2022 ·  2 min read

How to add methods to Enum in Dart using Extension Dart 2.6 version, Extensions are added to classes, and Enum adds extra features. Defined Enum class as given below enum WEEK { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } Next, Add a method to Enum using the extension feature as given below Declare and place this extension in the same class where Enum is defined. extension WeekExtension on WEEK { bool get isWeekend { switch (this) { case WEEK....


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

February 28, 2022 ·  3 min read

In this tutorial, You will find multiple ways to add or subtract years, months, days, hours, minutes, or seconds. Add Date years, months, days, and time to DateTime add(Duration), Duration can be days, hours, minutes, or seconds. Subtract Date years, months, days and time to DateTime subtract(Duration), Duration can be 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 the Duration object DateTime add(Duration duration) Duration can be passed with days, hours, minutes, seconds, mill, and microseconds....


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

February 28, 2022 ·  1 min read

In these examples, Learn how to capitalize the first letter of a string or statement in Dart programming 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, the Written capitalizeFirstLetter function...


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

February 28, 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....


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

February 28, 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 concatenate two strings in a dart?| Flutter By Example

February 28, 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 The + symbol appends the first string with the second string and the result is appended string....


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

February 28, 2022 ·  2 min read

Convert Binary to Decimal in Dart: using int.parseInt(String, {radix: base}) method, base as 2 .int.parse('10011110', radix: 2); returns int value 158. Convert Decimal to Binary in Dart: use Number.toRadixString(2) method, For example: 158.toRadixString(2) returns binary value 10011110. 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....


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

February 28, 2022 ·  2 min read

Convert Hexa to Decimal in Dart: using int.parseInt(String, {radix: base}) method, base as 16 .int.parse('0009e', radix: 2); returns decimal value 158. Convert Decimal to Hexa in Dart: use Number.toRadixString(16) method, For example: 158.toRadixString(16) returns hexa value 9e. 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....


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

February 28, 2022 ·  2 min read

Convert Octal to Decimal in Dart: using int.parseInt(String, {radix: base}) method, base as 16 .int.parse('00702', radix: 8); returns octal value 450. Convert Decimal to Octal in Dart: use Number.toRadixString(8) method, For example: 450.toRadixString(8) returns octal value 702. 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....


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

February 28, 2022 ·  4 min read

This tutorial shows multiple ways to convert double to String or string to double in Dart and flutter programming languages. Convert Double to String in Dart: Double.parse method takes string number and returns adouble value. double.parse("111.12") returns 111.12. Throws FormatException if given string is non-numeric. Double.tryParse method takes string number and returns double value. double.tryParse("111.12") returns 111.12. Does not throw exception and returns null if the string is non-numeric....


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

February 28, 2022 ·  2 min read

In these tutorials, you will learn how to convert an enum to int or int to an 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...


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

February 28, 2022 ·  3 min read

This tutorial shows multiple ways to convert integers 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...


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

February 28, 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 code to convert from one type into another. How to convert List to Map in Dart or Flutter programming List....


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

February 28, 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 in insertion order and allow duplicate objects. The Set is a data structure to store a collection of elements and does not allow duplicates. Both are different types in Dart or Flutter, and We have to write code to convert from one type into another....


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

February 28, 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 Create and build a Singleton Class Dart or Flutter example| Dart By Example

February 28, 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 constant 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....


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

February 28, 2022 ·  1 min read

The 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 display greeting message on user time in Dart| Flutter by Example

February 28, 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. The 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....


How to do Integer division in dart | Flutter By Example

February 28, 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 a compilation error Error: A value of type ‘double’ can’t be assigned to a variable of type ‘int’....


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

February 28, 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 is, Convert the integer to a string using the toString() method Call length property to return the length of a string....


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

February 28, 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 values 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 Find the number of days and years between two dates Dart or Flutter | Dart by Example

February 28, 2022 ·  2 min read

This tutorial shows multiple ways to find the number of days between two dates. The difference between the DateTime object is using the Duration difference method, Duration.inHours is also used to find the difference between two dates in the number of hours. Find the Number of years between dates How to find the number of days between two dates in dart First Created two dates with the DateTime constructor and now() Next, find the difference between two dates using the difference() method....


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

February 28, 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...


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

February 28, 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 a 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

February 28, 2022 ·  2 min read

This example shows how to get the Current Date and time in the Dart or Flutter programming language. Current Date and time using the DateTime.now() function. Current Time without Date using the DateFormat.Hms().format() method Current Date only without hours minutes, Using DateFormat.yMd().format(dateTime); function. How to get the Current Date and time in Dart Dart provides the DateTime class to process Date and Time-related functions. The now() method returns the current date and time....


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

February 28, 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 the Count of milliseconds elapsed since 1970-01-01 PST. How to get the Current Epoch Timestamp in Dart/Flutter Dart provides the DateTime class to provide Date and Time-related functions....


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

February 28, 2022 ·  2 min read

This tutorial shows you multiple ways to get the Last Day of a Month and Year in Dart and Flutter. Contents How to get the Last Day of a month in Dart and Flutter How to get Last Day of a Year in Dart/Flutter How to get the Last Day of a Current Week in Dart/Flutter Conclusion How to get the Last Day of a month in Dart and Flutter The first way, Using Datetime....


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

February 28, 2022 ·  2 min read

DateTime.weekday returns an 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 week name such as Monday in Dart. How to get the name of the 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 iterate loop Enum in Dart | Get Enum with index in Flutter By Example

February 28, 2022 ·  2 min read

How to loop enum constants in Dart? How to get Enum with index in Dart? How to loop enum constants and index in Dart? Enum provides a values method that returns an array of Enum constants. You can iterate the enum using the following variations of for loop for in loop: Iterate each element and print to console forEach loop: Iterate each element and use element and index, prints to console....


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

February 28, 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 read input arguments from console Dart| Read a string from the console command line from a program

February 28, 2022 ·  2 min read

Multiple ways to read input arguments Dart and flutter with examples Read Command line arguments, using stdin.readLineSync(), convert try.parseIntmethod to convert as Integer. Read arguments as a string, use stdin.readLineSync() 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....


How to round double numbers with limit the numbers with decimal places in Dart/ Flutter By Examples

February 28, 2022 ·  1 min read

This tutorial shows you how to round double numbers with a limit to the precision. For example, if the double number is 12.12345, limit the number of decimal places from 3 to 12.123. Let’s see an example. Double-precision after decimal places in dart There are two ways we can convert double to limit decimal placesto n times. One way, use the double toStringAsFixed method. The toStringAsFixed method takes fractionDigits and returns the string representation of double numbers with decimal digits limit fractionDigits....


How to round double numbers with limit the numbers with decimal places in Dart/ Flutter By Examples

February 28, 2022 ·  1 min read

This tutorial shows you how to round double numbers with a limit to the precision. For example, the double number is 12.12345, limiting the number of decimal places from 3 to 12.123. Let’s see an example. Double precision after decimal places in dart There are two ways we can convert double to limit decimal places to n times. One way, use the double toStringAsFixed method. toStringAsFixed method takes fractionDigits and returns the string representation of double numbers with decimal digits limit fractionDigits....


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

February 28, 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 structure used to sort numbers. Consider the Employee Class which contains int, string, and DateTime properties as given. Employee class contains fields - id, name, salary, and joinDate The toJson() method returns the JSON of an object. class Employee { final int id; final String name; final int salary; final DateTime joinDate; Employee(this....


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

February 28, 2022 ·  2 min read

cascade operator is used to call a 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....


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

February 28, 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 [email protected]


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

February 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 expressions. 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, and 123....


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

February 28, 2022 ·  2 min read

This tutorial shows, 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 loads asynchronously before displaying it in the front end. The 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: Convert List to List in Dart| Flutter By Example

February 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 it asynchronously and display it in the 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....


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

February 28, 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 the value itself of type Enum. For example, WEEK....


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

February 28, 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....


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

February 28, 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 the 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....


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

February 28, 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. This post contains code, convert String into Date time using the Datetime.parse() method. Also, How we can convert the Date format to a different format using dateFormat.forma() method 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....


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

February 28, 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 of 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 periodically or Timer class In Synchronous execution, you can use the Sleep method to execute sequentially....


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

February 28, 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? You can make a private constructor using the _ operator to empty brackets (). Generally, a Private constructor allows you not to create an object or instance of a class....


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

February 28, 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...


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