flutter_exp1
flutter_exp1
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.
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.
Software requirements
To write and compile Flutter code for desktop, you must have the following version of Windows
and the listed software packages.
Disk Space 1.64 GB (does not include disk space for IDE/tools).
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.
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.
--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.
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.
We can run dart from anywhere in the file system using command prompt.
ffff
— 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.
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.
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
// 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');
}
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
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