Sage-Code Laboratory

Basics

Key concepts for beginners:

Install Flutter on Windows

Steps to install Flutter SDK on Windows:

  1. First, download and install the latest version of the Flutter SDK for Windows from the official Flutter website https://flutter.dev/docs/get-started/install/windows.
  2. Once the download is complete, extract the zip file to a suitable location on your computer.
  3. Next, add the path to the Flutter SDK to your system environment variables. To do this, open the Control Panel, go to System and Security, then click on System. Click on Advanced System Settings, then click on Environment Variables. Under System Variables, click on New and add a new variable named "Flutter" with the value of the path to the Flutter SDK.
  4. Next, download and install the latest version of Android Studio from the official website (https://developer.android.com/studio/).
  5. Open Android Studio and click on the Configure menu, then select the SDK Manager. Under the SDK Platforms tab, make sure that Android 11 (R) is installed. Under the SDK Tools tab, make sure that Android SDK Build-Tools, Android Emulator, and Android SDK Platform-Tools are installed.
  6. After installing the necessary tools, open a terminal or command prompt and type "flutter doctor" to check if everything is set up correctly. If there are any issues, the "flutter doctor" command, explained bellow, will provide suggestions on how to fix them.
  7. Finally, you can start creating Flutter apps on Windows by using Android Studio or any other code editor that supports Flutter development.
That's it! You have successfully installed Flutter on Windows and are ready to start building awesome apps.

In Flutter "flutter doctor" is a command-line tool that is used to diagnose and troubleshoot issues with your Flutter environment. Here are the steps to use "flutter doctor":
Doctor summary (to see all details, run flutter doctor -v): 
      [✓] Flutter (Channel stable, version 2.8.1, ...)  
      [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
      [✓] Chrome - develop for the web
      [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.5)
      [✓] Android Studio (version 2021.1)
      [✓] IntelliJ IDEA Community Edition (version 2021.2)
      [✓] VS Code (version 1.63.2)
      [✓] Connected device (1 available)
That's it! By using the "flutter doctor" command, you can quickly diagnose and troubleshoot any issues with your Flutter environment, ensuring that your app development process is smooth and efficient.

I present below the simplest flutter application:

//simple flutter app
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Text('Hello Hello'),
    );
  }
}
Responsive image

This is a simple Flutter app that displays a text message "Hello Hello" on the screen. The app is built using the Material Design framework, which provides a set of pre-designed widgets and components for building beautiful and responsive user interfaces.

The app code is written in the Dart programming language and consists of a main() function and a StatelessWidget class called MyApp. The main() function is the entry point of the app and calls the MyApp widget to run.

In general, any Flutter program starts by importing the Flutter package: import 'package:flutter/material.dart'; . Here, we imported the material.dart package. which represents Material Design, an Android-oriented design language created by Google. This package gives us the possibility of creating an Android-type visual user interface. Its components allow a reliable development working model to build Android applications according to Google specifications.

Next in the program we find the entry point of Flutter applications. This is the main() function which passes an object called MyApp as an argument the runApp function: runApp(MyApp()); . This has the effect of attaching the MyApp widget to the screen.

In the next lines we used a StatelessWidget widget for creating the UI, which doesn't maintain any state: class MyApp extends StatelessWidget . In this block, MyApp retuns a MaterialApp widget at the root level of the application and contains one important property named home. Home: It is the inner interface of the application, through which another widget, text type: Text('Hello Hello') is displayed on screen. The colon  :   signs that appear designate the use of named arguments.

The MyApp widget overrides the build() method, which is responsible for building the user interface of the app. In this case, the build() method returns a MaterialApp widget that sets the home property to a Text widget containing the message "Hello Hello". The MaterialApp widget also provides some basic configuration options for the app, such as the app title, theme, and other settings.

Overall, this simple app serves as a good starting point for learning Flutter app development, as it demonstrates how to build a basic user interface and use the Material Design framework.

I have modified the application below adding text styles:

//adding text styles
    import 'package:flutter/material.dart';
  
    void main() {
      runApp(MyApp());
    }
  
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Text('Hello Hello',
              style: TextStyle(
                  fontSize: 40,
                  color: Colors.blue[400],
                  fontWeight: FontWeight.bold,
                  fontStyle: FontStyle.italic,
                  decoration: TextDecoration.none)),
        );
      }
    }
In the snippet marked with yellow we define the text styles:

    home: Text('Hello Hello',
              style: TextStyle(
                  fontSize: 40,
                  color: Colors.blue[400],
                  fontWeight: FontWeight.bold,
                  fontStyle: FontStyle.italic,
                  decoration: TextDecoration.none)
                  ),
   
Responsive image

I present below another simple flutter application which contain a Scaffold widget with AppBarr :

//simple dart program
  
  import 'package:flutter/material.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          home: Scaffold(
              appBar: AppBar(
        title: Text('App bar'),
      )));
    }
  }
Responsive image

This is a simple Flutter program written in Dart language that displays an app bar on the screen. The program starts with the main() function that calls the MyApp() widget to run.

The MyApp widget is defined as a StatelessWidget and overrides the build() method to build the user interface. In this case, the build() method returns a MaterialApp widget that sets the home property to a Scaffold widget. The Scaffold widget is a basic container that provides the basic structure and functionality of the app, such as app bar, drawer, bottom navigation bar, etc.

Within the Scaffold widget, the program creates an AppBar widget with the title 'App bar'. The AppBar widget is the topmost widget that displays the title and any additional actions on the screen. It is typically used to provide navigation and actions for the app.

Overall, this program demonstrates how to create a basic app bar in Flutter using the Scaffold and AppBar widgets. With Flutter's flexible and customizable widgets, developers can create beautiful and functional user interfaces that meet the needs of their app.


I present below another simple flutter application which contain a Scaffold widget with AppBarr and body:

//simple dart program
  import 'package:flutter/material.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('App screen'),
          ),
          body: Center(
            child: Text(
              "Hello world",
              style: TextStyle(
                color: Colors.blue,
                fontSize: 50.0,
              ),
            ),
          ),
        ),
      );
    }
  }
Responsive image

This is a basic Flutter app that displays a single screen with a centered "Hello world" text in blue color and font size of 50.

The app consists of a main function that runs the app, and a stateless widget MyApp that defines the app's UI using the MaterialApp widget.

Inside the MaterialApp widget, there is a Scaffold widget that defines the layout structure of the screen. It contains an AppBar widget with a title of "App screen" and a body that centers the "Hello world" text inside a Center widget.

The style property of the Text widget is used to set the text color to blue and the font size to 50.0. Overall, this is a simple example of how to create a basic Flutter app with a single screen.


Back to: Flutter index