feat(#977): Location is a top-level settings category and the only home for GPS
New LocationView pane directly under Radio Settings: the GPS toggle and the 0xC1 GPS status, then Coordinates and Position reporting interval as rows that open their own editors. The GPS toggle and the Location row leave Node Settings, and the combined Location dialog is gone, so GPS appears in exactly one place. What the radio sees is unchanged: the same gps and gps_interval custom vars, the same 60 to 86399 s validation, the same error messages. One deliberate difference: coordinates and the interval now save independently. The old dialog returned early on an empty or invalid interval and silently skipped saving the coordinates too. Tests: settings_location_test pins placement from both sides and the writes. Two existing settings tests now scroll a category into view before tapping it; the lazily built category list put Debug past a 900 px viewport once Location was added. untranslated.json is a full regeneration and also picks up two block_noRadio keys dev was already missing. Agent: MistyLynx (session 6c0d5797) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>feat/975-settings-restructure
parent
e3e69da9fb
commit
e85d7aeb5b
@ -0,0 +1,432 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../connector/meshcore_connector.dart';
|
||||
import '../../helpers/snack_bar_builder.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../models/offband_gps_status.dart';
|
||||
|
||||
/// Embeddable view (no Scaffold) for the Location settings pane (#977).
|
||||
///
|
||||
/// The single home for GPS: the GPS control and its status, the node's
|
||||
/// coordinates, and the position reporting interval. These used to sit in Node
|
||||
/// Settings and a Location dialog, with the GPS toggle in both. The radio sees
|
||||
/// the same writes as before: the same custom vars, the same validation, the
|
||||
/// same error messages.
|
||||
///
|
||||
/// One deliberate difference: coordinates and the reporting interval now save
|
||||
/// independently. In the old dialog an empty or invalid interval returned early
|
||||
/// and silently skipped the coordinates as well.
|
||||
class LocationView extends StatefulWidget {
|
||||
const LocationView({super.key});
|
||||
|
||||
@override
|
||||
State<LocationView> createState() => _LocationViewState();
|
||||
}
|
||||
|
||||
class _LocationViewState extends State<LocationView> {
|
||||
OffbandGpsStatus? _gpsStatus;
|
||||
bool _queryingGps = false;
|
||||
bool _queriedOnce = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final connector = context.watch<MeshCoreConnector>();
|
||||
final customVars = connector.currentCustomVars ?? const <String, String>{};
|
||||
// A radio with no GPS hardware reports no `gps` custom var at all, which is
|
||||
// how the old screens decided to hide the GPS controls too.
|
||||
final hasGps = customVars.containsKey('gps');
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
if (hasGps) ...[
|
||||
Card(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile(
|
||||
secondary: const Icon(Icons.gps_fixed),
|
||||
title: Text(l10n.settings_locationGPSEnable),
|
||||
subtitle: Text(l10n.settings_locationGPSEnableSubtitle),
|
||||
value: customVars['gps'] == '1',
|
||||
onChanged: (value) => _setGpsEnabled(connector, value),
|
||||
),
|
||||
if (connector.supportsOffbandGps)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
child: _buildGpsQuerySection(
|
||||
context,
|
||||
_gpsStatus ?? connector.offbandGpsStatus,
|
||||
() => _queryGps(connector),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.location_on_outlined),
|
||||
title: Text(l10n.settings_locationCoordinates),
|
||||
subtitle: Text(_coordinatesText(connector)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _editCoordinates(connector),
|
||||
),
|
||||
if (hasGps) ...[
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.schedule),
|
||||
title: Text(l10n.settings_locationReportInterval),
|
||||
subtitle: Text(_intervalText(customVars)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _editReportInterval(connector, customVars),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _coordinatesText(MeshCoreConnector connector) {
|
||||
final lat = connector.selfLatitude;
|
||||
final lon = connector.selfLongitude;
|
||||
if (lat == null || lon == null) return context.l10n.settings_locationNotSet;
|
||||
return '${lat.toStringAsFixed(6)}, ${lon.toStringAsFixed(6)}';
|
||||
}
|
||||
|
||||
String _intervalText(Map<String, String> customVars) {
|
||||
final l10n = context.l10n;
|
||||
final seconds = int.tryParse(customVars['gps_interval'] ?? '');
|
||||
if (seconds == null || seconds <= 0) return l10n.settings_locationNotSet;
|
||||
if (seconds % 60 == 0) {
|
||||
return l10n.settings_locationEveryMinutes(seconds ~/ 60);
|
||||
}
|
||||
return l10n.settings_locationEverySeconds(seconds);
|
||||
}
|
||||
|
||||
Future<void> _setGpsEnabled(MeshCoreConnector connector, bool value) async {
|
||||
try {
|
||||
await connector.setCustomVar(value ? 'gps:1' : 'gps:0');
|
||||
} catch (_) {
|
||||
if (mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: const Text(
|
||||
'Could not update GPS setting. Please try again.',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _queryGps(MeshCoreConnector connector) async {
|
||||
setState(() => _queryingGps = true);
|
||||
final s = await connector.requestOffbandGps();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_queryingGps = false;
|
||||
_queriedOnce = true;
|
||||
_gpsStatus = s;
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildGpsQuerySection(
|
||||
BuildContext context,
|
||||
OffbandGpsStatus? status,
|
||||
VoidCallback onRefresh,
|
||||
) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
|
||||
Widget row(String label, String value) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label),
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.w500)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final children = <Widget>[
|
||||
const Divider(),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.settings_gpsStatusTitle,
|
||||
style: theme.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
if (_queryingGps)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
)
|
||||
else
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: l10n.settings_gpsStatusRefresh,
|
||||
onPressed: onRefresh,
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
if (status != null) {
|
||||
final live = status.hasLiveFix;
|
||||
final color = live ? Colors.green : Colors.orange;
|
||||
children.add(
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
live ? Icons.gps_fixed : Icons.gps_off,
|
||||
size: 18,
|
||||
color: color,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
live
|
||||
? l10n.settings_gpsStatusLiveFix
|
||||
: l10n.settings_gpsStatusNoFix,
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
children.add(const SizedBox(height: 8));
|
||||
final coords = (status.latitude != null && status.longitude != null)
|
||||
? '${status.latitude!.toStringAsFixed(6)}, '
|
||||
'${status.longitude!.toStringAsFixed(6)}'
|
||||
: '—';
|
||||
children.add(row(l10n.settings_gpsStatusCoords, coords));
|
||||
children.add(
|
||||
row(l10n.settings_gpsStatusSats, status.satellites?.toString() ?? '—'),
|
||||
);
|
||||
children.add(
|
||||
row(
|
||||
l10n.settings_gpsStatusAltitude,
|
||||
status.altitudeCm != null
|
||||
? '${(status.altitudeCm! / 100).toStringAsFixed(1)} m'
|
||||
: '—',
|
||||
),
|
||||
);
|
||||
final t = status.timestampUtc?.toLocal();
|
||||
final ml = MaterialLocalizations.of(context);
|
||||
final timeStr = t == null
|
||||
? '—'
|
||||
: '${ml.formatCompactDate(t)} '
|
||||
'${ml.formatTimeOfDay(TimeOfDay.fromDateTime(t))}';
|
||||
children.add(row(l10n.settings_gpsStatusTime, timeStr));
|
||||
} else {
|
||||
children.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
_queriedOnce
|
||||
? l10n.settings_gpsStatusNoResponse
|
||||
: l10n.settings_gpsStatusTapRefresh,
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
|
||||
void _editCoordinates(MeshCoreConnector connector) {
|
||||
final l10n = context.l10n;
|
||||
final latController = TextEditingController(
|
||||
text: connector.selfLatitude?.toStringAsFixed(6) ?? '',
|
||||
);
|
||||
final lonController = TextEditingController(
|
||||
text: connector.selfLongitude?.toStringAsFixed(6) ?? '',
|
||||
);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.settings_locationCoordinates),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: latController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_latitude,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
signed: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: lonController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_longitude,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
signed: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
Navigator.pop(dialogContext);
|
||||
|
||||
final latText = latController.text.trim();
|
||||
final lonText = lonController.text.trim();
|
||||
if (latText.isEmpty && lonText.isEmpty) return;
|
||||
|
||||
final lat = latText.isNotEmpty
|
||||
? double.tryParse(latText)
|
||||
: connector.selfLatitude;
|
||||
final lon = lonText.isNotEmpty
|
||||
? double.tryParse(lonText)
|
||||
: connector.selfLongitude;
|
||||
if (lat == null || lon == null) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationBothRequired),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (lat < -90 || lat > 90 || lon < -180 || lon > 180) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationInvalid),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await connector.setNodeLocation(lat: lat, lon: lon);
|
||||
await connector.refreshDeviceInfo();
|
||||
} catch (_) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Could not update location. Please try again.',
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationUpdated),
|
||||
);
|
||||
},
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _editReportInterval(
|
||||
MeshCoreConnector connector,
|
||||
Map<String, String> customVars,
|
||||
) {
|
||||
final l10n = context.l10n;
|
||||
// Same default the old dialog pre-filled: 900 seconds when the radio has
|
||||
// not reported an interval.
|
||||
final current = int.tryParse(customVars['gps_interval'] ?? '') ?? 900;
|
||||
final intervalController = TextEditingController(text: current.toString());
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(l10n.settings_locationReportInterval),
|
||||
content: TextField(
|
||||
controller: intervalController,
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.settings_locationIntervalSec,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: false,
|
||||
signed: false,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: Text(l10n.common_cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
Navigator.pop(dialogContext);
|
||||
|
||||
final intervalText = intervalController.text.trim();
|
||||
if (intervalText.isEmpty) return;
|
||||
|
||||
final interval = int.tryParse(intervalText);
|
||||
if (interval == null || interval < 60 || interval >= 86400) {
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationIntervalInvalid),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await connector.setCustomVar('gps_interval:$interval');
|
||||
await connector.refreshDeviceInfo();
|
||||
} catch (_) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Could not update location. Please try again.',
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.settings_locationUpdated),
|
||||
);
|
||||
},
|
||||
child: Text(l10n.common_save),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,227 @@
|
||||
// Pins #977: Location is a top-level Settings category directly under Radio
|
||||
// Settings, and the only place GPS lives. Each placement is asserted from both
|
||||
// sides (present in Location, absent from Node Settings) so a control drifting
|
||||
// back fails CI. The writes the radio sees are pinned too: this was a move, not
|
||||
// a behavior change, apart from coordinates and interval saving independently.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/screens/settings_screen.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/storage/drift/blob_store.dart';
|
||||
import 'package:meshcore_open/storage/drift/offband_database.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:drift/native.dart';
|
||||
|
||||
/// Supplies custom vars and coordinates, and records every write so the
|
||||
/// negative cases can prove nothing left the client.
|
||||
class _SpyConnector extends MeshCoreConnector {
|
||||
Map<String, String>? vars;
|
||||
double? lat;
|
||||
double? lon;
|
||||
final List<String> customVarWrites = [];
|
||||
final List<(double, double)> locationWrites = [];
|
||||
|
||||
@override
|
||||
Map<String, String>? get currentCustomVars => vars;
|
||||
|
||||
@override
|
||||
double? get selfLatitude => lat;
|
||||
|
||||
@override
|
||||
double? get selfLongitude => lon;
|
||||
|
||||
@override
|
||||
Future<void> setCustomVar(String value) async {
|
||||
customVarWrites.add(value);
|
||||
final sep = value.indexOf(':');
|
||||
if (sep > 0) {
|
||||
(vars ??= <String, String>{})[value.substring(0, sep)] = value.substring(
|
||||
sep + 1,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setNodeLocation({
|
||||
required double lat,
|
||||
required double lon,
|
||||
}) async {
|
||||
locationWrites.add((lat, lon));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> refreshDeviceInfo() async {}
|
||||
}
|
||||
|
||||
void main() {
|
||||
late OffbandDatabase db;
|
||||
late _SpyConnector connector;
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
db = OffbandDatabase(NativeDatabase.memory());
|
||||
BlobStore.overrideForTest(BlobStore(db));
|
||||
connector = _SpyConnector();
|
||||
connector.sendFrameOverrideForTest = (_) {};
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
BlobStore.clearTestOverride();
|
||||
await db.close();
|
||||
});
|
||||
|
||||
Future<void> pumpSettings(WidgetTester tester) async {
|
||||
// Narrow layout: the category list renders and each pane is pushed.
|
||||
tester.view.physicalSize = const Size(400, 1000);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<MeshCoreConnector>.value(value: connector),
|
||||
ChangeNotifierProvider<AppSettingsService>(
|
||||
create: (_) => AppSettingsService(),
|
||||
),
|
||||
],
|
||||
child: const MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: SettingsScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> openPane(WidgetTester tester, String title) async {
|
||||
await tester.tap(find.text(title));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('Location sits directly under Radio Settings', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
|
||||
final radio = tester.getTopLeft(find.text('Radio Settings')).dy;
|
||||
final location = tester.getTopLeft(find.text('Location')).dy;
|
||||
final stats = tester.getTopLeft(find.text('Radio stats')).dy;
|
||||
expect(radio, lessThan(location));
|
||||
expect(location, lessThan(stats));
|
||||
expect(find.text('GPS, coordinates, and reporting'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Node Settings no longer carries GPS or a Location row', (
|
||||
tester,
|
||||
) async {
|
||||
// A GPS radio: before #977 this showed the toggle in Node Settings.
|
||||
connector.vars = {'gps': '1', 'gps_interval': '900'};
|
||||
await pumpSettings(tester);
|
||||
await openPane(tester, 'Node Settings');
|
||||
|
||||
expect(find.text('GPS Enable'), findsNothing);
|
||||
expect(find.byType(SwitchListTile), findsNothing);
|
||||
expect(find.text('GPS coordinates'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a GPS radio shows the toggle and the interval in Location', (
|
||||
tester,
|
||||
) async {
|
||||
connector.vars = {'gps': '1', 'gps_interval': '900'};
|
||||
connector.lat = 39.103118;
|
||||
connector.lon = -84.51202;
|
||||
await pumpSettings(tester);
|
||||
await openPane(tester, 'Location');
|
||||
|
||||
expect(find.text('GPS Enable'), findsOneWidget);
|
||||
final toggle = tester.widget<SwitchListTile>(find.byType(SwitchListTile));
|
||||
expect(toggle.value, isTrue);
|
||||
expect(find.text('39.103118, -84.512020'), findsOneWidget);
|
||||
expect(find.text('Every 15 minutes'), findsOneWidget);
|
||||
|
||||
// The toggle writes the same custom var it always did.
|
||||
await tester.tap(find.byType(SwitchListTile));
|
||||
await tester.pumpAndSettle();
|
||||
expect(connector.customVarWrites, equals(['gps:0']));
|
||||
});
|
||||
|
||||
testWidgets('a radio without GPS shows coordinates only', (tester) async {
|
||||
connector.vars = {};
|
||||
await pumpSettings(tester);
|
||||
await openPane(tester, 'Location');
|
||||
|
||||
expect(find.text('Coordinates'), findsOneWidget);
|
||||
expect(find.text('Not set'), findsOneWidget);
|
||||
expect(find.text('GPS Enable'), findsNothing);
|
||||
expect(find.text('Position reporting interval'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('coordinates save on their own, without touching the interval', (
|
||||
tester,
|
||||
) async {
|
||||
// No interval reported. In the old combined dialog an empty interval
|
||||
// returned early and skipped the coordinates; they must now save.
|
||||
connector.vars = {'gps': '1'};
|
||||
await pumpSettings(tester);
|
||||
await openPane(tester, 'Location');
|
||||
|
||||
await tester.tap(find.text('Coordinates'));
|
||||
await tester.pumpAndSettle();
|
||||
final fields = find.byType(TextField);
|
||||
await tester.enterText(fields.at(0), '39.5');
|
||||
await tester.enterText(fields.at(1), '-84.25');
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(connector.locationWrites, equals([(39.5, -84.25)]));
|
||||
expect(connector.customVarWrites, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('an out-of-range interval is refused and nothing is sent', (
|
||||
tester,
|
||||
) async {
|
||||
connector.vars = {'gps': '1', 'gps_interval': '900'};
|
||||
await pumpSettings(tester);
|
||||
await openPane(tester, 'Location');
|
||||
|
||||
await tester.tap(find.text('Position reporting interval'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextField), '59');
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(connector.customVarWrites, isEmpty);
|
||||
expect(
|
||||
find.text(
|
||||
'Interval must be at least 60 seconds, and less than 86400 seconds.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a valid interval writes the same custom var as before', (
|
||||
tester,
|
||||
) async {
|
||||
connector.vars = {'gps': '1', 'gps_interval': '900'};
|
||||
await pumpSettings(tester);
|
||||
await openPane(tester, 'Location');
|
||||
|
||||
await tester.tap(find.text('Position reporting interval'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextField), '120');
|
||||
await tester.tap(find.text('Save'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(connector.customVarWrites, equals(['gps_interval:120']));
|
||||
expect(connector.locationWrites, isEmpty);
|
||||
expect(find.text('Every 2 minutes'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in new issue