You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello I Have This Code in flutter:
`import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_beacon/flutter_beacon.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:simple_sensor/simple_sensor.dart';
class _RadarScreenState extends State {
final StreamController _beaconEventsController =
StreamController.broadcast();
List _beacons = [];
bool _haveDetected = false;
}
}
`
The visualization of iBeacons on radar sometime is intermittent . Can Someone test the code for to know if depending on FLutter_Beacon plugin or by another piece of my code ? Thanks in Advances
The text was updated successfully, but these errors were encountered:
Hello I Have This Code in flutter:
`import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_beacon/flutter_beacon.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:simple_sensor/simple_sensor.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await flutterBeacon.initializeScanning; // Initialize flutter_beacon
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Beacon Locator',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: RadarScreen(),
);
}
}
class RadarScreen extends StatefulWidget {
@OverRide
_RadarScreenState createState() => _RadarScreenState();
}
class _RadarScreenState extends State {
final StreamController _beaconEventsController =
StreamController.broadcast();
List _beacons = [];
bool _haveDetected = false;
// Sensors
StreamSubscription? _accelerometerSubscription;
StreamSubscription? _magnetometerSubscription;
StreamSubscription? _beaconSubscription;
List _accelerometerValues = [0.0, 0.0, 0.0];
List _magnetometerValues = [0.0, 0.0, 0.0];
double _bearing = 0.0;
final AngleLowpassFilter _angleLowpassFilter = AngleLowpassFilter();
final Region _beaconRegion = Region(
identifier: 'Exit 3p LA',
proximityUUID: 'FDA50693-A4E2-4FB1-AFCF-C6EB07647820');
@OverRide
void initState() {
super.initState();
requestPermissions().then(() {
_startSensors();
_startBeaconScan();
}).catchError((e) {
print("Permission request failed: $e");
});
}
@OverRide
void dispose() {
_stopSensors();
_beaconSubscription?.cancel();
_beaconEventsController.close();
super.dispose();
}
Future _requestPermissions() async {
var status = await [
Permission.bluetoothScan,
Permission.location,
].request();
}
void _startSensors() {
_accelerometerSubscription =
simpleSensor.accelerometer.listen((AccelerometerEvent event) {
setState(() {
_accelerometerValues = [event.x, event.y, event.z];
_calculateBearing();
});
});
}
void _stopSensors() {
_accelerometerSubscription?.cancel();
_magnetometerSubscription?.cancel();
}
void _calculateBearing() {
if (_accelerometerValues.isEmpty || _magnetometerValues.isEmpty) return;
}
Future _startBeaconScan() async {
final regions = [
_beaconRegion,
];
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Beacon Locator'),
centerTitle: true,
),
body: Center(
child: CustomPaint(
painter: RadarPainter(
bearing: _bearing,
beacons: _beacons,
haveDetected: _haveDetected,
),
child: Container(
width: 300,
height: 300,
),
),
),
);
}
}
class RadarPainter extends CustomPainter {
final double bearing;
final List beacons;
final bool haveDetected;
final double maxDistance = 15.0;
RadarPainter({
required this.bearing,
required this.beacons,
required this.haveDetected,
});
@OverRide
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
final radius = min(size.width, size.height) / 2 - 8;
}
void _drawDistanceLabels(Canvas canvas, Offset center, double radius) {
final textStyle = TextStyle(
color: Colors.black,
fontSize: 12,
);
}
@OverRide
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
class AngleLowpassFilter {
final List _values = [];
final int _windowSize = 10;
void add(double value) {
_values.add(value);
if (_values.length > _windowSize) {
_values.removeAt(0);
}
}
double average() {
if (_values.isEmpty) return 0.0;
return _values.reduce((a, b) => a + b) / _values.length;
}
}
class BeaconData {
final double distance;
final double angle;
final String identifier;
BeaconData({
required this.distance,
required this.angle,
required this.identifier,
});
factory BeaconData.fromBeacon(
Beacon beacon, double bearing, String regionIdentifier) {
double beaconAngle = calculateAngle(beacon, bearing);
}
static double calculateAngle(Beacon beacon, double bearing) {
double rssi = beacon.rssi.toDouble();
double maxRssi = -30; // RSSI at 1 meter (example)
double minRssi = -100; // RSSI at max distance (example)
}
}
`
The visualization of iBeacons on radar sometime is intermittent . Can Someone test the code for to know if depending on FLutter_Beacon plugin or by another piece of my code ? Thanks in Advances
The text was updated successfully, but these errors were encountered: