Add ability to select distance unit
Some checks failed
Some checks failed
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mileograph_flutter/services/authservice.dart';
|
||||
import 'package:mileograph_flutter/services/api_service.dart';
|
||||
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
||||
import 'package:mileograph_flutter/services/endpoint_service.dart';
|
||||
import 'package:mileograph_flutter/services/data_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -175,10 +176,11 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final endpointService = context.watch<EndpointService>();
|
||||
final distanceUnitService = context.watch<DistanceUnitService>();
|
||||
final loggedIn = context.select<AuthService, bool>(
|
||||
(auth) => auth.isLoggedIn,
|
||||
);
|
||||
if (!endpointService.isLoaded) {
|
||||
if (!endpointService.isLoaded || !distanceUnitService.isLoaded) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
@@ -204,6 +206,34 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Distance units',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Choose how distances are displayed across the app.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SegmentedButton<DistanceUnit>(
|
||||
segments: DistanceUnit.values
|
||||
.map(
|
||||
(unit) => ButtonSegment<DistanceUnit>(
|
||||
value: unit,
|
||||
label: Text(unit.label),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
selected: {distanceUnitService.unit},
|
||||
onSelectionChanged: (selection) {
|
||||
final next = selection.first;
|
||||
distanceUnitService.setUnit(next);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'API endpoint',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
|
||||
Reference in New Issue
Block a user