fix: output_device.dart example runs into an error screen
Description
I wanted to test the package on the windows platform, but I am not able due to: Unsupported operation: Operation 'toDartString' not allowed on a 'nullptr'.
Steps To Reproduce
- Clone repository
- Pick Flutter version 3.27.4
- Run output_device example on the windows platform
- See error: Unsupported operation: Operation 'toDartString' not allowed on a 'nullptr'.
Expected Behavior
The example enables users to verify the package features
Additional Context
Platform: Windows 11 StackTrace:
The relevant error-causing widget was:
MaterialApp MaterialApp:file:///D:/Users/koszo/flutter_soloud/example/lib/output_device/output_device.dart:51:11
When the exception was thrown, this was the stack:
#0 Utf8Pointer._ensureNotNullptr (package:ffi/src/utf8.dart:61:7)
utf8.dart:61
#1 Utf8Pointer.toDartString (package:ffi/src/utf8.dart:41:5)
utf8.dart:41
#2 FlutterSoLoudFfi.listPlaybackDevices (package:flutter_soloud/src/bindings/bindings_player_ffi.dart:234:33)
bindings_player_ffi.dart:234
#3 SoLoud.listPlaybackDevices (package:flutter_soloud/src/soloud.dart:326:34)
soloud.dart:326
#4 _HelloFlutterSoLoudState.initState (package:flutter_soloud_example/output_device/output_device.dart:79:31)
output_device.dart:79
#5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5762:55)
framework.dart:5762
#6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5607:5)
framework.dart:5607
... Normal element mounting (228 frames)
#234 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4480:16)
framework.dart:4480
#235 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7049:36)
framework.dart:7049
#236 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7061:32)
framework.dart:7061
... Normal element mounting (519 frames)
#755 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4480:16)
framework.dart:4480
#756 Element.updateChild (package:flutter/src/widgets/framework.dart:3963:18)
framework.dart:3963
#757 _RawViewElement._updateChild (package:flutter/src/widgets/view.dart:465:16)
view.dart:465
#758 _RawViewElement.mount (package:flutter/src/widgets/view.dart:488:5)
view.dart:488
... Normal element mounting (15 frames)
#773 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4480:16)
framework.dart:4480
#774 Element.updateChild (package:flutter/src/widgets/framework.dart:3963:18)
framework.dart:3963
#775 RootElement._rebuild (package:flutter/src/widgets/binding.dart:1636:16)
binding.dart:1636
#776 RootElement.mount (package:flutter/src/widgets/binding.dart:1605:5)
binding.dart:1605
#777 RootWidget.attach.<anonymous closure> (package:flutter/src/widgets/binding.dart:1558:18)
binding.dart:1558
#778 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3038:19)
framework.dart:3038
#779 RootWidget.attach (package:flutter/src/widgets/binding.dart:1557:13)
binding.dart:1557
#780 WidgetsBinding.attachToBuildOwner (package:flutter/src/widgets/binding.dart:1296:27)
binding.dart:1296
#781 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1278:5)
binding.dart:1278
#782 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:1264:7)
binding.dart:1264
#786 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
isolate_patch.dart:184
(elided 3 frames from class _Timer and dart:async-patch)
#781 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1278:5)
binding.dart:1278
#782 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:1264:7)
binding.dart:1264
#786 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
isolate_patch.dart:184
(elided 3 frames from class _Timer and dart:async-patch)
On the MacOS platform the output_device example works
Hi @skutimechanic,
I rolled back Flutter to 3.27.4 and ran the example on Windows 11, but I can't see the error you are facing.
Probably this issue is related to #186 which has been fixed in v3.0.1
Are you using the latest 3.0.3?
I cloned the repository yestarday and I am on the main branch where I can see there is a tag 3.0.3. The example uses the dependency from a path.
So answering the question: yes, I used the 3.0.3.
I thought also that the problem can be connected with too early api call so I moved the logic of fetching the list of devices in the button onClick call, but this does not resolve the issue.
Today I switched from path dependency to remote one and there is an other issue, but sound plays by the built-in speakers. When I used the path dependency the sound played too.
No devices found!
'package:flutter_soloud_example/output_device/output_device.dart':
Failed assertion: line 80 pos 12: 'devices.isNotEmpty'
The relevant error-causing widget was:
MaterialApp MaterialApp:file:///D:/Users/koszo/flutter_soloud/example/lib/output_device/output_device.dart:51:11
When the exception was thrown, this was the stack:
#2 _HelloFlutterSoLoudState.initState (package:flutter_soloud_example/output_device/output_device.dart:80:12)
output_device.dart:80
#3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5762:55)
framework.dart:5762
#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5607:5)
framework.dart:5607
... Normal element mounting (228 frames)
#232 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4480:16)
framework.dart:4480
#233 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:7049:36)
framework.dart:7049
#234 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:7061:32)
framework.dart:7061
... Normal element mounting (519 frames)
#753 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4480:16)
framework.dart:4480
#754 Element.updateChild (package:flutter/src/widgets/framework.dart:3963:18)
framework.dart:3963
#755 _RawViewElement._updateChild (package:flutter/src/widgets/view.dart:465:16)
view.dart:465
#756 _RawViewElement.mount (package:flutter/src/widgets/view.dart:488:5)
view.dart:488
... Normal element mounting (15 frames)
#771 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4480:16)
framework.dart:4480
#772 Element.updateChild (package:flutter/src/widgets/framework.dart:3963:18)
framework.dart:3963
#773 RootElement._rebuild (package:flutter/src/widgets/binding.dart:1636:16)
binding.dart:1636
#774 RootElement.mount (package:flutter/src/widgets/binding.dart:1605:5)
binding.dart:1605
#775 RootWidget.attach.<anonymous closure> (package:flutter/src/widgets/binding.dart:1558:18)
binding.dart:1558
#776 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3038:19)
framework.dart:3038
#777 RootWidget.attach (package:flutter/src/widgets/binding.dart:1557:13)
binding.dart:1557
#778 WidgetsBinding.attachToBuildOwner (package:flutter/src/widgets/binding.dart:1296:27)
binding.dart:1296
#779 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1278:5)
binding.dart:1278
#780 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:1264:7)
binding.dart:1264
#784 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
isolate_patch.dart:184
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)J
At least the listPlaybackDevices() doesn't crash. This last error comes up because the list of devices is 0, but at least one must be returned since the sound is played.
The strange thing is that moving back and forth between the cloned plugin and the one online causes different issues. I could think of some pub cache issue, but cannot figure it out!