Thursday, August 1, 2024

Flutter Basics and Let's start to code

 2.0

Folders

Lib -  Contain actual dart files

At start it is “main.dart” file , but as application grows you can create more folder structure

Android, MacOs , Linux, IOS -Folders comes in platforms names as this, contains platform specific files

Typically you do not need to do any changes – Flutter will take of that

Build – important folder – you won’t work here

Output files and temporary files generated by Flutter as it builds your app

Test – contains dart code - test code, automated test code for your app

.idea , .dart_tool – folders start with dot “.” Contains some extra configurations.

.idea – contain some extra configurations for Android Studio

.gitignore – version control file used by Git.  You don’t have to use Git, but don’t delete the file.

-          You cam manage snapshots

.metadata -  managed automatically by Flutter , keep track some internal information, meta data about your project.

You should not delete or Edit the file.

Analysis_option.yaml – configures some Flutter and Dart tooling that is used by code editor

-          To show you warnings and errors in code , before you even run the app

o   Amazing feature to catch errors early

-          You can dive into this file for customize.

Puspec.yml – ignore that -never managed file. You may edit when needed.

-          Add third party packages

-          Add images also

README.md – General Information about this project

-          short description about this project and resources

 

 

Flutter Code Compilation

From Top to Bottom

Code is compiled by various start and Flutter tools à and translated into native iOS and machine code ( understood by target platform)

Compiled code will executed on the mobile device

Understanding Languages

Two sections

-          Keywords

o   Import / void / const – basically highlighted or colored in Blue (depends on context , in VSCode blue, yellow for return …)

§  Built into programming language , reserved words

§  Have clear Specific meaning

-          Identifiers

o   Word as a developer defined yourself

§  Developed by developers of the programming language

§  To identify specific detail or block

·       Name given to a variable

·       Label in class in the program or function

 

Editor ( VsCode)

-          Colors for keywords and identifiers

o   Increase readability

-          Highlight error

 

 

Write First Code

-          You can edit main.dart

-          Here , we delete and start write from scratch

 

Start Write

runApp() ;  à Function

-          Funtion

o   Simply instructions that can be executed

 

 

runApp() is a function and instructions provided Flutter ( neither written by you nor built into Dart programming language )

 

-          All about getting App up and running

-          Actually to show some interfaces on the screen

-          But above will give error

-          Why

-          You need to wrap these functions to other Functions

-          We must create a custom function

-          In this case start with void and identifier must be main followed by parenthesis and opening and closing braces

 

Void main () { }

-          Void  - return type

-          Main – function name

-          { } between opening and closing braces , is Function Body

-          Code should executed when this function executed

 

              Those Functions are not executed by device (mobile ) or computer on which the code runs, unless you tell computer, device to Run the instructions

How

-          Using that instruction name

o   Followed by opening and closing parenthesis

 

Void main() {}  à Defining a function

RunApp() ; à Executing (or calling ) a function

 

Now Let’s put runApp() inside main

void main(){
              runApp(); -à The function runApp() isn’t defined.
}

 

Where should runApp(); come from
Remember runApp(); coming from Flutter. But Code editor does not know?
Goto pubspec.yaml à manage dependencies
This already has dependency for “Flutter”

dependencies:
  flutter:
    sdk: flutter
 

we need to import à

              import keyword within quotes/double quotes followed by ‘package’ and colon

import 'package:';

 

Then follow ‘flutter’ 

import 'package:flutter';

 

use arrow keys to select and TAB to finish.

import 'package:flutter/material.dart';

 

Questions

What's the most important folder, in which you'll work most of the time, in a Flutter project?

The “lib” folder

Which file is the entry point for a Flutter application?

Lib/main.dart

What is the main purpose of the Dart compiler?

Convert Dart code into machine code that can run on various platforms

What are functions in programming?

    Sequence of Instructions that perform specific task.

How do you import a package in a Dart file?

    Import “package_name”

Which key "elements" are involved in the startup process of drawing a UI onto the device screen?

    The main function and the runApp() function

 

Now code looks like

 

import 'package:flutter/material.dart';
 
void main(){
  runApp();
}
 
 

But still has an error __-> 1 positional argument expected by 'runApp', but 0 found.

 

Flutter code build with widgets and you will end up with Widget tree.

1.     Material App -root app require by most other widgets

a.     Scaffold – Screen layout widget that adds base styling and more

                                               i.     Row -  Widget that displays multiple adjacent child widgets

1.     Text – Widget that displays some Text on screen

2.     Text

3.     Text 

 

 

 

Wednesday, July 31, 2024

JavaScript

 What is JavaScript?

What Can you do with it?

Where does JavaScript code run?

