45 lines
1.2 KiB
Dart
45 lines
1.2 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:anyway/structs/landmark.dart';
|
|
import 'package:anyway/structs/trip.dart';
|
|
import 'package:anyway/modules/step_between_landmarks.dart';
|
|
import 'package:anyway/modules/landmark_card.dart';
|
|
|
|
|
|
// Returns a list of widgets that represent the landmarks matching the given selector
|
|
List<Widget> landmarksList(Trip trip, {required bool Function(Landmark) selector}) {
|
|
|
|
List<Widget> children = [];
|
|
|
|
if (trip.landmarks.isEmpty || trip.landmarks.length <= 1 && trip.landmarks.first.type == typeStart ) {
|
|
children.add(
|
|
const Text("No landmarks in this trip"),
|
|
);
|
|
return children;
|
|
}
|
|
|
|
for (Landmark landmark in trip.landmarks) {
|
|
if (selector(landmark)) {
|
|
children.add(
|
|
LandmarkCard(landmark, trip),
|
|
);
|
|
|
|
if (!landmark.visited) {
|
|
Landmark? nextLandmark = landmark.next;
|
|
while (nextLandmark != null && nextLandmark.visited) {
|
|
nextLandmark = nextLandmark.next;
|
|
}
|
|
if (nextLandmark != null) {
|
|
children.add(
|
|
StepBetweenLandmarks(current: landmark, next: nextLandmark!)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return children;
|
|
}
|