96 lines
3.0 KiB
Dart
96 lines
3.0 KiB
Dart
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),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|