我在我的应用程序中使用流构建器,但它一直返回 null
MyUserClass? user = Provider.of<MyUserClass?>(context);
print('$user settings_form \n ${user!.uid}');
return StreamBuilder<UserData?>(
stream: DatabaseService(uid: user.uid).userData,
builder: (context, snapshot) {
if(snapshot.hasData){
UserData? userData = snapshot.data;
return Form(
key: _formKey,
child: Column(
children: <Widget>[
Text(
'Update your brew settings',
style: TextStyle(fontSize: 18),
),
SizedBox(height: 20,),
TextFormField(
initialValue: userData!.name,
decoration: textInputDecoration,
validator: (val) =>
val!.isEmpty
? 'Please enter name'
: null,
onChanged: (val) => setState(() => _currentName = val),
),
SizedBox(height: 20,),
style: ElevatedButton.styleFrom(
primary: Colors.pink
),
)
],
),
);
} else{
return Loading();
}
我想从我的类“MyUserClass”中获取用户信息,用户信息正在控制台中打印信息,但它返回空值。