anyway/frontend/lib/modules/trips_overview.dart
Remy Moll d5e0b7d51a
Some checks failed
Build and push docker image / Build (pull_request) Failing after 2m49s
Build and release APK / Build APK (pull_request) Successful in 5m48s
Build web / Build Web (pull_request) Successful in 1m32s
Beginning to use different contexts
2024-06-03 13:51:01 +02:00

65 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:fast_network_navigation/layout.dart';
import 'package:fast_network_navigation/structs/trip.dart';
import 'package:fast_network_navigation/utils/get_trips.dart';
class TripsOverview extends StatefulWidget {
const TripsOverview({super.key});
@override
State<TripsOverview> createState() => _TripsOverviewState();
}
class _TripsOverviewState extends State<TripsOverview> {
final Future<List<Trip>> _trips = loadTrips();
Widget listBuild (BuildContext context, AsyncSnapshot<List<Trip>> snapshot) {
List<Widget> children;
if (snapshot.hasData) {
children = List<Widget>.generate(snapshot.data!.length, (index) {
Trip trip = snapshot.data![index];
return ListTile(
title: Text("Trip to ${trip.cityName} (${trip.landmarks.length} stops)"),
leading: Icon(Icons.pin_drop),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => BasePage(mainScreen: "map") //, trip: trip)
)
);
},
);
});
} else if (snapshot.hasError) {
children = [
const Icon(
Icons.error_outline,
color: Colors.red,
size: 60,
),
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text('Error: ${snapshot.error}'),
),
];
} else {
children = [Center(child: CircularProgressIndicator())];
}
return ListView(
children: children,
);
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _trips,
builder: listBuild,
);
}
}