feat(wip): implement trip persistence through a local repository. Include loaded trips in the start page UI
This commit is contained in:
95
frontend/lib/presentation/widgets/trip_summary_card.dart
Normal file
95
frontend/lib/presentation/widgets/trip_summary_card.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:anyway/domain/entities/trip.dart';
|
||||
import 'package:anyway/presentation/utils/trip_location_utils.dart';
|
||||
import 'package:anyway/presentation/widgets/trip_map.dart';
|
||||
|
||||
class TripSummaryCard extends StatefulWidget {
|
||||
const TripSummaryCard({super.key, required this.trip, required this.onTap});
|
||||
|
||||
final Trip trip;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
State<TripSummaryCard> createState() => _TripSummaryCardState();
|
||||
}
|
||||
|
||||
class _TripSummaryCardState extends State<TripSummaryCard> {
|
||||
late Future<String> _cityFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cityFuture = TripLocationUtils.resolveCityName(widget.trip);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant TripSummaryCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.trip.uuid != widget.trip.uuid) {
|
||||
_cityFuture = TripLocationUtils.resolveCityName(widget.trip);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final landmarksCount = widget.trip.landmarks.length;
|
||||
final startCoords = TripLocationUtils.startCoordinates(widget.trip);
|
||||
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TripMap(
|
||||
trip: widget.trip,
|
||||
showRoute: false,
|
||||
interactive: false,
|
||||
height: 180,
|
||||
borderRadius: 0,
|
||||
),
|
||||
// TODO - a more useful information to include will be the duration and the time of creation. But we are not there yet.
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 4),
|
||||
child: FutureBuilder<String>(
|
||||
future: _cityFuture,
|
||||
builder: (context, snapshot) {
|
||||
final title = snapshot.data ?? 'Trip ${widget.trip.uuid}';
|
||||
return Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
// TODO - start should be more descriptive. or omitted
|
||||
child: Text(
|
||||
startCoords == null
|
||||
? 'Start: unknown'
|
||||
: 'Start: ${startCoords[0].toStringAsFixed(4)}, '
|
||||
'${startCoords[1].toStringAsFixed(4)}',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.route, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text('$landmarksCount stops'),
|
||||
const Spacer(),
|
||||
const Icon(Icons.chevron_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user