1

我刚刚复制了 just_audio 库的示例并将其放入我的项目中,然后我正在热重新加载或按回,我收到一个错误

[VERBOSE-2:shell.cc(209)] Dart Error: Unhandled exception:
Bad state: You cannot close the subject while items are being added from addStream
#0      Subject.close (package:rxdart/src/subjects/subject.dart:152:7)
#1      AudioPlayer.dispose (package:just_audio/just_audio.dart:611:30)
<asynchronous suspension>
#2      _LessonPractiseScreenState.dispose (package:wbh/ui/pages/lesson/lesson_practise_screen.dart:90:13)
#3      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4773:12)
#4      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1935:13)
#5      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1933:7)
#6      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#7      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1931:13)
#8      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1933:7)
#9      SingleChildRenderObjec<…&gt;

我测试的导致小部件是:

Widget get _seekBar => StreamBuilder<Duration>(
        stream: _player.durationStream,
        builder: (context, snapshot) {
          final duration = snapshot.data ?? Duration.zero;
          return StreamBuilder<Duration>(
            stream: _player.positionStream,
            builder: (context, snapshot) {
              if (snapshot.hasData) {
                var position = snapshot.data ?? Duration.zero;
                if (position > duration) {
                  position = duration;
                }
                return SeekBar(
                  duration: duration,
                  position: position,
                  onChanged: (newPosition) {
                    _player.seek(newPosition);
                  },
                );
              } else
                return Container();
            },
          );
        },
      );

但是我无法自己修复它,并且在网上没有任何信息,因此将不胜感激。

4

1 回答 1

0

这是通过 GitHub 报告的一个错误,并在不久之后推出了一个修复程序(请参阅此问题进行讨论)。较新的版本 (>= 0.4.4) 应该可以解决此问题。

于 2021-02-06T13:58:34.573 回答