IF Else & Nested IF Else Conditional Statement in Flutter Dart Example

In computer programming language Conditional Statement is important part for performing actions according to given condition. If condition is works based on Boolean True and False values. In normal If condition there are two parts If part and Else part. If the given condition is True then it will execute the If body part statements. If the given condition is False then it will automatically execute the Else part. IF condition is used to compare only 1 condition but if you have more than one condition then we will use Nested IF Else Conditional Statement in Flutter Dart Android iOS Example Tutorial. So let’s get started :).

IF Else Conditional Statement Syntax in Flutter Dart:

Nested IF Else Conditional Statement Syntax in Flutter Dart:

Contents in this project IF Else & Nested IF Else Conditional Statement in Flutter Dart Android iOS Example Tutorial:

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

2. Create our main Void main runApp() method and here we would call our main MyApp class.

3. Create our main MyApp class extends with StatelessWidget.

4. Create a function named as checkMethodSimple() with integer argument. Inside the function we would use the If condition and compare the given integer number with 100 and than execute the result. We are printing a Console message using Print method of Dart.

5. Creating another function named as checkMethodNested() with integer parameter. Inside the function we would use the Nested If Else conditional statement and compare multiple conditions.

6. Creating Widget build area in MyApp class. Now we would make a Scaffold widget and create a Column widget. We would also create 2 Raised Button widget wrap in Container widget in Column Widget. We would call each function on button onPress event.

6. Complete source code for main.dart file:

Screenshots:

IF Else & Nested IF Else Conditional Statement in Flutter Dart Example

Leave a Reply

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