Skip to content

Commit

Permalink
better bottom sheet views
Browse files Browse the repository at this point in the history
  • Loading branch information
apps4av committed Jul 24, 2024
1 parent cd5788d commit bb49d33
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 55 deletions.
49 changes: 11 additions & 38 deletions lib/airport.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:math';

import 'package:auto_size_text/auto_size_text.dart';
import 'package:avaremp/destination.dart';
import 'package:avaremp/geo_calculations.dart';
import 'package:avaremp/storage.dart';
Expand All @@ -12,7 +11,7 @@ import 'constants.dart';

class Airport {

static String parseFrequencies(AirportDestination airport) {
static ListView parseFrequencies(AirportDestination airport) {

List<Map<String, dynamic>> frequencies = airport.frequencies;
List<Map<String, dynamic>> awos = airport.awos;
Expand Down Expand Up @@ -55,48 +54,22 @@ class Airport {
catch(e) {}
}

String ret = "";

if(tower.isNotEmpty) {
ret += "Tower\n ";
ret += tower.join("\n ");
}
if(ground.isNotEmpty) {
ret += "\nGround\n ";
ret += ground.join("\n ");
}
if(clearance.isNotEmpty) {
ret += "\nClearance\n ";
ret += clearance.join("\n ");
}
if(atis.isNotEmpty) {
ret += "\nATIS\n ";
ret += atis.join("\n ");
}
if(airport.ctaf.isNotEmpty) {
ret += "\nCTAF\n ";
ret += airport.ctaf;
}
if(airport.unicom.isNotEmpty) {
ret += "\nUNICOM\n ";
ret += airport.unicom;
}
if(automated.isNotEmpty) {
ret += "\nAutomated\n ";
ret += automated.join("\n ");
}

return ret;
ListView view = ListView(children: [
if(tower.isNotEmpty) ListTile(leading: const Icon(Icons.cell_tower), title: const Text("Tower"), subtitle: Text(tower.join("\n"))),
if(ground.isNotEmpty) ListTile(leading: const Icon(Icons.airport_shuttle), title: const Text("Ground"), subtitle: Text(ground.join("\n"))),
if(atis.isNotEmpty) ListTile(leading: const Icon(Icons.thermostat), title: const Text("ATIS"), subtitle: Text(atis.join("\n"))),
if(clearance.isNotEmpty) ListTile(leading: const Icon(Icons.perm_identity), title: const Text("Clearance"), subtitle: Text(clearance.join("\n"))),
if(airport.ctaf.isNotEmpty) ListTile(leading: const Icon(Icons.radio), title: const Text("CTAF"), subtitle: Text(airport.ctaf)),
if(airport.unicom.isNotEmpty) ListTile(leading: const Icon(Icons.radio), title: const Text("UNICOM"), subtitle: Text(airport.unicom)),
if(automated.isNotEmpty) ListTile(leading: const Icon(Icons.air), title: const Text("Automated"), subtitle: Text(automated.join("\n"))),
]);
return view;
}

static Widget runwaysWidget(AirportDestination airport, double dimensions) {
return CustomPaint(size: Size(dimensions, dimensions), painter: RunwayPainter(airport));
}

static Widget frequenciesWidget(String frequencies) {
return AutoSizeText(frequencies, minFontSize: 4, maxFontSize: 15, overflow: TextOverflow.visible);
}

static List<MapRunway> getRunwaysForMap(AirportDestination destination) {
GeoCalculations geo = GeoCalculations();
// pairs of two where a line will be drawn for runway, first is runway threshold, second 10 miles out
Expand Down
29 changes: 18 additions & 11 deletions lib/longpress_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import 'nav.dart';
class LongPressWidget extends StatefulWidget {
final Destination destination;

// it crashes if not static

const LongPressWidget({super.key, required this.destination});

@override
Expand Down Expand Up @@ -75,15 +73,17 @@ class LongPressFuture {
airportDiagram = Image.file(file);
}

pages.add(Airport.frequenciesWidget(Airport.parseFrequencies(showDestination as AirportDestination)));
pages.add(Airport.parseFrequencies(showDestination as AirportDestination));

}
else if(showDestination is NavDestination) {
pages.add(Nav.mainWidget(Nav.parse(showDestination as NavDestination)));
}
else if(showDestination is FixDestination) {
pages.add(const Text("Fix"));
}
else if(showDestination is AirwayDestination) {
pages.add(const Text("Airway"));
}
else if (showDestination is GpsDestination) {
// add labeling support
Expand Down Expand Up @@ -186,7 +186,6 @@ class LongPressWidgetState extends State<LongPressWidget> {
}
Widget? sounding = Sounding.getSoundingImage(widget.destination.coordinate, context);


if(future.showDestination is AirportDestination) {
Weather? w = Storage().metar.get("$k${future.showDestination.locationID}");
Weather? w1 = Storage().taf.get("$k${future.showDestination.locationID}");
Expand All @@ -197,7 +196,7 @@ class LongPressWidgetState extends State<LongPressWidget> {
w != null
? ListTile(title: const Text("METAR"),
subtitle: Text((w as Metar).text),
leading: Icon(Icons.circle_outlined, color: w.getColor(),),)
leading: Icon(Icons.circle_outlined, color: w.getColor(), size:32),)
: Container(),
w1 != null ? ListTile(title: const Text("TAF"),
subtitle: Text((w1 as Taf).text),
Expand All @@ -213,7 +212,11 @@ class LongPressWidgetState extends State<LongPressWidget> {
if (snapshot.hasData) {
Weather? w2 = snapshot.data;
if (w2 != null) {
return SingleChildScrollView(child: Text(w2.toString()));
List<String> notams = w2.toString().split("\n\n");
notams.insert(0, "NOTAMS");
return ListView.builder(itemCount: notams.length, itemBuilder: (context, index) {
return ListTile(leading: index == 0 ? const Text("") : Text(notams[index].substring(0, 4)), title: Text(notams[index]));
});
}
else {
return Container();
Expand All @@ -230,6 +233,7 @@ class LongPressWidgetState extends State<LongPressWidget> {
saaPage = future.pages.length;
future.pages.add(ListView(
children: [
ListTile(title: const Text("SUA")),
for(Saa s in future.saa)
ListTile(title: Text(s.designator),
subtitle: Text(s.toString())),
Expand All @@ -241,11 +245,14 @@ class LongPressWidgetState extends State<LongPressWidget> {
windsPage = future.pages.length;
WindsAloft wa = winds as WindsAloft;
future.pages.add(
SingleChildScrollView(child: Column(children:[
if(sounding != null)
sounding,
Text(wa.toString())
]))
ListView(children: [
ListTile(title: Text(winds.toString())),
if(sounding != null) ListTile(leading: sounding),
for((String, String) wl in wa.toList()) ListTile(
leading: Text(wl.$1),
title: Text(wl.$2),
),
])
);
}

Expand Down
19 changes: 13 additions & 6 deletions lib/weather/winds_aloft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,25 @@ class WindsAloft extends Weather {
);
}

@override
toString() {
DateTime zulu = expires.toUtc(); // winds in Zulu time
// boilerplate
String wind = "Winds - $station (Temps negative above 24000)\nValid till ${zulu.day .toString().padLeft(2, "0")}${zulu.hour.toString().padLeft(2, "0")}00Z\n\n";

List<(String, String)> toList() {
List<(String, String)> winds = [];
for(double altitude = 3000; altitude < 42000; altitude += 3000) {
double? speed;
double? dir;
(dir, speed) = getWindAtAltitude(altitude);
// show dir, speed, and actual string for every 3000ft
wind += " @${altitude.round().toString().toString().padLeft(5, "0")}FT ${dir == null ? "" : "${dir.round().toString().padLeft(3, "0")}\u00b0"} ${speed == null ? "" : "@${speed.round()}"} (${getWindAtAltitudeRaw(altitude.round())})\n";
winds.add(((altitude.round().toString().toString().padLeft(5, "0")), "${dir == null ? "" : "${dir.round().toString().padLeft(3, "0")}\u00b0"} ${speed == null ? "" : "@${speed.round()}"} (${getWindAtAltitudeRaw(altitude.round())})"));
}
return winds;
}


@override
toString() {
DateTime zulu = expires.toUtc(); // winds in Zulu time
// boilerplate
String wind = "Winds - $station (Temps negative above 24000)\nValid till ${zulu.day .toString().padLeft(2, "0")}${zulu.hour.toString().padLeft(2, "0")}00Z";
return wind;
}
}
Expand Down

0 comments on commit bb49d33

Please sign in to comment.