类型'String'不是类型'ImageProvider <dynamic>'的子类型

时间:2018-11-19 07:45:33

标签: flutter flutter-layout

我有类别列表,点击每个类别都会在新屏幕中显示该类别的用户。新屏幕上有一个image小部件和text小部件。如果用户有profile picture,并且没有与此用户相关联的个人资料图片,则会显示此错误,并且显示默认图片,不会引发此错误。

Widget _getProfilePic(Pro pro) {

    // If the pro has provided a profile picture
    if(pro.profilePhoto.length > 0) {

      // If the pro is available for a video call
      if(statusMap[pro.onlineStatus] == "Online, available") {
        return CircleAvatar(
            radius: 30.0,
            backgroundImage: pro.profilePhoto.startsWith("./profilepics") ? NetworkImage("" + pro.profilePhoto.substring(2)) : pro.profilePhoto);
      }
      // If pro is not available
      else {
        return CircleAvatar(
            radius: 30.0,
            backgroundImage: pro.profilePhoto.startsWith("./profilepics") ? NetworkImage("" + pro.profilePhoto.substring(2)) : pro.profilePhoto);
      }

    }
    // Else, provide a default icon
    else {
      // If the pro is available for a video call
      if(statusMap[pro.onlineStatus] == "Online, available") {
        var profileImg = Image.asset('icons/default_profile_icon.png', height: 60.0);

        return Image.asset('icons/default_profile_icon.png', height: 60.0);

      }
      // If the pro is not available
      else {
        return Image.asset('icons/default_profile_icon.png', height: 60.0);
      }
    }

这是Pro类模型:

class Pro extends User {
  String company;
  String experience;
  double rating;
  int reviewCount;
  int onlineStatus;
  String proId;

  Pro();

  // Returns a Pro created from JSON
  factory Pro.fromJson(Map<String, dynamic> json) {
    Pro pro = Pro();

    pro.proId = json['ProID'] as String;
    pro.fullname = json['FullName'] as String;
    pro.company = json['Company'] as String;
    pro.experience = json['about'] as String;
    pro.rating = json['ReviewAvg'] != null? double.tryParse(json['ReviewAvg']) : 0.0;
    pro.reviewCount = json['ReviewCount'];
    pro.onlineStatus = json['OnlineStatus'];
    pro.profilePhoto = json['profile_pic'] as String;

    return pro;
  }

}

// Converts a http response body into a List<Pro>
  List<Pro> parsePros(String responseBody) {
    final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
    return parsed.map<Pro>((json) => Pro.fromJson(json)).toList();
  }

1 个答案:

答案 0 :(得分:1)

您可能需要在要测试./profilepics的两个位置中将pro.profileImage包裹在NetworkImage中