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
Using version 0.4.0 quick_usb init doen't work on isolate.
I'haven't this problem using the prevoius version 0.3.1.
I've attached an example.
Best Regards
Alex
Using version 0.4.0 quick_usb init doen't work on isolate.
I'haven't this problem using the prevoius version 0.3.1.
I've attached an example.
Best Regards
Alex
import 'dart:async';
import 'dart:isolate';
import 'package:flutter/material.dart';
import 'package:quick_usb/quick_usb.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyHome());
}
class MyHome extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: MyApp(),
),
);
}
}
class MyApp extends StatefulWidget {
@OverRide
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
@OverRide
void initState() {
super.initState();
init();
}
Future init() async {
UsbService.usbRecvPort = ReceivePort();
await Isolate.spawn(UsbService.loopUsb, UsbService.usbRecvPort!.sendPort);
}
@OverRide
Widget build(BuildContext context) {
return _buildColumn();
}
void log(String info) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(info)));
}
Widget _buildColumn() {
return Column(
children: [
_init_exit(),
_getDeviceList(),
],
);
}
Widget _init_exit() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
child: Text('init'),
onPressed: () async {
var init = await QuickUsb.init();
log('init $init');
},
),
ElevatedButton(
child: Text('exit'),
onPressed: () async {
await QuickUsb.exit();
log('exit');
},
),
],
);
}
List? _deviceList;
Widget _getDeviceList() {
return ElevatedButton(
child: Text('getDeviceList'),
onPressed: () async {
_deviceList = await QuickUsb.getDeviceList();
log('deviceList $_deviceList');
},
);
}
}
class UsbService {
static SendPort? usbSendPort;
static ReceivePort? usbRecvPort;
static void loopUsb(SendPort sendPort) async {
ReceivePort p = ReceivePort();
sendPort.send(p.sendPort);
}
}
The text was updated successfully, but these errors were encountered: