You are on page 1of 9

Flutter Mobile Programming

Chapter 5
Navigators

1: What is Gesture-Detector?
Ans: Gesture Detector is a non-visual widget primarily used for detecting the user’s gesture.
To identify a gesture targeted on a widget, the widget can be placed inside Gesture Detector widget.
Gesture Detector will capture the gesture and dispatch multiple events based on the gesture

2: What is Slider?
Ans: A slider in Flutter is a material design widget used for selecting a range of values.
It is an input widget where we can set a range of values by dragging or pressing on the desired position

• Usually, we use the slider widget for changing a value. So, it is required to store the
value in a variable. This widget has a slider class that requires the onChanged()
3: What is Navigator?

Ans: widget. The navigator manages a stack of Route objects and provides methods for managing the
stack, like Navigator.push and Navigator.pop.

• Push a named route onto the navigator that most tightly encloses the given context
• Pop the top-most route off the navigator that most tightly encloses the given context
4: What are Routes?
Ans: Route: Apps are the new trend. The number of apps available in the play stores nowadays are
quite a lot.

The apps display their content in a full-screen container called pages or screens. In flutter, the pages or
screens are called as the Routes.

In android, these pages/screens are referred as Activity and in iOS, it is referred as ViewController. But,
in flutter, routes are referred as Widgets. In Flutter, a Page / Screen is called as a Route.
Chapter 6
Stateful widget lifecycle

1: What is Raised Button widget?


Ans: RaisedButton is the material design button based on a Material widget that elevates when pressed
upon in flutter. It is one of the most widely used buttons in the flutter library

2: What is Geolocator?
Ans: A Flutter geolocation plugin which provides easy access to platform specific location services
FusedLocationProviderClient or if not available the LocationManager on Android
and CLLocationManager on iOS

Features

• Get the last known location;

• Get the current location of the device;

• Get continuous location updates;

• Check if location services are enabled on the device;

• Calculate the distance (in meters) between two geocoordinates;

• Calculate the bearing between two geocoordinates

3: What is Synchronous and Asynchronous?


A synchronous operation blocks other operations from executing until it completes

synchronous function: A synchronous function only performs synchronous operations


Asynchronous operation: Once initiated, an asynchronous operation allows other
operations to execute before it completes
Asynchronous function: An asynchronous function performs at least one asynchronous
operation and can also perform synchronous operations
• The async and await keywords provide a declarative way to define asynchronous
functions and use their results. Remember these two basic guidelines when using async
and await:
• To define an async function, add async before the function body:
• The await keyword works only in async functions.

Stateful widget lifecycle
• When a Flutter builds a StatefulWidget it creates a State object. This object is where all
the mutable state for that widget is held
The concept of state is defined by two things:
1. The data used by the widget might change.
2. The data can't be read synchronously when the widget is built. (All state must be
established by the time the build method is called).
The lifecycle has the following simplified steps:
• createState()
• mounted == true
• initState()
• didChangeDependencies()
• build()
• didUpdateWidget()
• setState()
• deactivate()
• dispose()
• mounted == false
 createState()
• When Flutter is instructed to build a StatefulWidget it immediately calls createState().
This method must exist. A StatefulWidget rarely needs to be more complicated than this
mounted is true
• When createState creates the state class, a buildContext is assigned to that state.
• A BuildContext is, overly simplified, the place in the widget tree in which this widget is
placed. Here's a longer explanation.
• All widgets have a bool this.mounted property. It is turns true when the buildContext is
assigned. It is an error to call setState when a widget is unmounted
• initState()
• This is the first method called when the widget is created (after the class constructor, of
course.)
• initState is called once and only once. It must also call super.initState().
• This @override method is the best time to:
• Initialize data that relies on the specific BuildContext for the created instance of the
widget.
• Initialize properties that rely on this widgets 'parent' in the tree.
• Subscribe to Streams, ChangeNotifiers, or any other object that could change the data
on this widget.
didChangeDependencies()
• The didChangeDependencies method is called immediately after initState on the first
time the widget is built.
• It will also be called whenever an object that this widget depends on data from is called.
For example, if it relies on an InheritedWidget, which updates.
• build is always called after didChangeDependencies is called, so this is rarely needed.
However, this method is the first change you have to call
BuildContext.inheritFromWidgetOfExactType. This essentially would make this State
'listen' to changes on a Widget it's inheriting data from.
• The docs also suggest that it could be useful if you need to do network calls (or any
other expensive action) when an InheritedWidget updates.
build()
• This method is called often (think fps + render). It is a required, @override and must
return a Widget.
• Remember that in Flutter all gui is a widget with a child or children, even 'Padding',
'Center'.
didUpdateWidget(Widget oldWidget)
• didUpdateWidget() is called if the parent widget changes and has to rebuild this widget
(because it needs to give it different data), but it's being rebuilt with the same
runtimeType, then this method is called.
• This is because Flutter is re-using the state, which is long lived. In this case, required is to
initialize some data again, as one would in initState().
• If the state's build() method relies on a Stream or other object that can change,
unsubscribe from the old object and re-subscribe to the new instance in
didUpdateWidget().
setState()
• The 'setState()' method is called often from the Flutter framework itself and from the
developer.
• It is used to notify the framework that "data has changed", and the widget at this build
context should be rebuilt.
• setState() takes a callback which cannot be async. It is for this reason it can be called
often as required, because repainting is cheap :-)
deactivate()
• This is rarely used.
• 'deactivate()' is called when State is removed from the tree, but it might be reinserted
before the current frame change is finished. This method exists basically because State
objects can be moved from one point in a tree to another
dispose()
• 'dispose()' is called when the State object is removed, which is permanent.
• This method is where to unsubscribe and cancel all animations, streams, etc
mounted is false
• The state object can never remount, and an error is thrown is setState() is called.
4: What is Exception?
Ans: An exception (or exception event) is a problem that irises during the exception of a
program when an exception occurs the normal flow of the program is disrupted and the
program/Application terminates abnormally.
5: What is the try /on/catch block
• Every exception in Dart is a subtype of the pre-defined class Exception. Exceptions
must be handled to prevent the application from terminating abruptly
Ans: Every exception in Dart is a subtype of the pre-defined class Exception. Exceptions must be
handled to prevent the application

