Firebase 吸气剂';imgUrl';被调用为空

Firebase 吸气剂';imgUrl';被调用为空,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我想从Firestore获取(profile.imgUrl)的值,但得到错误: 对null调用了getter“imgUrl”。 收件人:空 试过打电话:imgUrl 虽然用户已登录,我可以在主页中获取数据,但当我导航到帐户页时,它会给我此错误 class Account extends StatelessWidget { final Profile profile; Account({this.profile}); final AuthService _auth = AuthService()

我想从Firestore获取(profile.imgUrl)的值,但得到错误: 对null调用了getter“imgUrl”。 收件人:空 试过打电话:imgUrl

虽然用户已登录,我可以在主页中获取数据,但当我导航到帐户页时,它会给我此错误

class Account extends StatelessWidget {
final Profile profile;
Account({this.profile});

final AuthService _auth = AuthService();

@override
Widget build(BuildContext context) {


print(profile.imgUrl);

return StreamProvider<List<Profile>>.value(
  value: DatabaseService().profiles,
  child: Scaffold(
      body: Stack(
    children: <Widget>[
      ClipPath(
        child: Container(
          color: Colors.green.withOpacity(0.8),
        ),
        clipper: getClipper(),
      ),
      Positioned(
        width: 400,
        top: MediaQuery.of(context).size.height / 5,
        child: Column(
          children: <Widget>[
            Container(
              width: 150.0,
              height: 150.0,
              decoration: BoxDecoration(
                  color: Colors.green,
                  image: DecorationImage(
                      image: NetworkImage(profile.imgUrl),
                      fit: BoxFit.cover),
                  borderRadius: BorderRadius.all(Radius.circular(75.0)),
                  boxShadow: [
                    BoxShadow(blurRadius: 7.0, color: Colors.black)
                  ]),
            ),
            SizedBox(
              height: 90.0,
            ),
            Text(
              'Alex Ali',
              style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 30.0,
                  fontFamily: 'Montserrat',
                  letterSpacing: 1.5),
            ),
            SizedBox(
              height: 15.0,
            ),
            Text(
              'New Seller',
              style: TextStyle(
                  fontStyle: FontStyle.italic,
                  fontSize: 17.0,
                  color: Colors.green),
            ),
            SizedBox(
              height: 25,
            ),
            Container(
              height: 30.0,
              width: 95.0,
              child: Material(
                borderRadius: BorderRadius.circular(20.0),
                shadowColor: Colors.greenAccent,
                color: Colors.green,
                elevation: 7.0,
                child: GestureDetector(
                  onTap: () {
                    print(profile.imgUrl);
                  },
                  child: Center(
                    child: Text(
                      'Edit Name',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ),
            ),
            SizedBox(
              height: 25,
            ),
            Container(
              height: 30.0,
              width: 95.0,
              child: Material(
                borderRadius: BorderRadius.circular(20.0),
                shadowColor: Colors.redAccent,
                color: Colors.red,
                elevation: 7.0,
                child: GestureDetector(
                  onTap: () async {
                    await _auth.signOut();
                  },
                  child: Center(
                    child: Text(
                      'Log out',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      )
    ],
  )

      ),
  );
  }
  }

 class getClipper extends CustomClipper<Path> {
 @override
 Path getClip(Size size) {
 var path = new Path();

 path.lineTo(0.0, size.height / 1.9);
 path.lineTo(size.width + 125, 0.0);
 path.close();
 return path;
}

@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
 return true;
}
}
类帐户扩展无状态小部件{
最终剖面图;
帐户({this.profile});
最终AuthService_auth=AuthService();
@凌驾
小部件构建(构建上下文){
打印(profile.imgUrl);
返回StreamProvider.value(
值:DatabaseService().profiles,
孩子:脚手架(
主体:堆栈(
儿童:[
克利帕斯(
子:容器(
颜色:颜色。绿色。不透明度(0.8),
),
clipper:getClipper(),
),
定位(
宽度:400,
顶部:MediaQuery.of(context).size.height/5,
子:列(
儿童:[
容器(
宽度:150.0,
高度:150.0,
装饰:盒子装饰(
颜色:颜色。绿色,
图像:装饰图像(
图像:NetworkImage(profile.imgUrl),
安装:BoxFit.盖),
borderRadius:borderRadius.all(半径圆形(75.0)),
boxShadow:[
BoxShadow(模糊半径:7.0,颜色:Colors.black)
]),
),
大小盒子(
身高:90.0,
),
正文(
“亚历克斯·阿里”,
样式:TextStyle(
fontWeight:fontWeight.bold,
字体大小:30.0,
fontFamily:“蒙特塞拉特”,
字母间距:1.5),
),
大小盒子(
身高:15.0,
),
正文(
“新卖家”,
样式:TextStyle(
fontStyle:fontStyle.italic,
字体大小:17.0,
颜色:颜色。绿色),
),
大小盒子(
身高:25,
),
容器(
身高:30.0,
宽度:95.0,
儿童:材料(
边界半径:边界半径。圆形(20.0),
shadowColor:Colors.greenAccent,
颜色:颜色。绿色,
标高:7.0,
儿童:手势检测器(
onTap:(){
打印(profile.imgUrl);
},
儿童:中心(
子:文本(
“编辑名称”,
样式:TextStyle(颜色:Colors.white),
),
),
),
),
),
大小盒子(
身高:25,
),
容器(
身高:30.0,
宽度:95.0,
儿童:材料(
边界半径:边界半径。圆形(20.0),
阴影颜色:Colors.redAccent,
颜色:颜色,红色,
标高:7.0,
儿童:手势检测器(
onTap:()异步{
等待_auth.signOut();
},
儿童:中心(
子:文本(
“注销”,
样式:TextStyle(颜色:Colors.white),
),
),
),
),
)
],
),
)
],
)
),
);
}
}
类getClipper扩展了CustomClipper{
@凌驾
路径getClip(大小){
var path=新路径();
path.lineTo(0.0,size.height/1.9);
path.lineTo(size.width+125,0.0);
path.close();
返回路径;
}
@凌驾
bool shouldReclip(CustomClipper oldClipper){
返回true;
}
}
这就是主页代码:

class Home extends StatefulWidget {
@override
_Home createState() => _Home();
}

class _Home extends State<Home> {
final AuthService _auth = AuthService();

@override
Widget build(BuildContext context) {
return StreamProvider<List<Profile>>.value(
  value: DatabaseService().profiles,
  child: Scaffold(


    body: SafeArea(
      child: ListView(
        padding: EdgeInsets.symmetric(vertical: 30.0),
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(left: 20.0, right: 120.0),
            child: Text(
              "What would you like to find?",
              style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
            ),
          ),
          SizedBox(height: 20.0),

          SizedBox(
            height: 20.0,
          ),
          SizedBox(height: 500, child: ProfileList()),
        ],
      ),
    ),
   ),
  );
  }
  }
class Home扩展StatefulWidget{
@凌驾
_Home createState()=>\u Home();
}
类_Home扩展状态{
最终AuthService_auth=AuthService();
@凌驾
小部件构建(构建上下文){
返回StreamProvider.value(
值:DatabaseService().profiles,
孩子:脚手架(
正文:安全区(
子:ListView(
填充:边缘设置。对称(垂直:30.0),
儿童:[
填充物(
填充:仅限边缘设置(左:20.0,右:120.0),
子:文本(
“你想找什么?”,
样式:TextStyle(fontSize:30,fontWeight:fontWeight.bold),
),
),
尺寸箱(高度:20.0),
大小盒子(
身高:20.0,
),
SizedBox(高度:500,子级:ProfileList()),
],
),
),
),
);
}
}
下面是通过BottomNavigationBar打开帐户页面的代码:

class Wrapper extends StatefulWidget {
@override
_WrapperState createState() => _WrapperState();
}

class _WrapperState extends State<Wrapper> {
int _currentTab = 0;

final _page = [
Home(),
Search(),
Account(),
];

@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
print(user);

if (user == null) {
  return Authenticate();
} else {
  return Scaffold(
    body: _page[_currentTab],
    bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentTab,
        onTap: (int value) {
          setState(() {
            _currentTab = value;
          });
        },
        items: [
          BottomNavigationBarItem(
              icon: Icon(
                Icons.home,
                size: 30.0,
              ),
              title: SizedBox.shrink()),
          BottomNavigationBarItem(
              icon: Icon(
                Icons.search,
                size: 30.0,
              ),
              title: SizedBox.shrink()),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.person,
              size: 30.0,
            ),
            title: SizedBox.shrink(),
          )
        ]),
  );
  }
  }
  }
类包装器扩展StatefulWidget{
@凌驾
_WrapperState createState()=>\u WrapperState();
}
类_包装器状态扩展状态{
int _currentTab=0;
最后一页=[
Home(),
搜索(),
帐户(),
];
@凌驾
小部件构建(构建上下文){
最终用户=提供者(上下文);
打印(用户);
if(user==null){
返回Authenticate();
}否则{
返回脚手架(
正文:_页面[_当前选项卡],
底部导航栏:底部导航栏(
currentIndex:_currentTab,
onTap:(int值){
设置状态(){
_currentTab=值;
});
},
项目:[
底部导航气压计(
图标:图标(
我的家,
尺寸:30.0,
),
标题:SizedBox.shrink()),
底部导航气压计(
图标:图标(
Icons.search,
尺寸:30.0,
),
标题:SizedBox.shrink()),
底部导航气压计(
图标:图标(
一个人,
尺寸:30.0,
),
标题:SizedBox.shr
final _page = [
Home(),
Search(),
Account(),
];

Scaffold(
    body: _page[_currentTab],
    // ...
)
  Widget _getPage(int pos, user User) {
    switch (pos) {
      case 0:
        return Home();
      case 1:
        return Search();
      case 2:
        return Account(user.profile); // Assuming profile is a member of user
      default:
        return Container();
    }
  }

Scaffold(
    body: _getPage(_currentTab, user),
    // ...
)