相关疑难解决方法(0)

flutter_bloc 库中的存储库提供程序在推送新路由时不提供存储库

我正在使用 flutter_bloc 库来构建我的应用程序。除了 BlocProvider 之外,我还使用了 Repository Provider,因为我将在整个应用程序中广泛使用特定的存储库。但是我在上下文方面遇到了问题。以下是我的代码片段:

main.dart

void main() async {
  .......
  appRepository _appRepository = AppRepository();
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((_) {
    runApp(
      BlocProvider(
        builder: (context) =>
            AuthenticationBloc(appRepository: _appRepository)..dispatch(AppStarted()),
        child: App(appRepository: _appRepository,),
      ),
    );
  });
}

class App extends StatelessWidget {

............
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
        builder: (BuildContext context, AuthenticationState state) {
       .....
          if (state is AuthenticationUnauthenticated) {
            return SafeArea(
              top: false,
              bottom: false,
              child: RepositoryProvider(
                builder: (context) => _appRepository,
                child: LoginPage(firebaseMessaging: _firebaseMessaging),
              ), …
Run Code Online (Sandbox Code Playgroud)

dart flutter bloc

4
推荐指数
1
解决办法
4819
查看次数

标签 统计

bloc ×1

dart ×1

flutter ×1