0% found this document useful (0 votes)
3 views

flutter_exp1

flutter notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

flutter_exp1

flutter notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

FLUTTER

1. a) Install Flutter and Dart SDK.

Introduction:

Flutter:
Flutter is an open source framework for building beautiful, natively compiled, multi-platform
applications for mobile, web, and desktop from a single codebase.It is used to build applications
for Android, iOS, Windows, and the web.

Flutter is an open-source UI software development toolkit. Initially developed


from Google and now manages by an ECMA standard. Flutter apps use Dart programming
language for creating an app.

The first version of Flutter was announced in the year 2015 at the Dart Developer Summit. It
was initially known as codename "Sky" and can run on the Android OS.

Dart:
Dart is an open-source programming language which is widely used to develop the mobile
application, modern web-applications, desktop application, and the Internet of Things (IoT)
using by Flutter framework.
It is initially designed by the Lars bark and Kespar and developed by Google. Syntactically,
it is quite similar to Java, C, and JavaScript.

Features of Flutter:
The main features that make flutter frame work unique from other sdk’s are:

1. Cross-platform Development: With Flutter,we write the code once, maintain, and that
code can run on different platforms. Because these different platforms use the same
codebase. It saves the time, effort, and money of the developers.
2. Hot Reload: With this feature, we can see the changes instantly when we change the
code.
3. Open Source: Flutter is a free and open-source framework for developing mobile
applications.
4. Widget Library: In Flutter all of the elements you see in an app are Widgets. The Flutter
framework offers widgets, which are capable of developing customizable specific
designs.
Flutter has two sets of widgets: Material Design and Cupertino widgets
that help to provide a glitch-free experience on all platforms.
Install and Configure Flutter SDK and Dart SDK on Windows

Prerequisites:
Before diving into the setup process, ensure that you system meets the following prerequisites
on your system:

Hardware requirements

Your Windows Flutter development environment must meet the following minimal 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 4.0 52.0

Software requirements
To write and compile Flutter code for desktop, you must have the following version of Windows
and the listed software packages.

Operating system 64-bit Windows 7 or later

Disk Space 1.64 GB (does not include disk space for IDE/tools).

Tools Windows Powershell 5.0

Configure a text editor or IDE

You can build apps with Flutter using any text editor or integrated development environment
(IDE) combined with Flutter's command-line tools.

--Using an IDE with a Flutter extension or plugin provides code completion, syntax highlighting,
widget editing assists, debugging, and other features.

--Some Popular options include:


 Visual Studio Code 1.77 or later with the Flutter extension for VS Code.
 Android Studio 2023.3.1 (Jellyfish) or later with the Flutter plugin for IntelliJ.
 IntelliJ IDEA 2023.3 or later with the Flutter plugin for IntelliJ.

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.

Step 1: Install Flutter

1. Download Flutter SDK:


