Files
mileograph_flutter/lib/components/calculator/route_summary_widget.dart
petegregoryy 45bd872b23
All checks were successful
Release / meta (push) Successful in 1m39s
Release / linux-build (push) Successful in 1m55s
Release / web-build (push) Successful in 3m12s
Release / android-build (push) Successful in 6m48s
Release / release-master (push) Successful in 22s
Release / release-dev (push) Successful in 28s
add support for network calculation from the calculator
2026-01-27 00:41:27 +00:00

106 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:mileograph_flutter/services/distance_unit_service.dart';
import 'package:provider/provider.dart';
class RouteSummaryWidget extends StatelessWidget {
final double distance;
final VoidCallback onDetailsPressed;
const RouteSummaryWidget({
super.key,
required this.distance,
required this.onDetailsPressed,
});
@override
Widget build(BuildContext context) {
final distanceUnits = context.watch<DistanceUnitService>();
return Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: Text(
"Total Distance: ${distanceUnits.format(distance, decimals: 2)}",
style: Theme.of(context).textTheme.titleMedium,
),
),
TextButton(
onPressed: onDetailsPressed,
child: const Text("View Details"),
),
],
),
);
}
}
class RouteDetailsView extends StatelessWidget {
final List<String> route;
final List<double> costs;
final VoidCallback onBack;
final Set<String> routingPoints;
final VoidCallback? onNetworksPressed;
const RouteDetailsView({
super.key,
required this.route,
required this.costs,
required this.onBack,
this.routingPoints = const {},
this.onNetworksPressed,
});
@override
Widget build(BuildContext context) {
final distanceUnits = context.watch<DistanceUnitService>();
final highlightColor = Theme.of(context).colorScheme.primary;
final mutedColor = Theme.of(context).colorScheme.outlineVariant;
return Column(
children: [
Row(
children: [
TextButton.icon(
onPressed: onBack,
icon: const Icon(Icons.arrow_back),
label: const Text('Back'),
),
const Spacer(),
if (onNetworksPressed != null)
TextButton.icon(
onPressed: onNetworksPressed,
icon: const Icon(Icons.account_tree),
label: const Text('Networks'),
),
],
),
Expanded(
child: ListView.builder(
itemCount: route.length,
itemBuilder: (context, index) {
final label = route[index];
final isRoutingPoint = routingPoints.contains(label);
return ListTile(
leading: Icon(
Icons.circle,
size: 12,
color: isRoutingPoint ? highlightColor : mutedColor,
),
title: Text(
label,
style: isRoutingPoint
? TextStyle(color: highlightColor, fontWeight: FontWeight.w600)
: null,
),
trailing: Text(
distanceUnits.format(costs[index], decimals: 2),
),
);
},
),
),
],
);
}
}