Atualização do mapa

This commit is contained in:
2026-03-11 17:14:25 +00:00
parent 256d34eb79
commit 782486d23b
5 changed files with 493 additions and 111 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:permission_handler/permission_handler.dart';
@@ -203,6 +204,63 @@ class _BluetoothConnectionScreenState extends State<BluetoothConnectionScreen> {
}
}
Future<void> _sendSignalToDevice() async {
if (_connectedDevice == null) return;
try {
// 1. Descobrir serviços do dispositivo
List<BluetoothService> services = await _connectedDevice!.discoverServices();
BluetoothCharacteristic? writableChar;
// 2. Procurar uma característica que permita escrita
for (var service in services) {
for (var char in service.characteristics) {
if (char.properties.write || char.properties.writeWithoutResponse) {
writableChar = char;
break;
}
}
if (writableChar != null) break;
}
if (writableChar != null) {
// 3. Enviar um sinal simples (ex: "1" em bytes)
await writableChar.write(utf8.encode("1"));
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(AppStrings.signalSent),
backgroundColor: AppColors.success,
behavior: SnackBarBehavior.floating,
),
);
}
} else {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(AppStrings.noWritableChar),
backgroundColor: AppColors.error,
behavior: SnackBarBehavior.floating,
),
);
}
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('${AppStrings.signalError}$e'),
backgroundColor: AppColors.error,
behavior: SnackBarBehavior.floating,
),
);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -320,6 +378,35 @@ class _BluetoothConnectionScreenState extends State<BluetoothConnectionScreen> {
),
),
const SizedBox(height: 30),
// Se houver um dispositivo conectado, mostra o botão de enviar sinal
if (_connectedDevice != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: SizedBox(
width: double.infinity,
height: 60,
child: ElevatedButton.icon(
onPressed: _sendSignalToDevice,
icon: const Icon(Icons.send_rounded),
label: const Text(
AppStrings.sendSignal,
style: TextStyle(fontWeight: FontWeight.bold, letterSpacing: 1.2),
),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.coral,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
elevation: 5,
),
),
),
),
const SizedBox(height: 20),
Expanded(
child: ListView.builder(
itemCount: _connectedDevice != null ? 1 : _scanResults.length,