Difference between JavaScript and ECMA Script ?


 What is JavaScript?

One of the most popular scripting languages used by most popular companies

What Can you do with it?

In past JavaScript used in browsers to build interactive web pages as toy language .

Today we have huge community support and Industry contributions (FB,Google..)

Used to create full blown Webs, Mobile apps, real time networking apps, command line tools , games.

Where does JavaScript code run?

Originally designed to run in Browsers. So all browsers has JavaScript Engine - execute JavaScript code.

JavaScript engines in FireFox -> SpiderMonkey , Chrome -> V8

 In 2009 --> Brian Doll

Took the open source JavaScript engine from Chrome and embedded inside C++ program. --> Node

With this we can run JavaScript outside Browser

Summary 

JavaScript can be run inside Browser or Node.

Difference between JavaScript and ECMA Script ?

ECMA - Specification - define standard ( European Computer Manufacturers Association )

JavaScript is the language - which confirms this ECMA specification.

First Spec released on 1997 then after 2015,2016.... 

1997 - v1

2015 - ES2015/ES6


Let's try JavaScript in Browser 

Open browser , click anywhere and go to Inspect --> dev tools

write

> console.log('Hello World');

Press Enter

Hello World

> 2+2

< 4



Sunday, July 28, 2024

Flutter

 

What is Flutter

 

Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase.

https://flutter.dev/

 

Original author(s)

Google

Developer(s)

Google and community

Initial release

Alpha (v0.0.6) / May 12, 2017; 7 years ago[1]

Stable release

3.22.0[2] Edit this on Wikidata / 14 May 2024; 2 months ago

Repository

Written in

C, C++, Dart[3]

Platform

Android, iOS, Google Fuchsia, Web platform, Linux, macOS and Windows

Type

Application framework

License

New BSD License

Website

flutter.dev

 

https://en.wikipedia.org/wiki/Flutter_(software)

 

 

Install Flutter

https://docs.flutter.dev/get-started/install

Follow the link and get the installation kit which is suitable for your developemnt with respect to OS.

 Widows

https://docs.flutter.dev/get-started/install/windows

 

Use recommended Android

https://docs.flutter.dev/get-started/install/windows/mobile

Follow the instructions in the given page

system requirements

 

Hardware requirements

 

Requirement

Minimum

Recommended

x86_64 CPU Cores

4

8

Memory in GB

8

16

Display resolution in pixels

WXGA (1366 x 768)

FHD (1920 x 1080)

Free disk space in GB

11.0

60.0

 

Software requirements

Note: you do not need to install DART separately as Flutter sdk include full DART sdk.

Operating system

1.       64-bit version of Microsoft Windows 10 or later.

2.       Windows should include the required Windows PowerShell 5 or later

Development tools

·       Git for Windows 2.27 or later to manage source code.

·       Android Studio 2023.2.1 (Iguana) or later to debug and compile Java or Kotlin code for Android. Flutter requires the full version of Android Studio.

Configure a text editor or IDE

 

Recommended

The Flutter team recommends installing Visual Studio Code 1.77 or later and the Flutter extension for VS Code. This combination simplifies installing the Flutter SDK.

 

Install the Flutter SDK

Follow the guide on website.

https://docs.flutter.dev/get-started/install/windows/mobile#development-tools

You have two options

  1. Use VS Code to install
  2. Down Flutter and install manually

Important points

1.       Install VS code with Flutter extension for VS Code.

2.       Configure the Android toolchain in Android Studio

3.       Configure your target Android device

a.       Virtual Device

b.       Physical Device

4.       Agree to Android Licenses

5.       Check your flutter development set up

a.       Run Fluter doctor with below command

b.       PS C:> flutter doctor

6.       Troubleshoot Flutter doctor issues

a.       Run Flutter doctor with verbose with below command

b.       PS C:> flutter doctor -v

 

Start developing Android on Windows apps with Flutter

Follow the below links in Flutter documentation

 

Manage your Flutter SDK

To learn more about managing your Flutter SDK install, consult the following resources.

Flutter Doctor Issues And Solutions


Error in Running Flutter Project

 

C:\Project\MyProject\Waste\1>flutter create app_1

Creating project app_1...

Resolving dependencies in `app_1`... (1.4s)

Downloading packages...

Got dependencies in `app_1`.

Wrote 129 files.

 

All done!

You can find general documentation for Flutter at: https://docs.flutter.dev/

Detailed API documentation is available at: https://api.flutter.dev/

If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

 

In order to run your application, type:

 

  $ cd app_1

  $ flutter run

 

Your application code is in app_1\lib\main.dart.

 

 

C:\Project\MyProject\Waste\1>flutter run

