airports.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:collection/collection.dart';
  2. import 'package:flutter/services.dart';
  3. //import 'package:csv/csv.dart';
  4. class Airport {
  5. String code;
  6. String timezoneid;
  7. String name;
  8. String citycode;
  9. String countryid;
  10. String location;
  11. String elevation;
  12. String url;
  13. String icao;
  14. String city;
  15. String county;
  16. String state;
  17. Airport(
  18. this.code,
  19. this.timezoneid,
  20. this.name,
  21. this.citycode,
  22. this.countryid,
  23. this.location,
  24. this.elevation,
  25. this.url,
  26. this.icao,
  27. this.city,
  28. this.county,
  29. this.state);
  30. }
  31. class Airports {
  32. // static final Airports instance = Airports._();
  33. // Airports._();
  34. // List lines = [];
  35. // List titles = [];
  36. static Airport? find(String code) =>
  37. Airports.list.firstWhereOrNull((e) => e.code == code);
  38. static Future<void> init() async {
  39. String x = await rootBundle.loadString('assets/csv/airports.csv');
  40. // lines = x.replaceAll('"', "").split("\n");
  41. // titles = lines[0].split(",");
  42. // lines.removeAt(0);
  43. // lines = lines
  44. // .map((e) => Map.fromIterables(
  45. // titles,
  46. // e.split(",").length == titles.length
  47. // ? e.split(",")
  48. // : List.generate(titles.length, (w) => "")))
  49. // .toList();
  50. // List<List<dynamic>> listData = const CsvToListConverter().convert(x);
  51. // for (var ap in listData) {
  52. // list.add(Airport(ap[0], ap[1], ap[2], ap[3], ap[4], ap[5],
  53. // ap[6].toString(), ap[7], ap[8], ap[9], ap[10], ap[11]));
  54. // }
  55. List<List<dynamic>> listData =
  56. x.split("\n").map((e) => e.split(",").toList()).toList();
  57. for (var ap in listData) {
  58. list.add(Airport(ap[0], ap[1], ap[2], ap[3], ap[4], ap[5],
  59. ap[6].toString(), ap[7], ap[8], ap[9], ap[10], ap[11]));
  60. }
  61. print("Airports: loaded ${list.length} Airports");
  62. }
  63. static List<Airport> list = [];
  64. }