Merge branch 'spike/block2-derisking'

This commit is contained in:
vjrj 2026-07-10 11:10:07 +02:00
commit dc599dae30
9 changed files with 69 additions and 31 deletions

View file

@ -357,7 +357,7 @@
"sharedCount": "Shared {n} seeds nearby", "sharedCount": "Shared {n} seeds nearby",
"nothingToShare": "Mark some seeds to give, swap or sell first", "nothingToShare": "Mark some seeds to give, swap or sell first",
"useLocation": "Use my approximate location", "useLocation": "Use my approximate location",
"locationFailed": "Couldn't get your location", "locationFailed": "Couldn't get your location — check that location is on and the permission is granted",
"queued": "Saved — we'll share these when you're connected" "queued": "Saved — we'll share these when you're connected"
}, },
"chat": { "chat": {

View file

@ -357,7 +357,7 @@
"sharedCount": "Compartidas {n} semillas", "sharedCount": "Compartidas {n} semillas",
"nothingToShare": "Marca antes algunas semillas para regalar, cambiar o vender", "nothingToShare": "Marca antes algunas semillas para regalar, cambiar o vender",
"useLocation": "Usar mi ubicación aproximada", "useLocation": "Usar mi ubicación aproximada",
"locationFailed": "No se pudo obtener tu ubicación", "locationFailed": "No se pudo obtener tu ubicación — comprueba que la ubicación está activada y el permiso concedido",
"queued": "Guardado — las compartiremos cuando tengas conexión" "queued": "Guardado — las compartiremos cuando tengas conexión"
}, },
"chat": { "chat": {

View file

@ -353,7 +353,7 @@
"sharedCount": "Partilhadas {n} sementes", "sharedCount": "Partilhadas {n} sementes",
"nothingToShare": "Marca primeiro algumas sementes para dar, trocar ou vender", "nothingToShare": "Marca primeiro algumas sementes para dar, trocar ou vender",
"useLocation": "Usar a minha localização aproximada", "useLocation": "Usar a minha localização aproximada",
"locationFailed": "Não foi possível obter a tua localização", "locationFailed": "Não foi possível obter a tua localização — verifica se a localização está ativa e a permissão concedida",
"queued": "Guardado — vamos partilhá-las quando tiveres ligação" "queued": "Guardado — vamos partilhá-las quando tiveres ligação"
}, },
"chat": { "chat": {

View file

@ -6,7 +6,7 @@
/// Locales: 3 /// Locales: 3
/// Strings: 986 (328 per locale) /// Strings: 986 (328 per locale)
/// ///
/// Built on 2026-07-10 at 09:03 UTC /// Built on 2026-07-10 at 09:08 UTC
// coverage:ignore-file // coverage:ignore-file
// ignore_for_file: type=lint, unused_import // ignore_for_file: type=lint, unused_import

View file

@ -1132,8 +1132,8 @@ class Translations$market$en {
/// en: 'Use my approximate location' /// en: 'Use my approximate location'
String get useLocation => 'Use my approximate location'; String get useLocation => 'Use my approximate location';
/// en: 'Couldn't get your location' /// en: 'Couldn't get your location check that location is on and the permission is granted'
String get locationFailed => 'Couldn\'t get your location'; String get locationFailed => 'Couldn\'t get your location — check that location is on and the permission is granted';
/// en: 'Saved — we'll share these when you're connected' /// en: 'Saved — we'll share these when you're connected'
String get queued => 'Saved — we\'ll share these when you\'re connected'; String get queued => 'Saved — we\'ll share these when you\'re connected';
@ -1960,7 +1960,7 @@ extension on Translations {
'market.sharedCount' => ({required Object n}) => 'Shared ${n} seeds nearby', 'market.sharedCount' => ({required Object n}) => 'Shared ${n} seeds nearby',
'market.nothingToShare' => 'Mark some seeds to give, swap or sell first', 'market.nothingToShare' => 'Mark some seeds to give, swap or sell first',
'market.useLocation' => 'Use my approximate location', 'market.useLocation' => 'Use my approximate location',
'market.locationFailed' => 'Couldn\'t get your location', 'market.locationFailed' => 'Couldn\'t get your location — check that location is on and the permission is granted',
'market.queued' => 'Saved — we\'ll share these when you\'re connected', 'market.queued' => 'Saved — we\'ll share these when you\'re connected',
'chat.title' => 'Chat', 'chat.title' => 'Chat',
'chat.hint' => 'Write a message…', 'chat.hint' => 'Write a message…',

View file

@ -629,7 +629,7 @@ class _Translations$market$es extends Translations$market$en {
@override String sharedCount({required Object n}) => 'Compartidas ${n} semillas'; @override String sharedCount({required Object n}) => 'Compartidas ${n} semillas';
@override String get nothingToShare => 'Marca antes algunas semillas para regalar, cambiar o vender'; @override String get nothingToShare => 'Marca antes algunas semillas para regalar, cambiar o vender';
@override String get useLocation => 'Usar mi ubicación aproximada'; @override String get useLocation => 'Usar mi ubicación aproximada';
@override String get locationFailed => 'No se pudo obtener tu ubicación'; @override String get locationFailed => 'No se pudo obtener tu ubicación — comprueba que la ubicación está activada y el permiso concedido';
@override String get queued => 'Guardado — las compartiremos cuando tengas conexión'; @override String get queued => 'Guardado — las compartiremos cuando tengas conexión';
} }
@ -1320,7 +1320,7 @@ extension on TranslationsEs {
'market.sharedCount' => ({required Object n}) => 'Compartidas ${n} semillas', 'market.sharedCount' => ({required Object n}) => 'Compartidas ${n} semillas',
'market.nothingToShare' => 'Marca antes algunas semillas para regalar, cambiar o vender', 'market.nothingToShare' => 'Marca antes algunas semillas para regalar, cambiar o vender',
'market.useLocation' => 'Usar mi ubicación aproximada', 'market.useLocation' => 'Usar mi ubicación aproximada',
'market.locationFailed' => 'No se pudo obtener tu ubicación', 'market.locationFailed' => 'No se pudo obtener tu ubicación — comprueba que la ubicación está activada y el permiso concedido',
'market.queued' => 'Guardado — las compartiremos cuando tengas conexión', 'market.queued' => 'Guardado — las compartiremos cuando tengas conexión',
'chat.title' => 'Chat', 'chat.title' => 'Chat',
'chat.hint' => 'Escribe un mensaje…', 'chat.hint' => 'Escribe un mensaje…',

View file

@ -625,7 +625,7 @@ class _Translations$market$pt extends Translations$market$en {
@override String sharedCount({required Object n}) => 'Partilhadas ${n} sementes'; @override String sharedCount({required Object n}) => 'Partilhadas ${n} sementes';
@override String get nothingToShare => 'Marca primeiro algumas sementes para dar, trocar ou vender'; @override String get nothingToShare => 'Marca primeiro algumas sementes para dar, trocar ou vender';
@override String get useLocation => 'Usar a minha localização aproximada'; @override String get useLocation => 'Usar a minha localização aproximada';
@override String get locationFailed => 'Não foi possível obter a tua localização'; @override String get locationFailed => 'Não foi possível obter a tua localização — verifica se a localização está ativa e a permissão concedida';
@override String get queued => 'Guardado — vamos partilhá-las quando tiveres ligação'; @override String get queued => 'Guardado — vamos partilhá-las quando tiveres ligação';
} }
@ -1312,7 +1312,7 @@ extension on TranslationsPt {
'market.sharedCount' => ({required Object n}) => 'Partilhadas ${n} sementes', 'market.sharedCount' => ({required Object n}) => 'Partilhadas ${n} sementes',
'market.nothingToShare' => 'Marca primeiro algumas sementes para dar, trocar ou vender', 'market.nothingToShare' => 'Marca primeiro algumas sementes para dar, trocar ou vender',
'market.useLocation' => 'Usar a minha localização aproximada', 'market.useLocation' => 'Usar a minha localização aproximada',
'market.locationFailed' => 'Não foi possível obter a tua localização', 'market.locationFailed' => 'Não foi possível obter a tua localização — verifica se a localização está ativa e a permissão concedida',
'market.queued' => 'Guardado — vamos partilhá-las quando tiveres ligação', 'market.queued' => 'Guardado — vamos partilhá-las quando tiveres ligação',
'chat.title' => 'Conversa', 'chat.title' => 'Conversa',
'chat.hint' => 'Escreve uma mensagem…', 'chat.hint' => 'Escreve uma mensagem…',

View file

@ -16,23 +16,38 @@ class GeolocatorCoarseLocation implements CoarseLocationProvider {
@override @override
Future<({double lat, double lon})?> currentCoarseLatLon() async { Future<({double lat, double lon})?> currentCoarseLatLon() async {
try { try {
if (!await Geolocator.isLocationServiceEnabled()) return null;
var permission = await Geolocator.checkPermission(); var permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) { if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission(); permission = await Geolocator.requestPermission();
} }
if (permission == LocationPermission.denied || // Give the user a way out of a permanent denial.
permission == LocationPermission.deniedForever) { if (permission == LocationPermission.deniedForever) {
await Geolocator.openAppSettings();
return null; return null;
} }
final position = await Geolocator.getCurrentPosition( if (permission == LocationPermission.denied) return null;
locationSettings: const LocationSettings( if (!await Geolocator.isLocationServiceEnabled()) {
accuracy: LocationAccuracy.low, await Geolocator.openLocationSettings();
), return null;
); }
// A fresh coarse fix can take a while (or never come indoors); fall back
// to the last known position so the button stays responsive.
Position? position;
try {
position = await Geolocator.getCurrentPosition(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.low,
timeLimit: Duration(seconds: 12),
),
);
} catch (_) {
position = await Geolocator.getLastKnownPosition();
}
if (position == null) return null;
return (lat: position.latitude, lon: position.longitude); return (lat: position.latitude, lon: position.longitude);
} catch (_) { } catch (_) {
return null; // service off, plugin unsupported (desktop), timeout, return null; // plugin unsupported (desktop), etc.
} }
} }
} }

