Public Access
feat: implement route creating from segment and in UI
This commit is contained in:
+48
-15
@@ -222,7 +222,12 @@ class StationList extends StatelessWidget {
|
||||
|
||||
class ChooseDeparturePage extends StatefulWidget {
|
||||
final Station startStation;
|
||||
const ChooseDeparturePage({super.key, required this.startStation});
|
||||
final int? journeyId;
|
||||
const ChooseDeparturePage({
|
||||
super.key,
|
||||
this.journeyId,
|
||||
required this.startStation,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChooseDeparturePage> createState() => _ChooseDeparturePageState();
|
||||
@@ -231,6 +236,7 @@ class ChooseDeparturePage extends StatefulWidget {
|
||||
class _ChooseDeparturePageState extends State<ChooseDeparturePage> {
|
||||
List<Departure> departureList = [];
|
||||
Departure? _selectedDeparture;
|
||||
|
||||
void loadDepartures(Station startStation) async {
|
||||
departureList = await ApiHandler.departures(startStation.id);
|
||||
setState(() {});
|
||||
@@ -281,7 +287,10 @@ class _ChooseDeparturePageState extends State<ChooseDeparturePage> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChooseArrivalPage(departure: departure),
|
||||
builder: (context) => ChooseArrivalPage(
|
||||
departure: departure,
|
||||
journeyId: widget.journeyId,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -313,8 +322,11 @@ class DepartureList extends StatelessWidget {
|
||||
|
||||
class ChooseArrivalPage extends StatefulWidget {
|
||||
final Departure departure;
|
||||
final int? journeyId;
|
||||
|
||||
const ChooseArrivalPage({
|
||||
super.key,
|
||||
this.journeyId,
|
||||
required this.departure,
|
||||
});
|
||||
|
||||
@@ -323,11 +335,11 @@ class ChooseArrivalPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ChooseArrivalPageState extends State<ChooseArrivalPage> {
|
||||
List<Departure> departureList = [];
|
||||
List<Departure> arrivalList = [];
|
||||
Departure? _selectedDeparture;
|
||||
|
||||
void loadArrivals(String ref) async {
|
||||
departureList = await ApiHandler.tripDetail(
|
||||
arrivalList = await ApiHandler.tripDetail(
|
||||
ref,
|
||||
startStationId: widget.departure.stationId,
|
||||
);
|
||||
@@ -352,7 +364,8 @@ class _ChooseArrivalPageState extends State<ChooseArrivalPage> {
|
||||
child: SizedBox(
|
||||
height: 400,
|
||||
child: ArrivalList(
|
||||
departureList: departureList,
|
||||
departure: widget.departure,
|
||||
arrivalList: arrivalList,
|
||||
onTapped: _handleArrivalTapped,
|
||||
),
|
||||
),
|
||||
@@ -372,26 +385,46 @@ class _ChooseArrivalPageState extends State<ChooseArrivalPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleArrivalTapped(Departure departure) async {
|
||||
void _handleArrivalTapped(Departure departure, Departure arrival) async {
|
||||
// setState(() {
|
||||
// _selectedDeparture = departure;
|
||||
// });
|
||||
Station startStation = await Station.dbGet(departure.stationId);
|
||||
departure.dbInsert;
|
||||
arrival.dbInsert;
|
||||
Segment newSegment = await Segment.fromDepartures(departure, arrival);
|
||||
Station startStation = await Station.dbGet(arrival.stationId);
|
||||
int journeyId;
|
||||
if (widget.journeyId == null) {
|
||||
Journey journey = await Journey.fromSegment(newSegment);
|
||||
journeyId = journey.id as int;
|
||||
} else {
|
||||
Segment segment = await newSegment;
|
||||
Journey.dbAppendJourneySegment(
|
||||
widget.journeyId as int,
|
||||
segment.id as int,
|
||||
);
|
||||
journeyId = widget.journeyId as int;
|
||||
}
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChooseDeparturePage(startStation: startStation),
|
||||
builder: (context) => ChooseDeparturePage(
|
||||
startStation: startStation,
|
||||
journeyId: journeyId,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ArrivalList extends StatelessWidget {
|
||||
final List<Departure> departureList;
|
||||
final ValueChanged<Departure> onTapped;
|
||||
final Departure departure;
|
||||
final List<Departure> arrivalList;
|
||||
final Function onTapped;
|
||||
|
||||
const ArrivalList({
|
||||
required this.departureList,
|
||||
required this.departure,
|
||||
required this.arrivalList,
|
||||
required this.onTapped,
|
||||
});
|
||||
|
||||
@@ -399,11 +432,11 @@ class ArrivalList extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
children: [
|
||||
for (Departure departure in departureList)
|
||||
for (Departure arrival in arrivalList)
|
||||
ListTile(
|
||||
title: Text(departure.stationName),
|
||||
subtitle: Text(departure.arrivalTime.toString()),
|
||||
onTap: () => onTapped(departure),
|
||||
title: Text(arrival.stationName),
|
||||
subtitle: Text(arrival.arrivalTime.toString()),
|
||||
onTap: () => onTapped(departure, arrival),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user