Flutter Drawer Photo 不工作 - 'package:flutter/src/painting/_network_image_io.dart':失败的断言:第 25 行 pos 14:'url != null':不是真的

时间:2021-04-06 20:01:41

标签: firebase flutter google-cloud-firestore flutter-dependencies

我想在抽屉标题中显示个人资料照片,但显示错误 'package:flutter/src/painting/_network_image_io.dart':断言失败:第 25 行 pos 14:'url != null':不正确。

Firebase 为变量提供个人资料照片 URL,但错误显示变量为空

我尝试了很多方法来解决这个错误,但很遗憾无法修复

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:fivetagsmobileapp/constant.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_restart/flutter_restart.dart';

class Drwr extends StatefulWidget {
  @override
  _DrwrState createState() => _DrwrState();
}

class _DrwrState extends State<Drwr> {
  final _auth = FirebaseAuth.instance;

  String profilePhoto;

  @override
  void initState() {
    super.initState();
    final User user = _auth.currentUser;
    final uid = user.uid;

    FirebaseFirestore.instance
        .collection('users')
        .doc(uid)
        .get()
        .then((DocumentSnapshot documentSnapshot) {
      profilePhoto = documentSnapshot.data()["profileURL"];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(
        canvasColor: blueLight,
      ),
      child: ClipRRect(
        borderRadius: BorderRadius.only(
          bottomRight: Radius.circular(150),
        ),
        child: Drawer(
          child: ListView(
            padding: EdgeInsets.zero,
            children: <Widget>[
              DrawerHeader(
                decoration: BoxDecoration(
                  color: blueLightUnselected,
                  boxShadow: [BoxShadow(color: blueLight, spreadRadius: 1)],
                ),
                child: Padding(
                  padding: EdgeInsets.only(right: 25.0),
                  child: Center(
                    child: CircleAvatar(
                      radius: 30.0,
                      foregroundImage: NetworkImage(profilePhoto),
                    ),
                  ),
                ),
              ),
              
            ],
          ),
        ),
      ),
    );
  }
}```

1 个答案:

答案 0 :(得分:0)

您是否尝试使用默认图像?如果“profilePhoto”为空