0% found this document useful (0 votes)
61 views48 pages

Flutter Variable Naming and Basics

This document provides guidance on learning Flutter including recommended documentation resources and tutorials. It also includes notes on Flutter style conventions, key concepts, and code snippets. Key recommendations include letting Ali teach, learning Dart basics independently, and reviewing the online Flutter documentation for tutorials and references. The document aims to help new developers get started with Flutter.

Uploaded by

lava bhai
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)
61 views48 pages

Flutter Variable Naming and Basics

This document provides guidance on learning Flutter including recommended documentation resources and tutorials. It also includes notes on Flutter style conventions, key concepts, and code snippets. Key recommendations include letting Ali teach, learning Dart basics independently, and reviewing the online Flutter documentation for tutorials and references. The document aims to help new developers get started with Flutter.

Uploaded by

lava bhai
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

FLUTTER & E-Notes

Learning strategy:
 Let Ali teach
 In the meanwhile, Learn dart basics by yourself.
 [Link]
 [Link]
 For help getting started with Flutter development, view the [online
documentation] ([Link] which offers tutorials,
samples, guidance on mobile development, and a full API reference.

NOTES:
1. Name of classes in upper Camel case, e.g. CamelCase
2. Material App provides material UI for Google Apps Look & Feel.
3. Scaffold is a class in flutter which provides many widgets or we can
say APIs like Drawer, SnackBar, BottomNavigationBar,
FloatingActionButton, AppBar, etc. Scaffold will expand or occupy
the whole device screen. It will occupy the available space.
4. Type parameters start with lower case.
5. Screen with input fields will have their respective controller made
inside the respective screen class.
6. Underscore before a variable name makes it private for that class.
7. Dart DOES NOT provide keywords like: “Public”, “Private” &
“Protected”
8. Null safety is checked by either placing ! or ??
9. In Dart, we use the late keyword to declare variables that will be
initialized later. These are called non-nullable variables as they are
initialized after the declaration. Hence, we use the late keyword.
Note: Once we declare a non-nullable late variable, the variable can’t be null at
runtime.
[Link] b/w var and dynamic DATATYPES in DART:
[Link]
4d6d19794532#:~:text=If%20a%20variable%20is%20declared,type%20can
%20change%20over%20time.&text=If%20you%20declare%20variable%20as,assigned
%20type%20can%20not%20change.

Syntax

late data_type variable_name;

[Link]
11. final vs const keyword: [Link]
marked-as-final-in-flutter-custom-classes/#:~:text=A%20variable
%20with%20the%20final,method%20will%20be%20initialized
%20again.
12. Var; open data type to store data of any type.
13. ObjectBox flutter
database [Link]
14. Future ?

15.
A variable of type double cannot be assigned to type int, three is a VAR:

16.
17. ALI PLZ FIND ERROR IN BELOW:
List: List data type is similar to arrays in other programming languages. A list is
used to represent a collection of objects (can be a heterogenous collection) . It is
an ordered group of objects.

myList is growable but myList2 is not:


Growable, integer specific myList:
Now default value set to String:

Sorts in ascending:
Sorts in descending:

[Link]
[Link]
in-dart/?ref=rp
[Link]
Lambda functions:
are a short and simple way to express tiny functions. Lambda functions
are also known as arrow functions. Like any other function, a Lambda
function cannot execute a block of code. (Source:
[Link]
dart-programming )

Dart Constructors
 [Link]
 [Link]
dart_programming_classes.htm#
 Named Constructor and initializer list:
Cascading Operators: ([Link]
dart-cascade-notation )
Keyboard Shortcuts:
1. Ctrl + j closes & opens up terminal
2. Ctrl + f5 runs a program.
3. Ctrl + b: closes left side menu
4. Ctrl + Shift + p to install new dependencies
5. Alt + Shift + r to open a file in File Explorer
6. Ctrl + Alt + L; Auto Format in Android Studio
7. Alt + Enter; shows you possible widgets to wrap a child widget

Dart/Flutter Shortcuts:
1. We run “flutter pub get” to get all the dependencies listed in
the [Link] file in the current working directory, as well as
their transitive dependencies.
2. dart fix --dry-run; lets you see all of the proposed quick fixes.
3. dart fix --apply; will apply all of those fixes.
Types of Buttons in flutter:
1. Elevated Button:
[Link]

2.

ICONS:
SMD-MID-1 LACKINGS:
1. RunApp(): The runApp() method in Flutter is used to start the execution of a Flutter
application. It takes a Widget as its argument, which represents the root of the widget
tree that makes up the app's user interface. The runApp() method creates a new
FlutterBinding instance, which initializes the framework and starts the rendering
pipeline. It also creates a WidgetsBinding instance, which manages the lifecycle of the
widget tree and handles input events and other system messages. By calling the
runApp() method, the developer signals to the Flutter framework that the app is ready
to be started, and the framework takes care of the rest of the setup and initialization.
2. Asynchronous data: Asynchronous data in Flutter refers to data that is not immediately
available and may take some time to load or fetch. This type of data is typically loaded
from a remote server or other external source, and its availability is not guaranteed at
the time the application is running.
In order to handle asynchronous data in Flutter, the framework provides several tools
and mechanisms, including Futures, Streams, and async/await syntax. Futures represent
a value that may not be available yet, and they allow developers to write code that
waits for a value to become available before continuing execution. Streams, as
mentioned in the previous answer, allow developers to handle sequences of data that
arrive over time, such as data from a network connection.
The async and await keywords are used to write asynchronous code in a more
synchronous style, making it easier to read and write. The async keyword is used to
define a function that performs asynchronous operations, and the await keyword is
used to pause the execution of a function until a Future completes.
Overall, asynchronous data is an important concept in Flutter, as it allows developers to
build apps that are responsive and can handle data that is not immediately available.

3. Streams: In Flutter, streams are a way of handling asynchronous data. A stream is a


sequence of data that is continuously emitted over time, and it can be listened to by
multiple listeners at the same time. Streams are useful for handling events, data that
arrives over a network connection, or any other data that arrives over time and can't
be fetched synchronously.
In Flutter, the Stream class is used to represent a stream of data. Streams can be
created using the StreamController class, which allows developers to add data to a
stream and notify listeners when new data is available. To listen to a stream, developers
can use the StreamBuilder widget, which automatically rebuilds its child widget
whenever new data is emitted by the stream. Alternatively, they can use the listen()
method on a stream, which allows them to register a callback function that is called
whenever new data is available.
Streams are a powerful concept in Flutter and are widely used throughout the
framework, including for handling user input, managing state, and interacting with
external services.

4. Life Cycle of Stateful Events:


In Flutter, the lifecycle of a StatefulWidget is as follows:
i. createState(): This method is called when the widget is first created and the
framework creates a corresponding state object.
ii. initState(): This method is called once after the state object has been
created, and it is where developers can initialize any state data that the
widget needs.
iii. didChangeDependencies(): This method is called after initState(), and it is
where the widget can initialize any state data that depends on other
widgets in the tree.
iv. build(): This method is called whenever the widget needs to be rebuilt,
such as when the state data changes or when the widget is inserted into
the tree.
v. didUpdateWidget(): It is called whenever the parent widget rebuilds and
can be used to update the state of the widget based on any changes in the
parent widget's properties.
vi. setState(): This method is used to update the state of the widget,
triggering a rebuild of the widget.
vii. deactivate(): This method is called when the widget is removed from the
tree, allowing the widget to clean up any resources it was using.
viii. dispose(): This method is called when the state object is being destroyed,
allowing the widget to release any resources it was using.
Overall, this lifecycle allows developers to manage the state of a widget and to
ensure that it is updated and rendered correctly as the app changes and evolves
over time. By properly managing the state of their widgets, developers can build
apps that are responsive, efficient, and easy to maintain.

5. initState():
6. BuiltContext(): The BuildContext class in Flutter is used to provide information about
the location of a widget within the widget tree. It is a fundamental part of the Flutter
framework and is used extensively throughout the API.
The BuildContext class provides a number of methods that allow widgets to interact
with their parent and child widgets in the tree. For example, the BuildContext can be
used to retrieve the Theme data, the MediaQueryData for the device, or the Navigator
for the app.
The BuildContext is typically passed as an argument to widget constructors, allowing
them to access the context of the widget in which they are being built. It is also used to
build child widgets within the build() method of a widget.
It's worth noting that the BuildContext is immutable and can't be modified directly by
the widget. Instead, it is used to provide information and context to the widget and its
children, allowing the framework to manage the widget tree and ensure that the app is
rendered correctly.

7. Performant: Making a Flutter app performant means optimizing the app's performance
to ensure that it is fast, responsive, and efficient. This involves reducing the app's
startup time, minimizing the app's memory usage, and optimizing the app's rendering
performance.
To achieve optimal performance, developers should follow best practices such as using
efficient data structures, avoiding unnecessary rebuilds of widgets, minimizing network
requests, and reducing the size of assets and resources.
Some specific techniques that can be used to improve the performance of a
Flutter app include:
i. Using asynchronous programming techniques, such as Futures and
Streams, to minimize blocking the main thread and ensure that the app
remains responsive.
ii. Utilizing state management techniques, such as Provider or BLoC, to
manage the app's state in a centralized and efficient way.
iii. Optimizing the app's rendering performance by minimizing the number of
widgets that need to be rebuilt and reducing the complexity of widget
trees.
iv. Minimizing the app's memory usage by avoiding unnecessary object
allocations, using efficient data structures, and minimizing the size of assets
and resources.
v. By following these best practices and techniques, developers can create
Flutter apps that are fast, responsive, and efficient, providing a great user
experience for their users

8. Declarative Framework:
9. Reactive Programming:
[Link] between network image and [Link]: In Flutter, both
NetworkImage and [Link] are used to load images from a network resource,
but they differ in their usage and behavior.
NetworkImage is a class that creates a widget that displays an image from a URL. It's
typically used when the image is the primary content of the widget, such as in an Image
widget or inside CircleAvatar, backgroundImage property. It requires a valid URL to the
image resource, and the image is loaded asynchronously, so it may take some time to
appear on the screen. NetworkImage is also useful when you need to manipulate the
image in some way, such as decoding and resizing the image.
On the other hand, [Link] is a widget that takes a URL as an argument and
displays the corresponding image on the screen. It's typically used as a child widget of
another widget, such as a Column or ListView, and can be used to display multiple
images in a single view. Like NetworkImage, the image is loaded asynchronously, and
the widget will update itself automatically once the image has loaded.
The main difference between the two is that NetworkImage is a widget builder, which
can be used to create an Image widget, while [Link] is a widget itself that can
be used directly in the widget tree.
In summary, NetworkImage is a class that creates an ImageProvider that can be used to
create an Image widget, while [Link] is a widget that can be used directly to
display an image.

[Link]/Show Widgets: The Visibility widget is used to show or hide widgets in Flutter
based on a given condition. It takes a visible parameter that specifies whether the child
widget should be visible or hidden, and also provides options for controlling the space
occupied by the child widget when it is hidden.
Here's an example of how to use Visibility widget to show or hide a child widget based
on a boolean value:
dartCopy code
bool isVisible = false;
Visibility(
visible: isVisible,
child: Text('This text will be visible if isVisible is true'),
)
In this example, the Text widget will only be visible if isVisible is true. If isVisible is false,
the Text widget will be hidden, but its space will still be reserved in the layout. If you
want to completely remove the space occupied by the hidden widget, you can set the
maintainSize parameter to false:
dartCopy code
Visibility(
visible: isVisible, maintainSize: false,
child: Text('This text will be hidden along with its space when isVisible is false'),
)
In this example, the space occupied by the Text widget will be removed when isVisible
is false, so other widgets in the layout will move up to fill the space. This can be useful
for creating dynamic layouts where the size and position of widgets can change based
on user interactions or other conditions.

[Link] Dart Language Tour: [Link]


[Link] ki hgt and width properties nahe hotein, we wrap it inside a SizedBox to give hgt
and width properties.

Basic Development with Flutter!


Course: By 10 Pearls

+ Center
 ROW and COLUMN are not scrollable widgets, they are just confined
on the screen size available.
 For scrollable widgets use ListView.
Getting Started with Flutter!
Course: By 10 Pearls
Loops in dart:
1. For
2. For..in
3. While
4. Do While

Functions in dart:
Example 3 has optional Positional parameter [int c]
Mixin? And Enum classes?
[Link]
does-underscore-before-variable-name-mean-for-flutter

Point 2 unclear
Inhertance in flutter:
[Link]
%20inheritance%2C%20a%20class,only%20a%20single%20parent
%20class.&text=Here%2C%20the%20child%20class%20can,own
%20unique%20properties%20and%20methods.&text=In%20the
%20above%20example%2C%20we,and%20inherited%20the%20Parrot
%20class.
Basic Development with Flutter Cont’D –
10 Pearls University
Refer: Basic Development with Flutter project from folder and tasbeeh project
//Adding Date Picker:
initialDate is our attribute of state class, which we are changing
whenever the button is pressed to select Date.
//Adding Time Picker:
initialTime is our attribute of state class, which we are changing
whenever the button is pressed to select Time.

//Adding Text Formfield


//Dialogs
//Drawer

The ListView widget supports horizontal lists. Use the standard ListView
constructor, passing in a horizontal scrollDirection , which overrides the default
vertical direction.

//[Link](ten_pearls_app project)
 Made a class of course
 Made a List of type course inside state class, and initialized attributes.
 Inside body, used [Link]:
//[Link]: includes Divider()

Callback Functions (need more explanation)


 Mostly used while handling events.
 [Link]
functions/
 [Link]
flutter-89dc207cba37

ANGELA YOU COURSE


Section: Intro
EXTRACTING A SCREEN FROM ALREADY BUILT
APPLICATION

1. Create a new project


2. Copy Assets, Lib, Fonts and [Link] file contents from
original project to new project.
Miss Angela’s course cont’d
Lecture: 03
Video: 024;
 I am rich app;
 MaterialApp(); Material App provides material UI for Google Apps
Look & Feel.
 MaterialApp(home: ); what widget the homepage of our app will
contain.
Making the text to appear at center of screen:

 Center widget centers anything/widget that is contained in it.


Lecture: 04
Video: 026;

 We used Scaffold widget followed by Appbar, Color and Center


widgets.
 We also used properties of AppBar like: title, backgroundColor.
 Properties of Scaffold like: body, with Centre widget wrapped around
[Link] widget.
Miss Angela’s course cont’d
Lecture: 05
Video: 027;
In this video we learnt how to add images from a
directory (folder we create) inside the project.
How to make changes in yaml file to add a folder
as assets that contain our images.
 Always put 2 spaces from gutter
 Be careful of indentation while updating yaml
file.
 If had error then delete the comments.
 Run “pub get” after changing yaml file

Module: 5 “I am Poor”
Lecture: 06
Video: 034;
 App Challenge; made my app: “I am very Rich- RUBY”

Module: 6 “MiCard”
Video: 039;
 Taught how to clone a project from Github

 Video: 040;
 Hot reload & hot restart.
 Video: 041;
 Layout widgets:
[Link]
1. Single child layout widgets: Sets layout for a SINGLE child widget
ONLY, e.g. Container, Padding, Margin.
2. Multi child Layout widgets: Sets layout for a MULTIPLE child widgets
e.g. Row, Coloum etc.
3.

Container (similar to div in html)


 If it doesn't have a child, it won't show on the screen. (QUIZ)
 A SafeArea widget encapsulates a child widget so that the child
widget does not hides itself behind screen notch, bezel or any
screen component like clock etc.

 Margin: is for the outside of your widget.


 Padding: is for the inside (child) of your widget.

 Both margin and padding properties use “EdgeInsets” widget to


customized themselves.
 Video: 042;
“How to use Column & Row Widgets for
Layout”
 Video: 043;
“FLUTTER Layout Challenge”

 Video: 045 “Using Custom Fonts”;


“MiCard”
Steps:
1. Download the loved font from
[Link]
query=source+sans
2. Unzip the files.
3. Make a new directory named “fonts” directly INSIDE the
project folder.
4. Drag the respective font ttf file in it.
5. Inside yaml file, include the respective fonts and keep a close
eye on INDENTATION (Refer:
[Link] )
6. Run “pub get”
7. Run “get Dependencies” in [Link]

 Video: 046 “Adding Material Icons with Icon


Widget - MiCard”

 Video: 047 “Flutter Card & ListTile Widgets -


MiCard”
 Card provides rounded corners.

Common questions

Powered by AI

Asynchronous data handling in Flutter is essential for building responsive applications that can manage data fetching and processing without blocking the UI thread. Flutter provides several tools to achieve this: Futures, Streams, and the async/await syntax. Futures allow developers to work with values that may not be immediately available, effectively handling asynchronous operations. Streams manage sequences of data over time, which is useful for events or data that arrives intermittently. The async/await syntax provides a more readable and synchronous-looking way to handle asynchronous code, improving code maintainability. These tools enable developers to create Flutter apps that efficiently handle data loading, ensuring smooth user experiences .

The 'StreamBuilder' widget in Flutter enhances real-time data handling by offering a reactive user interface component that listens to a Stream and rebuilds parts of the UI whenever a new data event occurs. It provides a declarative approach to synchronizing the application state with asynchronous data sources. By using the StreamBuilder, developers can manage dynamic data flows, such as user input or network data, allowing automatic UI updates when new data emerges. This capability is pivotal for apps that need to respond to continuously changing data without manual intervention .

Performance optimization in Flutter applications is crucial to ensuring that apps are fast, responsive, and efficient, directly affecting user satisfaction and engagement. Optimization strategies include using asynchronous programming to keep the main thread unblocked, employing efficient state management solutions like Provider or BLoC, optimizing rendering by reducing unnecessary widget rebuilds, and managing app loading times by minimizing asset sizes. These practices, along with effective use of memory through reduced object allocations and efficient data structures, are essential in building applications that run smoothly and provide a seamless user experience .

The 'Scaffold' widget is a fundamental class in Flutter that provides the basic structure for a material design layout. It offers several essential APIs such as Drawer, SnackBar, BottomNavigationBar, FloatingActionButton, and AppBar, which help in building a uniform look and feel for an application. The 'Scaffold' expands to occupy the entire screen space, ensuring that the app's UI components are well-managed and organized within the available screen area .

Dart's 'null safety' feature fundamentally changes how null references are handled in programming, significantly reducing runtime null exceptions by introducing non-nullable types and safe syntax for nullable operations. Developers are required to specify whether variables can be nullable or non-nullable, providing a guarantee at compile-time that non-nullable variables cannot hold null values. The use of operators like '!' for forced unwrapping and '??' for null-aware operations allows developers to handle nulls explicitly and safely. This system prevents accidental null dereferencing, which is a common source of bugs, thus enhancing code robustness and reliability .

In Flutter, NetworkImage is typically used as an ImageProvider, useful when the image needs to be manipulated before display, as it facilitates decoding and resizing. It is used inside widgets that accept an ImageProvider, such as the backgroundImage property of CircleAvatar. Conversely, Image.network is a widget that directly loads and displays an image from the URL and is often used as a child widget. Both load images asynchronously, but while NetworkImage allows more control and manipulation before being used inside Image widgets, Image.network is straightforward for use directly in the widget tree .

In Flutter, a StatefulWidget's lifecycle involves several methods that manage its state: createState(), initState(), didChangeDependencies(), build(), didUpdateWidget(), setState(), deactivate(), and dispose(). These methods play critical roles in initializing, updating, rebuilding, and cleaning up resources for a widget. For instance, initState() is called once to initialize state data, didChangeDependencies() handles changes in dependencies, while build() is invoked whenever the widget needs rebuilding. After changes in a parent widget, didUpdateWidget() updates state accordingly. Methods like setState() help update the UI, and dispose() ensures resource cleanup when the state object is destroyed. This comprehensive lifecycle management helps achieve responsive and maintainable applications .

The 'late' keyword in Dart is used to declare variables that will be initialized later, ensuring they are non-nullable. This is particularly useful because it allows developers to delay the initialization of variables until they are needed, without them being null at runtime. Non-nullable variables, once declared with 'late', must be initialized before they are used. This feature is crucial in preventing null errors and ensuring that variables are always used with valid values .

The 'Visibility' widget in Flutter controls dynamic displays by allowing developers to conditionally show or hide widgets based on a Boolean condition. It provides the 'visible' parameter to determine if the widget is displayed, and can manage the layout behavior when hidden using parameters like 'maintainSize', ensuring the hidden widget's space is either reserved or removed. This is crucial for creating flexible, dynamic UIs where widgets can appear or disappear based on user interaction or application state while maintaining visual consistency .

The 'BuildContext' in Flutter is pivotal for widget interaction within the widget tree as it provides context about the widget's position. It is used extensively to access information about parent and child widgets, like obtaining themes, media queries, or navigators. BuildContext is passed as an argument to widget constructors and used within build() methods to enable interaction with the widget tree, offering methods that facilitate various tasks such as theme retrieval. Immutable nature ensures widgets have a consistent reference to their surrounding context, despite the tree's dynamic nature, thereby aiding in maintaining reliable widget hierarchies .

You might also like