I get the error: Could not find the correct Provider<User> above this settings widget (ALREADY FIXED)

I get the error: Could not find the correct Provider<User> above this settings widget (ALREADY FIXED)

已修复: 在 materialapp

之前我没有设置 streamprovider

我有这个:

 final user = Provider.of<User>(context);

return StreamBuilder<UserData>(
  stream: DatabaseService(uid: user.uid).userData,
  builder: (context, snapshot) {
    if(snapshot.hasData){

      UserData userData = snapshot.data;

我有一个 class 用户:

class User {

final String uid;
final String email;
final String instagram;
String age;
String gender;
bool account;

User({this.email, this.age, this.gender, this.uid, this.instagram, this.account,});

}

我不知道是什么问题,我在其他地方用过它,它工作正常

这里是错误日志:

Error: Could not find the correct Provider<User> above this Settings Widget

要修复,请:

确保 Provider 在小部件树中的设置小部件上方,为此您可以通过使用 Provider() 包装整个 material 应用程序或仅包装来自提供程序的用户 class Provider

的设置小部件
Provider<User>(
create:(context)=>User(),
child:MaterialApp(
  //app
 ),
),

Provider<User>(
    create:(context)=>User(),
    child:SettingsWidget(
      //app
     ),
    ),