flutter flight co2 calculator
this plugin provides a collection of classes that can be used to:
- load a list of airports from the openflights.org dataset.
- lookup airports matching a search query against the entire data-set of airports.
- calculate the distance and co2 emissions from flights.
what you can do with this
build a flight co2 calculator app such as this:
how to use it
load data:
list<airport> airports = await airportdatareader.load('data/airports.dat');
create an airportlookup
service:
final airportlookup = airportlookup(airports: airports);
search for airports matching a query:
list<airport> results = airportlookup.searchstring(query);
calculate distance and co2 emissions:
class flightcalculationdata {
flightcalculationdata({this.distancekm, this.co2e});
final double distancekm;
final double co2e;
}
flightcalculationdata _calculate(flightdetails flightdetails) {
double distancekm;
double co2e;
airport departure = flightdetails.departure;
airport arrival = flightdetails.arrival;
if (departure != null && arrival != null) {
double multiplier =
flightdetails.flighttype == flighttype.oneway ? 1.0 : 2.0;
distancekm = distancecalculator.distanceinkmbetween(
departure.location, arrival.location);
distancekm = co2calculator.correcteddistancekm(distancekm);
co2e =
co2calculator.calculateco2e(distancekm, flightdetails.flightclass) *
multiplier;
}
return flightcalculationdata(distancekm: distancekm, co2e: co2e);
}
example
see the sample flight co2 calculator app bundled with the project in the example
folder.
Comments are closed.