Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bizz84/flight_co2_calculator_flutter
Flutter package and sample app to calculate Flight CO2 emissions
https://github.com/bizz84/flight_co2_calculator_flutter
android dart flutter ios
Last synced: 3 days ago
JSON representation
Flutter package and sample app to calculate Flight CO2 emissions
- Host: GitHub
- URL: https://github.com/bizz84/flight_co2_calculator_flutter
- Owner: bizz84
- License: mit
- Created: 2018-11-15T22:42:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-14T16:27:06.000Z (over 4 years ago)
- Last Synced: 2024-08-23T23:54:34.430Z (3 months ago)
- Topics: android, dart, flutter, ios
- Language: Dart
- Homepage: https://codewithandrea.com/
- Size: 1.83 MB
- Stars: 57
- Watchers: 5
- Forks: 20
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flight CO2 Calculator
## About
This plugin provides a collection of classes that can be used to:
- Load a list of airports from the [OpenFlights.org dataset](https://openflights.org/data.html).
- 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:
![](screenshots/FlightCalculator-screenshots.png)
## How to use it
Load data:
```dart
List airports = await AirportDataReader.load('data/airports.dat');
```Create an `AirportLookup` service:
```dart
final airportLookup = AirportLookup(airports: airports);
```Search for airports matching a query:
```dart
List results = airportLookup.searchString(query);
```Calculate distance and CO2 emissions:
```dart
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.
### [License: MIT](LICENSE)