Flutter Dart Create Call Static Variables Static Methods Example

Static variables and Static methods are used to reduce memory usages in any programming languages. Static variables can create once and used many times without creating class Object. So Static variables and get memory once on declaration time. Static variables and Static methods are called without object directly with Class name with Dot operator. Static variables are also known as Class variables. Static methods are also known as Class methods. So in this tutorial we would learn about Flutter Dart Create Call Static Variables Static Methods Android iOS Example Tutorial.

Contents in this project Flutter Dart Create Call Static Variables Static Methods Android iOS Example Tutorial:

1. Import material.dart package in your app’s main.dart file.

2. Creating void main runApp() method and here we would call our main MyApp main class.

3. Creating a class named as Holder. In this class we would make a Static Double variable named as number and a Static function named as message. We are simply printing a message on Terminal screen using Print function.

4. Creating our main MyApp class extends with StatelessWidget. This is our main Widget View class.

5. Creating 2 function named as callStaticMember() and callStaticFunction(). In first function we would printing Static double variable on terminal screen and in other function we would call the message function with class name.

Note: To call the Static function and Static member variable we would use Class name + Dot operator + Variable Name or Function name Syntax.

6. Creating Widget Build area in MyApp class. Now we would make 2 Raised Buttons widget and call above declared both function onPress event.

7. Complete source code for main.dart file:

Screenshots: Flutter Dart Create Call Static Variables Static Methods Example

Flutter Dart Create Call Static Variables Static Methods Example

Leave a Reply

Your email address will not be published. Required fields are marked *