Coder Social home page Coder Social logo

heliocastro / flight_co2_calculator_flutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bizz84/flight_co2_calculator_flutter

0.0 0.0 0.0 1.98 MB

Flutter package and sample app to calculate Flight CO2 emissions

Home Page: https://codingwithflutter.com/

License: MIT License

Kotlin 3.21% Ruby 7.23% Swift 2.51% Objective-C 1.22% Dart 85.83%

flight_co2_calculator_flutter's Introduction

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.
  • 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.

flight_co2_calculator_flutter's People

Contributors

bizz84 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.