Closed kanojiyasmit closed 2 days ago
Hi @kanojiyasmit,
There are several issues with your code that are preventing it from operating as you expect. This is not a problem with the package itself. I recommend posting to a forum that provides help with Flutter and Dart coding.
Hi @faithoflifedev Thanks for quick reply, i am checking several times of my code but not getting any clue can you help me on this ? What i am doing wrong? Also i am using your package and example everything works perfectly on Android but from iOS side i am not able to discover. Your help will be appreciated.
import 'package:easy_onvif/probe.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Onvif Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: MyHomePage(title: 'Onvif Flutter Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
final multicastProbe = MulticastProbe(releaseMode: kReleaseMode);
final String title;
MyHomePage({
super.key,
required this.title,
});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final multicastProbe = MulticastProbe(releaseMode: kReleaseMode);
Future<List<ProbeMatch>> fetchDevice() async {
await multicastProbe.probe();
return multicastProbe.onvifDevices;
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.grey[200],
),
backgroundColor: Colors.grey[200],
body: Center(
child: FutureBuilder(
future: fetchDevice(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text(
'Scanning network to find out ONVIF devices',
style: TextStyle(fontSize: 16),
),
],
),
);
} else if (snapshot.hasError) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.error,
color: Colors.red,
size: 48,
),
const SizedBox(height: 16),
Text(
'An error occurred: ${snapshot.error}',
style: const TextStyle(fontSize: 16, color: Colors.red),
textAlign: TextAlign.center,
),
],
);
} else if (snapshot.hasData && snapshot.data!.isNotEmpty) {
final devices = snapshot.data!;
return ListView.builder(
itemCount: devices.length,
itemBuilder: (context, index) {
final device = devices[index];
return Card(
margin:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
contentPadding: const EdgeInsets.all(16),
leading: const Icon(
Icons.devices,
size: 40,
color: Colors.blue,
),
title: Text(
device.hardware,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
device.xAddr,
style: const TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
trailing: const Icon(
Icons.arrow_forward_ios,
color: Colors.grey,
),
onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => DeviceDetails(device: device),
// ),
// );
},
),
);
},
);
} else {
return const Text("No devices found.");
}
},
),
),
);
}
}
Hi @faithoflifedev ,
Thank you for the correction. I tried this approach, but I’m still encountering the same error on the iOS side.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Send failed (OS Error: No route to host, errno = 65), address = 0.0.0.0, port = 0
#0 _NativeSocket.send (dart:io-patch/socket_patch.dart:1275:34)
#1 _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:2590:15)
#2 MulticastProbeIo.start (package:easy_onvif/src/platform/multicast_probe_io.dart:160:23)
#3 MulticastProbeIo.probe (package:easy_onvif/src/platform/multicast_probe_io.dart:144:5)
<asynchronous suspension>
#4 _MyHomePageState.fetchDevice (package:onvif_discovery_hub/main.dart:41:5)
<asynchronous suspension>
#5 _FutureBuilderState._subscribe.<anonymous closure> (package:flutter/src/widgets/async.dart:638:31)
<asynchronous suspension>
I’ve already added Local Network Permission and App Transport Security (ATS) configurations. Is there any other capability or configuration required for iOS to make this work?
Hi @faithoflifedev , The application fails to send UDP packets due to a “No route to host” error during device discovery.