— Visit the [Flutter website](https://flutter.dev/docs/get-started/install) and

--Now download the appropriate Flutter SDK for your operating system (Windows, macOS, or
Linux).
2. Extract the SDK:
— Extract the downloaded file to a suitable location on your machine.
---- Create a folder where you can install Flutter.
-----Consider creating a directory at
C:\Users\{username}.
For example, you might place it in C:\Lenevo42\flutter on Windows.

3. Set/Update the flutter SDK Path:


— Add the Flutter SDK path to your system environment variables so you can run Flutter
commands from the terminal.
— On Windows through command prompt:
setx PATH "%PATH%;C:\src\flutter\bin"
or
Set path through Edit environmental variables for your account.
4. Verify Installation:
— Open a terminal or command prompt and run:

type flutter --version .

The flutter version and the dart version are displayed.

--Run flutter doctor

flutter doctor

This command checks your environment and displays a report of the status of your Flutter
installation.
Flutter Doctor help us to check that all flutter requirements are met. When you run Flutter
Doctor, you find some ✓ icons and some ✖ icons. These ✖ icons indicate that you need to do that
setup.

Step-2: Install Dart SDK in Windows


Step 1: Download Dart SDK.

Download Dart SDK from the Dart SDK archive page.

The URL is: Dart SDK Download(https://dart.dev/get-dart/archive)


Click on DART SDK to download SDK for Windows 64-Bit Architecture. The download will
start and a zip file will be downloaded.

Note: To download SDK for any other OS select OS of your choice.


Step 2: Extract the downloaded zip file. Extract the contents of downloaded zip file and after
extracting contents of zip file will be as shown:

Setting Path in Environment Variables


Step 3: Setting up path in environment variables. Open Environment Variables from advanced
system settings and add Path in System Variables as depicted in image:
Now we are done to use Dart from anywhere in the file system.

Step 4: Run Dart Using cmd

We can run dart from anywhere in the file system using command prompt.

Step 3: Install Visual Studio Code


Visual Studio Code (VS Code) is a popular and powerful code editor that supports Flutter
development through its extensions and integrated tools. In this article, we’ll go through the steps
to set up Flutter and start building a Flutter app using VS Code.

Step 1. Download and Install VS Code:


— Download Visual Studio Code from the [official website](https://code.visualstudio.com/).
— Follow the installation instructions for your operating system.
Step 2. Install Flutter and Dart Extensions:
— Open VS Code.
— Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side
of the window or by pressing `Ctrl+Shift+X`.
— Search for and install the Flutter extension by `Dart Code`. This extension will also install
the Dart extension.

Step 3: Create a New Flutter Project

1. Create Project Using VS Code:


— Open VS Code.
— Open the Command Palette by pressing Ctrl+Shift+P.
— Type Flutter: New Project and select it.
— Enter a project name (e.g., `flutter_demo`) and choose a location for your project.

ffff

2. Explore the Project Structure:


— The `lib/main.dart` file is the entry point for your application.

Step 4: Run Your Flutter App

1. Run the App:


— Open lib/main.dart in VS Code.

— Press `F5` to start debugging. This will build and run your app on the connected device or
emulator.
-----choose your connected device or browser from the list of devices to run your app.
— You should see the default Flutter counter app running.

Step 5: Modify the Default App

Let’s make some changes to the default Flutter app to understand how it works.
1. Open lib/main.dart:
----open the main.dart file located under lib directory.

2. Make a Simple Change:


— Update the `Text` widget to change the displayed message.
Text(
'You have clicked the button this many times:',
),
3. Hot Reload:
— Save the file and see the changes immediately in your running app thanks to Flutter’s hot
reload feature.

b) Write a simple Dart program to understand the language basics.

// This is a simple Dart program to demonstrate the basics

// Function to divide two numbers

double divide(double a, double b) {


if (b == 0) {
throw Exception('Cannot divide by zero');
}
return a / b;
}

void main() {
// Variables declaration
var name = 'Dart';
var year = 2011;
var isAwesome = true;
double num1 = 10;
double num2 = 0;
double quotient=0.0;
// Printing to the console
print('Hello, $name!'); // Output: Hello, Dart!
print('Dart was created in $year.'); // Output: Dart was created in 2011.
print('Is Dart awesome? $isAwesome'); // Output: Is Dart awesome?
true

// Control flow statements


if (year < 2020) {
print('Dart is relatively new.');
} else {
print('Dart has been around for a while.');
}

// Loop
for (var i = 0; i < 3; i++) {
print('Loop iteration: $i');
}

// Function definition
int add(int a, int b) {
return a + b;
}
// Print the results
if (num2 != 0) {
print('Division: $quotient');
}

var sum = add(5, 3);


print('Sum of 5 and 3 is $sum'); // Output: Sum of 5 and 3 is 8
try {
quotient = divide(num1, num2);
} catch (e) {
print(e);
}
}

Output:

Hello, Dart!
Dart was created in 2011.
Is Dart awesome? true
Dart is relatively new.
Loop iteration :0
Loop iteration :1
Loop iteration :2
Sum of 5 and 3 is 8
Exception: Cannot divide by zero

Running the Program:

You can run this Dart program using the Dart SDK. Save the code in a
file named calculator.dart, and execute it with the following command in
your command prompt.

dart calculator.dart

You might also like