diff --git a/lib/main.dart b/lib/main.dart index 39a1e07..9e8c1da 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -280,7 +280,9 @@ class _ChooseDeparturePageState extends State { // }); Navigator.push( context, - MaterialPageRoute(builder: (context) => ChooseStationPage()), + MaterialPageRoute( + builder: (context) => ChooseArrivalPage(departure: departure), + ), ); } } @@ -308,3 +310,99 @@ class DepartureList extends StatelessWidget { ); } } + +class ChooseArrivalPage extends StatefulWidget { + final Departure departure; + const ChooseArrivalPage({ + super.key, + required this.departure, + }); + + @override + State createState() => _ChooseArrivalPageState(); +} + +class _ChooseArrivalPageState extends State { + List departureList = []; + Departure? _selectedDeparture; + + void loadArrivals(String ref) async { + departureList = await ApiHandler.tripDetail(ref); + setState(() {}); + } + + @override + initState() { + loadArrivals(widget.departure.ref); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Arrivals for ${widget.departure.vehicleName}'), + ), + body: Center( + child: Column( + children: [ + Expanded( + child: SizedBox( + height: 400, + child: DepartureList( + departureList: departureList, + onTapped: _handleArrivalTapped, + ), + ), + ), + ElevatedButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => ChooseStationPage()), + ); + }, + child: const Text('Vehicle picked!'), + ), + ], + ), + ), + ); + } + + void _handleArrivalTapped(Departure departure) async { + // setState(() { + // _selectedDeparture = departure; + // }); + Station startStation = await Station.dbGet(departure.stationId); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ChooseDeparturePage(startStation: startStation), + ), + ); + } +} + +class ArrivalList extends StatelessWidget { + final List departureList; + final ValueChanged onTapped; + + const ArrivalList({ + required this.departureList, + required this.onTapped, + }); + + @override + Widget build(BuildContext context) { + return ListView( + children: [ + for (Departure departure in departureList) + ListTile( + title: Text(departure.stationId), + subtitle: Text(departure.arrivalTime.toString()), + onTap: () => onTapped(departure), + ), + ], + ); + } +} \ No newline at end of file