View file

@ -410,6 +410,8 @@ class _ConfigSheetState extends State<_ConfigSheet> {
final _area = TextEditingController(); final _area = TextEditingController();
final _servers = TextEditingController(); final _servers = TextEditingController();
bool _loading = true; bool _loading = true;
bool _locationBusy = false;
String? _locationError;
@override @override
void initState() { void initState() {
@ -433,16 +435,21 @@ class _ConfigSheetState extends State<_ConfigSheet> {
/// geohash so no precise fix is stored. /// geohash so no precise fix is stored.
Future<void> _useLocation() async { Future<void> _useLocation() async {
final provider = widget.location; final provider = widget.location;
if (provider == null) return; if (provider == null || _locationBusy) return;
final messenger = ScaffoldMessenger.of(context); setState(() {
final t = context.t; _locationBusy = true;
_locationError = null;
});
final loc = await provider.currentCoarseLatLon(); final loc = await provider.currentCoarseLatLon();
if (!mounted) return; if (!mounted) return;
if (loc == null) { setState(() {
messenger.showSnackBar(SnackBar(content: Text(t.market.locationFailed))); _locationBusy = false;
return; if (loc == null) {
} _locationError = context.t.market.locationFailed;
setState(() => _area.text = Geohash.encode(loc.lat, loc.lon, precision: 5)); } else {
_area.text = Geohash.encode(loc.lat, loc.lon, precision: 5);
}
});
} }
@override @override
@ -464,7 +471,8 @@ class _ConfigSheetState extends State<_ConfigSheet> {
), ),
child: _loading child: _loading
? const SizedBox(height: 120, child: Center(child: CircularProgressIndicator())) ? const SizedBox(height: 120, child: Center(child: CircularProgressIndicator()))
: Column( : SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
@ -496,9 +504,23 @@ class _ConfigSheetState extends State<_ConfigSheet> {
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
child: TextButton.icon( child: TextButton.icon(
key: const Key('market.useLocation'), key: const Key('market.useLocation'),
icon: const Icon(Icons.my_location, size: 18), icon: _locationBusy
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.my_location, size: 18),
label: Text(t.market.useLocation), label: Text(t.market.useLocation),
onPressed: _useLocation, onPressed: _locationBusy ? null : _useLocation,
),
),
if (_locationError != null)
Padding(
padding: const EdgeInsets.only(top: 4),
child: Text(
_locationError!,
style: const TextStyle(color: Color(0xFFB3261E), fontSize: 12),
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
@ -541,6 +563,7 @@ class _ConfigSheetState extends State<_ConfigSheet> {
), ),
], ],
), ),
),
); );
} }
} }