Error: No pubspec.yaml file found.

This command should be run from the root of your Flutter project.

 

C:\Project\MyProject\Waste\1>cd  app_1

 

C:\Project\MyProject\Waste\1\app_1>flutter run

Connected devices:

Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22631.3880]

Chrome (web)      • chrome  • web-javascript • Google Chrome 127.0.6533.73

Edge (web)        • edge    • web-javascript • Microsoft Edge 127.0.2651.74

[1]: Windows (windows)

[2]: Chrome (chrome)

[3]: Edge (edge)

Please choose one (or "q" to quit): 1

Launching lib\main.dart on Windows in debug mode...

Error: Unable to find suitable Visual Studio toolchain. Please run `flutter doctor` for

more details.

 

C:\Project\MyProject\Waste\1\app_1>flutter doctor

Doctor summary (to see all details, run flutter doctor -v):

[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.22631.3880],

    locale en-US)

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)

    X cmdline-tools component is missing

      Run `path/to/sdkmanager --install "cmdline-tools;latest"`

      See https://developer.android.com/studio/command-line for more details.

    X Android license status unknown.

      Run `flutter doctor --android-licenses` to accept the SDK licenses.

      See https://flutter.dev/docs/get-started/install/windows#android-setup for more

      details.

[√] Chrome - develop for the web

[X] Visual Studio - develop Windows apps

    X Visual Studio not installed; this is necessary to develop Windows apps.

      Download at https://visualstudio.microsoft.com/downloads/.

      Please install the "Desktop development with C++" workload, including all of its

      default components

[√] Android Studio (version 2023.2)

[√] VS Code, 64-bit edition (version 1.88.1)

[√] Connected device (3 available)

[√] Network resources

 

! Doctor found issues in 2 categories.

 

 

1.      cmdline-tools component is missing

 

When you run Flutter doctor

Below is the Output

C:\Project\MyProject\Waste\1\app_1>flutter doctor

Doctor summary (to see all details, run flutter doctor -v):

[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.22631.3880],

    locale en-US)

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)

    X cmdline-tools component is missing

      Run `path/to/sdkmanager --install "cmdline-tools;latest"`

      See https://developer.android.com/studio/command-line for more details.

    X Android license status unknown.

      Run `flutter doctor --android-licenses` to accept the SDK licenses.

      See https://flutter.dev/docs/get-started/install/windows#android-setup for more

      details.

[√] Chrome - develop for the web

[X] Visual Studio - develop Windows apps

    X Visual Studio not installed; this is necessary to develop Windows apps.

      Download at https://visualstudio.microsoft.com/downloads/.

      Please install the "Desktop development with C++" workload, including all of its

      default components

[√] Android Studio (version 2023.2)

[√] VS Code, 64-bit edition (version 1.88.1)

[√] Connected device (3 available)

[√] Network resources

 

! Doctor found issues in 2 categories.

 

 

 

Resolve First Problem: Android Command Line tool

Android toolchain - develop for Android devices (Android SDK version 35.0.0)

    X cmdline-tools component is missing

      Run `path/to/sdkmanager --install "cmdline-tools;latest"`

      See https://developer.android.com/studio/command-line for more details.

 

Solution

https://stackoverflow.com/questions/68236007/i-am-getting-error-cmdline-tools-component-is-missing-after-installing-flutter

The solution for me was opening Android Studio and going to SDK Manager, switch to the SDK Tools tab and check Android SDK Command-line Tools (latest).

 

Don't forget to add to your PATH the tools and platform-tools folder that are inside your SDK.

Eg: Open Edit Environment PATH variables and add

1.     First Path is path for Flutter SDK

2.     Other two are for the platform

C:\Users\Gest\dev\flutter\flutter\bin

C:\Android\Sdk\platform-tools

C:\Android\Sdk\platforms

 

2.      Accept Licenses

After resolving above issue, Now let’s run Flutter doctor again

You will see Next issue

Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

 

C:\Project\MyProject\Waste\1\app_1>flutter doctor

Doctor summary (to see all details, run flutter doctor -v):

[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Version 10.0.22631.3880], locale en-US)

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)

    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[√] Chrome - develop for the web

[X] Visual Studio - develop Windows apps

    X Visual Studio not installed; this is necessary to develop Windows apps.

      Download at https://visualstudio.microsoft.com/downloads/.

      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.2)

[√] VS Code, 64-bit edition (version 1.88.1)

[√] Connected device (3 available)

[√] Network resources

 

! Doctor found issues in 2 categories.

 

Solution

Run Accept license command

flutter doctor --android-licenses  and Type “y” for all.

You will finally see

Accept? (y/N): y

All SDK package licenses accepted