gpt4 book ai didi

flutter - 信息 : 'runZoned' is deprecated and shouldn't be used. 这将在 v9.0.0 中删除。使用 Bloc.Bloc.transformer 代替

转载 作者:行者123 更新时间:2023-12-02 01:29:16 29 4
gpt4 key购买 nike

我在尝试在 DartPad 上运行我的代码时遇到了这个问题。

'runZoned' is deprecated and shouldn't be used. This will be removed in v9.0.0. Use Bloc.Bloc.transformer instead...

正确的替换方法是什么?

代码:

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

void main() {
BlocOverrides.runZoned(
() => runApp(const App()),
blocObserver: AppBlocObserver(),
);
}

/// Custom [BlocObserver] that observes all bloc and cubit state changes.
class AppBlocObserver extends BlocObserver {
@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
if (bloc is Cubit) print(change);
}

@override
void onTransition(Bloc bloc, Transition transition) {
super.onTransition(bloc, transition);
print(transition);
}
}

最佳答案

解决方案是:

void main() {
Bloc.observer = AppBlocObserver();
runApp(const App());
}

关于flutter - 信息 : 'runZoned' is deprecated and shouldn't be used. 这将在 v9.0.0 中删除。使用 Bloc.Bloc.transformer 代替,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73685907/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com