Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何实现依赖于另一个提供程序的提供程序?_Flutter_Dart - Fatal编程技术网

Flutter 如何实现依赖于另一个提供程序的提供程序?

Flutter 如何实现依赖于另一个提供程序的提供程序?,flutter,dart,Flutter,Dart,我使用的是带有flatter和dart的provider包,我有一个身份验证提供程序和一个提供用户模型的流提供程序。提供用户模型的流提供程序依赖于身份验证提供程序。如何将我的用户id获取到流提供商 这是我的multiprovider MultiProvider( providers: [ Provider<AuthenticationProvider>(builder: (context) => AuthenticationProvider(),),

我使用的是带有flatter和dart的provider包,我有一个身份验证提供程序和一个提供用户模型的流提供程序。提供用户模型的流提供程序依赖于身份验证提供程序。如何将我的用户id获取到流提供商

这是我的multiprovider

MultiProvider(
      providers: [
        Provider<AuthenticationProvider>(builder: (context) => AuthenticationProvider(),),
        StreamProvider<UserModel>.value(value: userStream(//here we call the async method in the Authentication provider to get the user id),
        ),
      ]
编辑

这就是我现在拥有的

Provider<AuthenticationProvider>(create: (_) => AuthenticationProvider(),),
Provider<UserProvider>(
  create: (_) => UserProvider(),
),
StreamProvider(create: (context) {
  return Provider.of<UserProvider>(context).userStream(Provider.of<AuthenticationProvider>(context).userAuthenticationCertificate());
}),
Provider(创建:(\u)=>AuthenticationProvider(),),
提供者(
创建:()=>UserProvider(),
),
StreamProvider(创建:(上下文){
返回Provider.of(context).userStream(Provider.of(context).userAuthenticationCertificate());
}),

那么现在我在streamprovider中提供用户提供者?我想以流的形式提供userModel我该怎么做?

您可以使用传递给提供商的
创建
上下文
参数来读取其他提供商:

Provider(创建:(\u)=>Auth()),
StreamProvider(创建:(上下文){
返回(上下文)某物的提供者;
});

它表示create是一个未定义的参数
未定义命名参数“create”。请尝试将名称更正为现有命名参数的名称,或在提供程序和流提供程序中定义名为
的命名参数?您使用的是过期版本的providerI,而我确实使用的是旧版本。问题在您的示例中,您使用AuthProvider两次。那么,用户提供者从何而来?我尝试在流提供程序中添加用户提供程序,但这会使我回到需要身份验证提供程序的同一问题。我没有使用
Auth
两次。第二个是获得第一个,而不是创建一个单独的
import 'package:firebase_auth/firebase_auth.dart';

class UserAuthenticationCertificate
{
  String _userID;

  String get userID{
    return _userID;
  }

  UserAuthenticationCertificate(this._userID);

  UserAuthenticationCertificate._internal(this._userID);

  factory UserAuthenticationCertificate.fromFirebase(FirebaseUser firebaseUser)
  {
    return UserAuthenticationCertificate._internal(
      firebaseUser.uid
    );
  }
}
Provider<AuthenticationProvider>(create: (_) => AuthenticationProvider(),),
Provider<UserProvider>(
  create: (_) => UserProvider(),
),
StreamProvider(create: (context) {
  return Provider.of<UserProvider>(context).userStream(Provider.of<AuthenticationProvider>(context).userAuthenticationCertificate());
}),