6: What is Application Programming Interface (API)?

Ans: API is the acronym for Application Programming Interface, which is a software intermediary that
allows two applications to talk to each other.

Each time you use an app like Facebook, send an instant message, or check the weather on your phone,
you're using an API.

7: What is http package?


Ans: This package contains a set of high-level functions and classes that make it easy to consume HTTP
resources. It's multi-platform, and supports mobile, desktop, and the browser.

8: What is JSON?
Ans: JSON is an open standard file format, and data interchange format, that uses human-
readable text to store and transmit data objects consisting of attribute–value
• JSON stands for JavaScript Object Notation
• JSON is a lightweight data-interchange format
• JSON is "self-describing" and easy to understand
• JSON is language independent
Openweathermap
• Access current weather data for any location on Earth including over 200,000 cities!
We collect and process weather data from different sources such as global and local
weather models, satellites, radars and vast network of weather stations. Data is
available in JSON, XML, or HTML forma
Chapter 7 Firebase

1: What is firebase?
• Store and sync data with our NoSQL cloud database.
• Data is synced across all clients in realtime, and remains available when your app goes
offline
• The Firebase Realtime Database is a cloud-hosted database.
• Data is stored as JSON and synchronized in realtime to every connected client. When
you build cross-platform apps with our iOS, Android, and JavaScript SDKs, all of your
clients share one Realtime Database instance and automatically receive updates with
the newest data
2: firebase realtime database?
Ans: Firebase Realtime Database is a cloud-hosted NoSQL database that allows you to store and
synchronize data between your users in real time.

• NEW: Cloud Firestore allows you to store, sync and search app data on a global scale
3: What Cloud Functions?

Ans: Cloud Functions for Firebase is a serverless framework that lets you automatically run backend
code in response to events triggered by Firebase features and HTTPS requests.

Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.
There's no need to manage and scale your own servers.

4: What is Cloud firestore?

Ans: Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for
your mobile and web apps - at global scale.

Advantages Cloud firestore


• Strong user-based security
• Scale globally
• Sync data across devices, on or offline
• Build truly serverless apps
• Query and structure data the way you like

Query and structure data 


• Structure your data easily with collections and documents. Build hierarchies to store
related data and easily retrieve the data you need using expressive queries. All queries
scale with the size of your result set (note: not your data set), so your app is ready to
scale from day one
Build truly serverless apps
• Cloud Firestore ships with mobile and web SDKs and a comprehensive set of security
rules so you can access your database without needing to stand up your own server.
Using Cloud Functions, our serverless compute product, you can execute hosted
backend code that responds to data changes in your database. Of course, you can also
access Cloud Firestore with traditional client libraries too (i.e. Node, Python, Go, and
Java).
Scale globally
• Powered by Google’s storage infrastructure, Cloud Firestore is built to scale with your
business. Now, you can focus on building your app instead of managing servers or
worrying about consistency
Strong user-based security
• With our declarative security language, you can restrict data access based on user
identity data, pattern matching on your data, and more. Cloud Firestore also integrates
with Firebase Authentication to give you simple and intuitive user authentication
Firebase Authentication
• Firebase Authentication aims to make building secure authentication systems easy,
while improving the sign-in and onboarding experience for end users. It provides an
end-to-end identity solution, supporting email and password accounts, phone auth, and
Google, Twitter, Facebook, and GitHub login, and more.
Firebase Crashlytics
• Firebase Crashlytics helps you track, prioritize, and fix stability issues that erode app
quality, in realtime. Spend less time triaging and troubleshooting crashes and more time
building app features that delight users
Google Analytics in Firebase
• At the heart of Firebase is Google Analytics, a free and unlimited analytics solution.
Analytics integrates across Firebase features and provides you with unlimited reporting
for up to 500 distinct events that you can define using the Firebase SDK. Analytics
reports help you understand clearly how your users behave, which enables you to make
informed decisions regarding app marketing and performance optimizations.
ML Kit
• ML Kit provides us on-Device and Cloud APIs. The on-Device process the data without
the use of an internet connection, Cloud provides us high-level accuracy with the use of
Google Cloud Platform’s machine learning technology.
• To enable the use of ML Kit we need to connect the app with the firebase. We will be
using two dependencies firebase_ml_vision: ^0.9.7
• for ML Kit and image_picker: ^0.6.7+11 to get the image using a gallery or camera.

You might also like