add support for network calculation from the calculator
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
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
This commit is contained in:
@@ -40,6 +40,7 @@ class RouteDetailsView extends StatelessWidget {
|
||||
final List<double> costs;
|
||||
final VoidCallback onBack;
|
||||
final Set<String> routingPoints;
|
||||
final VoidCallback? onNetworksPressed;
|
||||
|
||||
const RouteDetailsView({
|
||||
super.key,
|
||||
@@ -47,6 +48,7 @@ class RouteDetailsView extends StatelessWidget {
|
||||
required this.costs,
|
||||
required this.onBack,
|
||||
this.routingPoints = const {},
|
||||
this.onNetworksPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -56,13 +58,21 @@ class RouteDetailsView extends StatelessWidget {
|
||||
final mutedColor = Theme.of(context).colorScheme.outlineVariant;
|
||||
return Column(
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back'),
|
||||
),
|
||||
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(
|
||||
|
||||
@@ -32,6 +32,8 @@ class _LegCardState extends State<LegCard> {
|
||||
final sharedTo = leg.sharedTo;
|
||||
final distanceUnits = context.watch<DistanceUnitService>();
|
||||
final routeSegments = _parseRouteSegments(leg.route);
|
||||
final networkMileage = _sortedNetworkMileage(leg);
|
||||
final countryMileage = _sortedCountryMileage(leg);
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
@@ -160,10 +162,11 @@ class _LegCardState extends State<LegCard> {
|
||||
),
|
||||
);
|
||||
}
|
||||
if (leg.network.isNotEmpty) {
|
||||
final networkSummary = _networkSummary(leg);
|
||||
if (networkSummary != null) {
|
||||
children.add(
|
||||
Text(
|
||||
leg.network,
|
||||
networkSummary,
|
||||
style: textTheme.labelSmall,
|
||||
),
|
||||
);
|
||||
@@ -285,6 +288,28 @@ class _LegCardState extends State<LegCard> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
if (networkMileage.isNotEmpty || countryMileage.isNotEmpty) ...[
|
||||
Text('Network mileage', style: textTheme.titleSmall),
|
||||
const SizedBox(height: 6),
|
||||
...networkMileage.map(
|
||||
(entry) => Text(
|
||||
'${entry.network}: ${distanceUnits.format(entry.miles, decimals: 1)}',
|
||||
style: textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
if (countryMileage.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text('Country mileage', style: textTheme.titleSmall),
|
||||
const SizedBox(height: 6),
|
||||
...countryMileage.map(
|
||||
(entry) => Text(
|
||||
'${entry.country}: ${distanceUnits.format(entry.miles, decimals: 1)}',
|
||||
style: textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
if (routeSegments.isNotEmpty) ...[
|
||||
Text('Route', style: textTheme.titleSmall),
|
||||
const SizedBox(height: 6),
|
||||
@@ -483,6 +508,33 @@ class _LegCardState extends State<LegCard> {
|
||||
List<String> _parseRouteSegments(List<String> route) {
|
||||
return route.map((e) => e.toString()).where((e) => e.trim().isNotEmpty).toList();
|
||||
}
|
||||
|
||||
List<NetworkMileage> _sortedNetworkMileage(Leg leg) {
|
||||
final items = leg.networkMileage
|
||||
.where((entry) => entry.network.trim().isNotEmpty)
|
||||
.toList();
|
||||
items.sort((a, b) => b.miles.compareTo(a.miles));
|
||||
return items;
|
||||
}
|
||||
|
||||
List<CountryMileage> _sortedCountryMileage(Leg leg) {
|
||||
final items = leg.countryMileage
|
||||
.where((entry) => entry.country.trim().isNotEmpty)
|
||||
.toList();
|
||||
items.sort((a, b) => b.miles.compareTo(a.miles));
|
||||
return items;
|
||||
}
|
||||
|
||||
String? _networkSummary(Leg leg) {
|
||||
final networks = _sortedNetworkMileage(leg);
|
||||
if (networks.isNotEmpty) {
|
||||
return networks.map((entry) => entry.network).join(', ');
|
||||
}
|
||||
if (leg.network.trim().isNotEmpty) {
|
||||
return leg.network;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class _SharedIcons extends StatelessWidget {
|
||||
|
||||
@@ -192,7 +192,7 @@ class _LoginLogoState extends State<_LoginLogo> {
|
||||
}
|
||||
|
||||
String _colorToHex(Color color) {
|
||||
final hex = color.value.toRadixString(16).padLeft(8, '0');
|
||||
final hex = color.toARGB32().toRadixString(16).padLeft(8, '0');
|
||||
return '#${hex.substring(2)}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mileograph_flutter/components/calculator/route_summary_widget.dart';
|
||||
import 'package:mileograph_flutter/objects/objects.dart';
|
||||
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CalculatorDetailsPage extends StatelessWidget {
|
||||
const CalculatorDetailsPage({
|
||||
@@ -34,13 +36,85 @@ class CalculatorDetailsPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: RouteDetailsView(
|
||||
route: parsed.calculatedRoute,
|
||||
costs: parsed.costs,
|
||||
routingPoints: parsed.inputRoute.toSet(),
|
||||
onBack: () => context.pop(),
|
||||
final networks = List<NetworkMileage>.from(parsed.networkMileage)
|
||||
..sort((a, b) => b.miles.compareTo(a.miles));
|
||||
final countries = List<CountryMileage>.from(parsed.countryMileage)
|
||||
..sort((a, b) => b.miles.compareTo(a.miles));
|
||||
|
||||
return Scaffold(
|
||||
endDrawer: _NetworksDrawer(
|
||||
networks: networks,
|
||||
countries: countries,
|
||||
),
|
||||
body: Builder(
|
||||
builder: (scaffoldContext) => Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: RouteDetailsView(
|
||||
route: parsed.calculatedRoute,
|
||||
costs: parsed.costs,
|
||||
routingPoints: parsed.inputRoute.toSet(),
|
||||
onBack: () => context.pop(),
|
||||
onNetworksPressed: () =>
|
||||
Scaffold.of(scaffoldContext).openEndDrawer(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NetworksDrawer extends StatelessWidget {
|
||||
const _NetworksDrawer({
|
||||
required this.networks,
|
||||
required this.countries,
|
||||
});
|
||||
|
||||
final List<NetworkMileage> networks;
|
||||
final List<CountryMileage> countries;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final distanceUnits = context.watch<DistanceUnitService>();
|
||||
return Drawer(
|
||||
child: SafeArea(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Text(
|
||||
'Networks',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (networks.isEmpty)
|
||||
const Text('No network mileage data.')
|
||||
else
|
||||
...networks.map(
|
||||
(entry) => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(entry.network),
|
||||
trailing:
|
||||
Text(distanceUnits.format(entry.miles, decimals: 2)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Countries',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (countries.isEmpty)
|
||||
const Text('No country mileage data.')
|
||||
else
|
||||
...countries.map(
|
||||
(entry) => ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(entry.country),
|
||||
trailing:
|
||||
Text(distanceUnits.format(entry.miles, decimals: 2)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -813,17 +813,17 @@ List<DateTime> _buildBoundaries(
|
||||
for (final seg in segments) {
|
||||
boundaryDates.add(seg.start);
|
||||
boundaryDates.add(seg.end);
|
||||
minStart = minStart == null || seg.start.isBefore(minStart!)
|
||||
minStart = minStart == null || seg.start.isBefore(minStart)
|
||||
? seg.start
|
||||
: minStart;
|
||||
maxEnd = maxEnd == null || seg.end.isAfter(maxEnd!) ? seg.end : maxEnd;
|
||||
maxEnd = maxEnd == null || seg.end.isAfter(maxEnd) ? seg.end : maxEnd;
|
||||
}
|
||||
minStart ??= now.subtract(const Duration(days: 1));
|
||||
final effectiveMinStart = minStart ?? now.subtract(const Duration(days: 1));
|
||||
final effectiveMaxEnd = maxEnd ?? now;
|
||||
boundaryDates.add(effectiveMaxEnd);
|
||||
var boundaries = boundaryDates.toList()..sort();
|
||||
if (boundaries.length < 2) {
|
||||
boundaries = [minStart!, effectiveMaxEnd];
|
||||
boundaries = [effectiveMinStart, effectiveMaxEnd];
|
||||
}
|
||||
return boundaries;
|
||||
}
|
||||
|
||||
@@ -1399,16 +1399,18 @@ class _NewEntryPageState extends State<NewEntryPage> {
|
||||
singleColumn: true,
|
||||
),
|
||||
),
|
||||
const Divider(height: 24),
|
||||
TextFormField(
|
||||
controller: _networkController,
|
||||
textCapitalization: TextCapitalization.characters,
|
||||
inputFormatters: const [_UpperCaseTextFormatter()],
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Network',
|
||||
border: OutlineInputBorder(),
|
||||
if (_useManualMileage) ...[
|
||||
const Divider(height: 24),
|
||||
TextFormField(
|
||||
controller: _networkController,
|
||||
textCapitalization: TextCapitalization.characters,
|
||||
inputFormatters: const [_UpperCaseTextFormatter()],
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Network',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
TextFormField(
|
||||
controller: _notesController,
|
||||
maxLines: 3,
|
||||
@@ -1520,6 +1522,9 @@ class _NewEntryPageState extends State<NewEntryPage> {
|
||||
onSelected: (val) {
|
||||
setState(() {
|
||||
_useManualMileage = val;
|
||||
if (!val) {
|
||||
_networkController.clear();
|
||||
}
|
||||
if (val && _routeResult != null) {
|
||||
_mileageController.text = _formatDistance(
|
||||
distanceUnitService,
|
||||
|
||||
@@ -18,7 +18,7 @@ extension _NewEntrySubmitLogic on _NewEntryPageState {
|
||||
}
|
||||
}
|
||||
|
||||
if (_networkController.text.trim().isEmpty) {
|
||||
if (_useManualMileage && _networkController.text.trim().isEmpty) {
|
||||
missing.add('Network');
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ extension _NewEntrySubmitLogic on _NewEntryPageState {
|
||||
final isEditingExisting = _isEditing && widget.editLegId != null;
|
||||
|
||||
try {
|
||||
final commonPayload = {
|
||||
final commonPayload = {
|
||||
if (isEditingExisting) "leg_id": widget.editLegId,
|
||||
"leg_trip": _selectedTripId,
|
||||
"leg_begin_time": _legDateTime.toIso8601String(),
|
||||
@@ -104,7 +104,8 @@ extension _NewEntrySubmitLogic on _NewEntryPageState {
|
||||
"leg_destination_time": destinationTime.toIso8601String(),
|
||||
"leg_notes": _notesController.text.trim(),
|
||||
"leg_headcode": _headcodeController.text.trim(),
|
||||
"leg_network": _networkController.text.trim(),
|
||||
if (_useManualMileage)
|
||||
"leg_network": _networkController.text.trim(),
|
||||
"leg_origin": _originController.text.trim(),
|
||||
"leg_destination": _destinationController.text.trim(),
|
||||
"leg_begin_delay": beginDelay,
|
||||
|
||||
@@ -170,6 +170,21 @@ class _StatsPageState extends State<StatsPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (year.topCountries.isNotEmpty)
|
||||
_buildSection<StatsCountryMileage>(
|
||||
context,
|
||||
title: 'Top countries',
|
||||
items: year.topCountries,
|
||||
emptyLabel: 'No country data',
|
||||
itemBuilder: (item, index) => ListTile(
|
||||
dense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
title: Text(item.country),
|
||||
trailing: Text(
|
||||
distanceUnits.format(item.mileage, decimals: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildSection<StatsStationVisits>(
|
||||
context,
|
||||
title: 'Top stations',
|
||||
|
||||
@@ -699,11 +699,8 @@ class _TractionPageState extends State<TractionPage> {
|
||||
);
|
||||
|
||||
final hasAdminActions = isElevated;
|
||||
final hasMoreMenu = true;
|
||||
|
||||
final moreButton = !hasMoreMenu
|
||||
? null
|
||||
: PopupMenuButton<_TractionMoreAction>(
|
||||
final moreButton = PopupMenuButton<_TractionMoreAction>(
|
||||
tooltip: 'More options',
|
||||
onSelected: (action) async {
|
||||
switch (action) {
|
||||
@@ -859,11 +856,11 @@ class _TractionPageState extends State<TractionPage> {
|
||||
final desktopActions = [
|
||||
refreshButton,
|
||||
newTractionButton,
|
||||
if (moreButton != null) moreButton,
|
||||
moreButton,
|
||||
];
|
||||
|
||||
final mobileActions = [
|
||||
if (moreButton != null) moreButton,
|
||||
moreButton,
|
||||
newTractionButton,
|
||||
refreshButton,
|
||||
];
|
||||
@@ -1041,8 +1038,9 @@ class _TractionPageState extends State<TractionPage> {
|
||||
if (!mounted) return;
|
||||
errorMessage = e.toString();
|
||||
} finally {
|
||||
if (!mounted) return;
|
||||
setModalState(() => uploading = false);
|
||||
if (mounted) {
|
||||
setModalState(() => uploading = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user