SlideShare a Scribd company logo
1 of 21
CSE-4078
MOBILE APPLICATION
DEVELOPMENT
LECTURES – WEEK 10
SARA MASOOD
APP OF THE MODULE
GEO LOCATION
◼ Use the package GeoLocator
◼ geolocator | Flutter Package (pub.dev)
dependencies:
geolocator: ^8.0.0
import 'package:geolocator/geolocator.dart';
GEO LOCATION
◼ Current location
Position position = await Geolocator.getCurrentPosition(desiredAccuracy:
LocationAccuracy.high);
◼ Last known location
Position position = await Geolocator.getLastKnownPosition();
ADDING PERMISSIONS TO ANDROID MANIFEST
◼ Go to android > app > src > main > AndroidMenifest.xml and add following permissions (like added in below-
given picture)
◼ Location Permission
◼ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
◼ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
◼ Internet permission
◼ <uses-permission android:name="android.permission.INTERNET"/>
PERMISSION FOR LOCATION SERVICES
◼ Checking the permission
◼ LocationPermission permission = await Geolocator.checkPermission();
◼ Request the permission
◼ LocationPermission permission = await Geolocator.requestPermission();
GEO LOCATION MUST BE ASYNC
void getLocation() async{
Position position =
await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
ASYNCHRONOUS PROGRAMMING: FUTURES, ASYNC, AWAIT
◼ Asynchronous operations let your program complete work while waiting for another operation to
finish.
void example() async {
await …
}
◼ Future
◼ A future (lower case “f”) is an instance of the Future (capitalized “F”) class.
◼ A future represents the result of an asynchronous operation, and can have two states: uncompleted or
completed.
ASYNCHRONOUS PROGRAMMING: FUTURES, ASYNC, AWAIT
Future<void> printOrderMessage() async {
print('Awaiting user order...');
var order = await fetchUserOrder();
print('Your order is: $order');
}
INTERNAL STATE FOR A STATEFULWIDGET
◼ State is information that
◼ can be read synchronously when the widget is built
◼ might change during the lifetime of the widget.
◼ State objects have the different lifecycle
◼ State class - widgets library - Dart API (flutter.dev)
INTERNAL STATE FOR A STATEFULWIDGET
◼ initState() → void
◼ Called when this object is inserted into the tree
◼ activate() → void
◼ Called when this object is reinserted into the tree after having been removed via deactivate
◼ build(BuildContext context) → Widget
◼ Describes the part of the user interface represented by this widget
◼ deactivate() → void
◼ Called when this object is removed from the tree
◼ dispose() → void
◼ Called when this object is removed from the tree permanently
APIS
API (APPLICATION
PROGRAM
INTERFACE)
◼ An API is a set of routines,
protocols, and tools for
building software applications.
◼ You must have API Keys.
API
GET WEATHER API KEY
◼ Go to Weather API – OpenWeatherMap and
create get API key.
USING HTTP PACKAGE
◼ A composable, Future-based library for making HTTP requests.
◼ This package contains a set of high-level functions and classes that make it easy to consume
HTTP resources.
◼ Installing
dependencies:
http: ^0.13.4
import 'package:http/http.dart’ as http;
◼ http | Dart Package (pub.dev)
◼ Fetch data from the internet | Flutter
USING HTTP PACKAGE - MAKE A NETWORK REQUEST
Future<http.Response> fetchWeather() async {
return await http.get(Uri.parse('
api.openweathermap.org/data/2.5/weather?q={city name}&appid={API_key}'));
}
◼ The http.Response class contains the data received from a successful http call.
GETTING THE RESPONSE CODE AND BODY
◼ Get the response body
◼ response.body
◼ Get the resoonse code
◼ response.statusCode
HTTP RESPONSE CODES
◼ Informational responses (100–199)
◼ Successful responses (200–299)
◼ Redirection messages (300–399)
◼ Client error responses (400–499)
◼ Server error responses (500–599)
JSON (JAVASCRIPT OBJECT
NOTATION)
◼ '{"name":"John", "age":30, "car":null}'
◼ It defines an object with 3 properties:
◼ name
◼ age
◼ car
PARSING THE JSON
◼ Use the dart:convert library
◼ dart:convert library - Dart API
◼ import 'dart:convert’;
◼ Use the jsonDecode function
◼ Parses the string and returns the resulting Json object.
◼ var longitude = jsonDecode(data)[‘coord’][‘lon’];
◼ jsonDecode function - dart:convert library - Dart API

More Related Content

Similar to CSE-4078 - Lecture - Week 10 -11aga.pptx

Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containersJosé Moreira
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...varunsunny21
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Building with Firebase
Building with FirebaseBuilding with Firebase
Building with FirebaseMike Fowler
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platformsAyush Sharma
 
I/O Extended 2019 WebTech - New capabilities for the web
I/O Extended 2019 WebTech - New capabilities for the webI/O Extended 2019 WebTech - New capabilities for the web
I/O Extended 2019 WebTech - New capabilities for the webHanboramRobinJang
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про HerokuSerge Seletskyy
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про HerokuGeeksLab Odessa
 
The Google App Engine Oil Framework
The Google App Engine Oil FrameworkThe Google App Engine Oil Framework
The Google App Engine Oil FrameworkEric ShangKuan
 
Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaSAppsembler
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With RpmMartin Jackson
 
Automated integration testing of distributed systems with Docker Compose and ...
Automated integration testing of distributed systems with Docker Compose and ...Automated integration testing of distributed systems with Docker Compose and ...
Automated integration testing of distributed systems with Docker Compose and ...Boris Kravtsov
 
Minimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestrationMinimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestrationOutlyer
 
Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Luc Bors
 
JQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On VacayJQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On VacayNatasha Rooney
 

Similar to CSE-4078 - Lecture - Week 10 -11aga.pptx (20)

Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containers
 
Oracle API Gateway Installation
Oracle API Gateway InstallationOracle API Gateway Installation
Oracle API Gateway Installation
 
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...Project Description Of Incident Management System Developed by PRS (CRIS) , N...
Project Description Of Incident Management System Developed by PRS (CRIS) , N...
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Building with Firebase
Building with FirebaseBuilding with Firebase
Building with Firebase
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
I/O Extended 2019 WebTech - New capabilities for the web
I/O Extended 2019 WebTech - New capabilities for the webI/O Extended 2019 WebTech - New capabilities for the web
I/O Extended 2019 WebTech - New capabilities for the web
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про Heroku
 
Хокку про Heroku
Хокку про HerokuХокку про Heroku
Хокку про Heroku
 
The Google App Engine Oil Framework
The Google App Engine Oil FrameworkThe Google App Engine Oil Framework
The Google App Engine Oil Framework
 
Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaS
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
 
GlassFish Embedded API
GlassFish Embedded APIGlassFish Embedded API
GlassFish Embedded API
 
Automated integration testing of distributed systems with Docker Compose and ...
Automated integration testing of distributed systems with Docker Compose and ...Automated integration testing of distributed systems with Docker Compose and ...
Automated integration testing of distributed systems with Docker Compose and ...
 
Minimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestrationMinimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestration
 
Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)Reaching out from ADF Mobile (ODTUG KScope 2014)
Reaching out from ADF Mobile (ODTUG KScope 2014)
 
JQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On VacayJQuery UK February 2015: Service Workers On Vacay
JQuery UK February 2015: Service Workers On Vacay
 

Recently uploaded

Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service AvailableNashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Availablepr788182
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...ssuserf63bd7
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfwill854175
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistanvineshkumarsajnani12
 
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptxRoofing Contractor
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 MonthsIndeedSEO
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...daisycvs
 
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...pujan9679
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableBerhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Availablepr788182
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwaitdaisycvs
 
Kalyan Call Girl 98350*37198 Call Girls in Escort service book now
Kalyan Call Girl 98350*37198 Call Girls in Escort service book nowKalyan Call Girl 98350*37198 Call Girls in Escort service book now
Kalyan Call Girl 98350*37198 Call Girls in Escort service book nowranineha57744
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Falcon Invoice Discounting
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizharallensay1
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 

Recently uploaded (20)

Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service AvailableNashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
Nashik Call Girl Just Call 7091819311 Top Class Call Girl Service Available
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdf
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
 
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableBerhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Kalyan Call Girl 98350*37198 Call Girls in Escort service book now
Kalyan Call Girl 98350*37198 Call Girls in Escort service book nowKalyan Call Girl 98350*37198 Call Girls in Escort service book now
Kalyan Call Girl 98350*37198 Call Girls in Escort service book now
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 

CSE-4078 - Lecture - Week 10 -11aga.pptx

  • 2. APP OF THE MODULE
  • 3. GEO LOCATION ◼ Use the package GeoLocator ◼ geolocator | Flutter Package (pub.dev) dependencies: geolocator: ^8.0.0 import 'package:geolocator/geolocator.dart';
  • 4. GEO LOCATION ◼ Current location Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); ◼ Last known location Position position = await Geolocator.getLastKnownPosition();
  • 5. ADDING PERMISSIONS TO ANDROID MANIFEST ◼ Go to android > app > src > main > AndroidMenifest.xml and add following permissions (like added in below- given picture) ◼ Location Permission ◼ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> ◼ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> ◼ Internet permission ◼ <uses-permission android:name="android.permission.INTERNET"/>
  • 6. PERMISSION FOR LOCATION SERVICES ◼ Checking the permission ◼ LocationPermission permission = await Geolocator.checkPermission(); ◼ Request the permission ◼ LocationPermission permission = await Geolocator.requestPermission();
  • 7. GEO LOCATION MUST BE ASYNC void getLocation() async{ Position position = await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); }
  • 8. ASYNCHRONOUS PROGRAMMING: FUTURES, ASYNC, AWAIT ◼ Asynchronous operations let your program complete work while waiting for another operation to finish. void example() async { await … } ◼ Future ◼ A future (lower case “f”) is an instance of the Future (capitalized “F”) class. ◼ A future represents the result of an asynchronous operation, and can have two states: uncompleted or completed.
  • 9. ASYNCHRONOUS PROGRAMMING: FUTURES, ASYNC, AWAIT Future<void> printOrderMessage() async { print('Awaiting user order...'); var order = await fetchUserOrder(); print('Your order is: $order'); }
  • 10. INTERNAL STATE FOR A STATEFULWIDGET ◼ State is information that ◼ can be read synchronously when the widget is built ◼ might change during the lifetime of the widget. ◼ State objects have the different lifecycle ◼ State class - widgets library - Dart API (flutter.dev)
  • 11. INTERNAL STATE FOR A STATEFULWIDGET ◼ initState() → void ◼ Called when this object is inserted into the tree ◼ activate() → void ◼ Called when this object is reinserted into the tree after having been removed via deactivate ◼ build(BuildContext context) → Widget ◼ Describes the part of the user interface represented by this widget ◼ deactivate() → void ◼ Called when this object is removed from the tree ◼ dispose() → void ◼ Called when this object is removed from the tree permanently
  • 12. APIS
  • 13. API (APPLICATION PROGRAM INTERFACE) ◼ An API is a set of routines, protocols, and tools for building software applications. ◼ You must have API Keys.
  • 14. API
  • 15. GET WEATHER API KEY ◼ Go to Weather API – OpenWeatherMap and create get API key.
  • 16. USING HTTP PACKAGE ◼ A composable, Future-based library for making HTTP requests. ◼ This package contains a set of high-level functions and classes that make it easy to consume HTTP resources. ◼ Installing dependencies: http: ^0.13.4 import 'package:http/http.dart’ as http; ◼ http | Dart Package (pub.dev) ◼ Fetch data from the internet | Flutter
  • 17. USING HTTP PACKAGE - MAKE A NETWORK REQUEST Future<http.Response> fetchWeather() async { return await http.get(Uri.parse(' api.openweathermap.org/data/2.5/weather?q={city name}&appid={API_key}')); } ◼ The http.Response class contains the data received from a successful http call.
  • 18. GETTING THE RESPONSE CODE AND BODY ◼ Get the response body ◼ response.body ◼ Get the resoonse code ◼ response.statusCode
  • 19. HTTP RESPONSE CODES ◼ Informational responses (100–199) ◼ Successful responses (200–299) ◼ Redirection messages (300–399) ◼ Client error responses (400–499) ◼ Server error responses (500–599)
  • 20. JSON (JAVASCRIPT OBJECT NOTATION) ◼ '{"name":"John", "age":30, "car":null}' ◼ It defines an object with 3 properties: ◼ name ◼ age ◼ car
  • 21. PARSING THE JSON ◼ Use the dart:convert library ◼ dart:convert library - Dart API ◼ import 'dart:convert’; ◼ Use the jsonDecode function ◼ Parses the string and returns the resulting Json object. ◼ var longitude = jsonDecode(data)[‘coord’][‘lon’]; ◼ jsonDecode function - dart:convert library - Dart API