如何解决将有状态小部件转换为 Bloc 架构的问题
我正在尝试将我的 Stateful 小部件转换为 bloc 架构,
之前,一切正常:
@override
void initState() {
AgoraClient _engine = AgoraClient(
agoraConnectionData: AgoraConnectionData(
appId: Global.agoraAppId,channelName: channelName,tokenUrl: 'http://10.0.0.4:8080'),enabledPermission: [Permission.camera,Permission.microphone],agoraChannelData: AgoraChannelData(
channelProfile: ChannelProfile.LiveBroadcasting,clientRole: role,),);
}
@override
Widget build(BuildContext context) {
return AgoraVideoViewer(client: _engine)
所以我把这部分移到 bloc 和 repository
LiveVideoBloc
Stream<LiveVideoState> _mapLiveVideoInitToState(event) async* {
yield state.copyWith(status: LiveVideoStatus.loading);
try {
AgoraClient _engine = _liveRepository.initRtcEngine(
channelName: event.channelName,role: event.role,);
yield state.copyWith(
engine: _engine,status: LiveVideoStatus.loaded);
} catch (e) {
yield state.copyWith(
status: LiveVideoStatus.error,failure: Failure(message: 'Failed to init'),);
}
}
live_repository
@override
AgoraClient initRtcEngine({
required String channelName,required ClientRole role,}) {
AgoraClient _engine = AgoraClient(
agoraConnectionData: AgoraConnectionData(
appId: Global.agoraAppId,tokenUrl: 'http://10.0.0.1:8080'),);
return _engine;
}
我在 BlocProvider 之后添加事件 在我的测试过程中,事件被触发,但是
return AgoraVideoViewer(client: state.engine)
抛出Unhandled Exception: PlatformException(5,request is refused,null,null)
通过查看 Agora API 文档,我认为是因为 Agora 引擎没有初始化。
我刚开始学习 bloc,我的架构设置有什么问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。