i am making a ble-scanner and i need to send a ScanResult to another page. i am using parameters. but i get Invalid constant value.dart(invalid_constant)
ScanResult result
Type: ScanResult
ScanPage.dart
// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:ble/pages/devicePage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:permission_handler/permission_handler.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
bool isRunning = false;
class _HomePageState extends State<HomePage> {
void runScan() async {
Map<Permission, PermissionStatus> statuses = await [
Permission.bluetooth,
Permission.bluetoothScan,
Permission.bluetoothConnect,
Permission.location,
Permission.bluetoothAdvertise
].request();
bool allGranted = statuses.values.every((status) => status.isGranted);
if (allGranted) {
_scan();
} else {
print("Permissions not granted");
}
}
Future _scan() async {
FlutterBlue flutterBlue = FlutterBlue.instance;
flutterBlue.startScan(timeout: Duration(days: 14));
bool isFound = false;
isRunning = true;
flutterBlue.scanResults.listen((res) {
if (!isFound) {
for (ScanResult result in res) {
if (result.device.id.toString() == "10:CE:A9:0C:7F:C4") {
isFound = true;
flutterBlue.stopScan();
isRunning = false;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const Devicepage(device: result)));
return;
}
}
}
});
}
@override
Widget build(BuildContext context) {
runScan();
return Scaffold(
appBar: AppBar(title: Text("asd"), centerTitle: true),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new SizedBox(
height: 100.0,
width: 200.0,
child: ElevatedButton(
onPressed: () {
if (!isRunning) runScan();
},
child: Text("scan"),
),
)
],
)),
);
}
}
devicePage.dart
import 'package:ble/pages/ScanPage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_blue/flutter_blue.dart';
class Devicepage extends StatelessWidget {
final ScanResult device;
const Devicepage({super.key, required this.device});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(device.device.name),
centerTitle: true,
),
);
}
}
i want to be able to pass the ScanResult to the devicePage.dart
All help would be appreciated i am a beginner.