Category: Flutter Tutorials

Flutter Tutorials

  • Tutorial 3

    Tutorial 3

    [visual_code_viewer code=” app/
    └── Modules/
    └── HelloWorld
    ├── Http
    │   └── Controllers
    │   └── HelloWorldController.php
    ├── Models
    │   └── HelloWorld.php
    ├── resources
    │   ├── lang
    │   │   └── en.php
    │   └── views
    │   └── welcome.blade.php
    └── routes
    ├── api.php
    └── web.php“]

     

  • Statements & loops

    Statements

    Very often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this.

  • Variables & operators

    Variables

    Just like JavaScript, A variable can be defined with a var, const and final keywords and concatenate with sign ‘+’, let cant be use for variable it is used to use class return function , Please see below example

    [visual_code_viewer code=’import “package:flutter/material.dart”;
    void main() {
    runApp(const MyApp());
    }
    class MyApp extends StatelessWidget {
    const MyApp({super.key});
    @override
    Widget build(BuildContext context) {
    const var1 = “Variable 1”;
    final finalvar1 = “Final var1”;
    final finalvar2 ;
    finalvar2 = “Final var2”;

    return MaterialApp(
    title: “Welcome to Flutter”,
    home: Scaffold(
    appBar: AppBar(
    title: const Text(“Welcome to Flutter”),
    ),
    body: Center(
    child: Text(var1+”, “+finalvar1+”, “+finalvar2)
    ),
    ),
    );
    }
    }’]

    Operators

    Mostly we use below three operators

    1. Assignment operators
    2. Arithmetic operators
    3. Comparison operators
    4. Ternary Operator

    Assignment Operators

    Operator Meaning
    -= subtraction assignment
    /= divisions assigment
    %= modulo assignment
    += addition assignment
    *= multiplication
    ~/= integer division assignment
    >>= bitwise shift right assignment
    ^= bitwise XOR assignment
    <<= bitwise shift left assignment
    &= bitwise and assignment
    |= bitwise or assignment

    Arithmetic operators

    Operator Meaning
    + Add
    Subtract
    -expr Unary minus, also known as negation (reverse the sign of the expression)
    * Multiply
    / Divide
    ~/ Divide, returning an integer result
    % Get the remainder of an integer division (modulo)
    ++var var = var + 1 (expression value is var + 1)
    var++ var = var + 1 (expression value is var)
    –var var = var – 1 (expression value is var – 1)
    var– var = var – 1 (expression value is var)

    Comparison operators

    Operator Meaning
    == Equal
    != Not equal
    > Greater than
    < Less than
    >= Greater than or equal to
    <= Less than or equal to

    Ternary Operator

    Ternary operators can be defined as a conditional operator that is reasonable for cutting the lines of codes in your program while accomplishing comparisons as well as conditionals. This is treated as an alternative method of implementing if-else or even nested if-else statements. This conditional statement takes its execution from left to right. Using this ternary operator is not only an efficient solution but the best case with a time-saving approach. It returns a warning while encountering any void value in its conditions.

    Operator Meaning
    (( 3>2)?'Greater':'Less')
     return string “Greater”
    (( var1>finalvar1)??'Less')
    return true ,false
    (( var4)??'Test')
    return true if value is exists for variable var4 else print Test