Flutter 3 Variable Declaration, Initialization And Discuss With String😜

Introduction

Hi folks, the previous article has explained how to install flutter on windows in an easy way. This article will explain the first program after flutter setup, and variable declaration and initialization as well, so let’s start.

Dart 🤔

Dart is an open-source programming language for flutter. Dart is a client-optimized language for building the fastest mobile applications on any platform. Here are some powerful features of the Dart programming language and you already know dart and flutter were developed by Google.

Why Dart

  • Open Source
  • Hybrid Support (Windows, Linux, Mac, Android, IOS, Web Support) 🤯
  • Object-oriented 
  • Best Community and Easy to Learn and so on
  • Dart has tons of libraries.

What is Dartpad?

Dartpad is an open-source tool that lets you play with the dart programming language in any modern browser. Click here to access the dart pad.

Let's start with Hello World 🤩

Here is a simple dart program.

void main() {
    String name = 'Hello World';
    print(name);
}

In Detail…

Variable    Declaration      Variable Initialization
String            name         =     ‘Hello World’;

Variable Type Variable Name Assignment Value Terminator

Variable 🤔

Variable is used to store a value. In the above program, the string is a variable. And ‘name’ is name of the variable, any name you enter; in this case, we entered name. Enter a value for storing into the name, in my case we entered ‘Hello World’ and assigned our value into a name using the assignment operator.

Let’s Go Into Detail About Strings

A string is a sequence of characters. Dart accepts strings in single quotes or double-quotes. 

String Interpolation

String interpolation is the simple process of making a new string in an existing string called string interpolation. 

String Properties

String has three types of properties to perform various tasks.

  • codeUnits - Return UTF -16 of given string
  • isEmpty - If the given string is empty it returns true
  • Length - Length of the given string
  • And so on… Click Here for more properties.

void main() {
    String title = 'CSharpcorner';
    String empty = '';
    String notEmpty = 'This not a Empty String';
    print(title.codeUnits);
    print(empty.isEmpty);
    print(notEmpty.isNotEmpty);
    print(title.length);
    print(title.runes);
    print(title.runtimeType);
}

String Manipulation

So methods are used to manipulate the string. Here are some methods to manipulate strings. Click Here for more string manipulation methods.

void main() {
    String upperCase = "NAVIN PRAKASH";
    String lowerCase = "navin prakash";
    String trimWhitespace = "       Navinprakash       ";
    String replaceString = "String Replace";
    print(upperCase.toLowerCase());
    print(lowerCase.toUpperCase());
    print(trimWhitespace.trim());
    print("New String: ${replaceString.replaceAll('String Replace','All Strings are Replaced')}");
}

Conclusion

Thank you. In this article, we discussed dart strings, variable declaration and initialization. Please learn more about string properties and manipulation methods because there are a lot of available methods in dart. For the next article, we will discuss about more data types in dart. Thank you.


Similar Articles