【问题标题】:'package:flutter/src/paintings/_network_image_io.dart':Failed assertion: line 25 pros 14: 'url != null': is not true.StreamBuilder'package:flutter/src/paintings/_network_image_io.dart':断言失败:第 25 行 pro 14:'url != null':不正确。StreamBuilder
【发布时间】:2021-05-14 21:46:21
【问题描述】:

我正在尝试使用颤振构建一个社交媒体应用程序,我已经创建了一个登录页面和登录页面,它需要 userAvatar, 用户名,用户电子邮件,用户密码也是。当单击浮动操作按钮作为提交按钮时,它将注册帐户,但在我的情况下,它只注册电子邮件、用户 ID、用户名和用户密码,但不注册用户图像,它显示这个'package:flutter/src/paintings/_network_image_io.dart':断言失败:第 25 行专业人士 14:'url != null':不正确。导致小部件的相关错误是流生成器...这是我的错误..任何人都可以帮忙 我将在下面留下我的代码。

LandingServices 作为登录和登录

class LandingService with ChangeNotifier {
TextEditingController userEmailController = TextEditingController();
TextEditingController userNameController = TextEditingController();
 TextEditingController userPasswordController = TextEditingController();
 ConstantColors constantColors = ConstantColors();

showUserAvatar

  showUserAvatar(BuildContext context) {
return showModalBottomSheet(
    context: context,
    builder: (context) {
      return Container(
        height: MediaQuery.of(context).size.height * 0.36,
        width: MediaQuery.of(context).size.width,
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 150.0),
              child: Divider(
                thickness: 4.0,
                color: constantColors.whiteColor,
              ),
            ),
            CircleAvatar(
              radius: 69.0,
              backgroundColor: constantColors.transperant,
              backgroundImage: FileImage(
                Provider.of<LandingUtils>(context, listen: false).userAvatar
              )),
            Container(
              child: 
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  MaterialButton(
                      child: Text(
                        'Reselect',
                        style: TextStyle(
                            color: constantColors.whiteColor,
                            fontWeight: FontWeight.bold,
                            decoration: TextDecoration.underline,
                            decorationColor: constantColors.whiteColor),
                      ),
                      onPressed: () {
                        Provider.of<LandingUtils>(context, listen: false)
                            .pickUserAvatar(context, ImageSource.gallery);
                      }),
                  MaterialButton(
                      color: constantColors.blueColor,
                      child: Text(
                        'Confirm Image',
                        style: TextStyle(
                          color: constantColors.whiteColor,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      onPressed: () {
                        Provider.of<FirebaseOperations>(context,
                                listen: false)
                            .uploadUserAvatar(context)
                            .whenComplete(() {
                          signInSheet(context);
                        });
                      }),
                ],
              ),
            )
          ],
        ),
        decoration: BoxDecoration(
          color: constantColors.blueGreyColor,
          borderRadius: BorderRadius.circular(15.0),
        ),
      );
    });
   }

passswordLessSignIn

  Widget passswordLessSignIn(BuildContext context) {
return SizedBox(
  height: MediaQuery.of(context).size.height * 0.40,
  width: MediaQuery.of(context).size.width,
  child: StreamBuilder<QuerySnapshot>(
    stream: FirebaseFirestore.instance.collection('users').snapshots(),
    builder: (context, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return Center(
          child: CircularProgressIndicator(),
        );
      } else {
        return new ListView(
            children:
                snapshot.data.docs.map((DocumentSnapshot documentSnapshot) {
          return ListTile(
            trailing: IconButton(
              icon: Icon(FontAwesomeIcons.trashAlt,
                  color: constantColors.redColor),
              onPressed: () {},
            ),
            leading: CircleAvatar(
              backgroundColor: constantColors.transperant,
              backgroundImage:
                  NetworkImage(documentSnapshot.data()['userimage']),
            ),
            subtitle: Text(documentSnapshot.data()['useremail'],
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: constantColors.greenColor,
                    fontSize: 12.0)),
            title: Text(documentSnapshot.data()['username'],
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: constantColors.greenColor)),
          );
        }).toList());
      }
    },
  ),
);
  }

signInSheet

 signInSheet(BuildContext context) {
return showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    builder: (context) {
      return Padding(
        padding: EdgeInsets.only(
            bottom: MediaQuery.of(context).viewInsets.bottom),
        child: Container(
          height: MediaQuery.of(context).size.height * 0.5,
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(
              color: constantColors.blueGreyColor,
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(12.0),
                  topRight: Radius.circular(12.0))),
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 150.0),
                child: Divider(
                  thickness: 4.0,
                  color: constantColors.whiteColor,
                ),
              ),
              CircleAvatar(
                backgroundImage: FileImage(
                    Provider.of<LandingUtils>(context, listen: false)
                        .getUserAvatar),
                backgroundColor: constantColors.redColor,
                radius: 60.0,
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10.0),
                child: TextField(
                  controller: userNameController,
                  decoration: InputDecoration(
                    hintText: 'Enter name...',
                    hintStyle: TextStyle(
                      color: constantColors.whiteColor,
                      fontWeight: FontWeight.bold,
                      fontSize: 16.0,
                    ),
                  ),
                  style: TextStyle(
                    color: constantColors.whiteColor,
                    fontWeight: FontWeight.bold,
                    fontSize: 18.0,
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10.0),
                child: TextField(
                  controller: userEmailController,
                  decoration: InputDecoration(
                    hintText: 'Enter Email...',
                    hintStyle: TextStyle(
                      color: constantColors.whiteColor,
                      fontWeight: FontWeight.bold,
                      fontSize: 16.0,
                    ),
                  ),
                  style: TextStyle(
                    color: constantColors.whiteColor,
                    fontWeight: FontWeight.bold,
                    fontSize: 18.0,
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10.0),
                child: TextField(
                  controller: userPasswordController,
                  decoration: InputDecoration(
                    hintText: 'Enter Password...',
                    hintStyle: TextStyle(
                      color: constantColors.whiteColor,
                      fontWeight: FontWeight.bold,
                      fontSize: 16.0,
                    ),
                  ),
                  style: TextStyle(
                    color: constantColors.whiteColor,
                    fontWeight: FontWeight.bold,
                    fontSize: 18.0,
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 0.32),
                child: FloatingActionButton(
                    backgroundColor: constantColors.redColor,
                    child: Icon(
                      FontAwesomeIcons.check,
                      color: constantColors.whiteColor,
                    ),
                    onPressed: () {
                      if (userEmailController.text.isNotEmpty) {
                        Provider.of<Authentication>(context, listen: false)
                            .createAccount(userEmailController.text,
                                userPasswordController.text)
                            .whenComplete(() {
                          print('Creating collections...');
                          Provider.of<FirebaseOperations>(context,
                                  listen: false)
                              .createUserCollection(context, {
                            'useruid': Provider.of<Authentication>(context,
                                    listen: false)
                                .getUserUid,
                            'useremail': userEmailController.text,
                            'username': userNameController.text,
                            'userimage': Provider.of<LandingUtils>(context,
                                    listen: false)
                                .getUserAvatarUrl,
                          });
                        }).whenComplete(() {
                          Navigator.pushReplacement(
                              context,
                              PageTransition(
                                  child: Homepage(),
                                  type: PageTransitionType.bottomToTop));
                        });
                      } else {
                        warningText(context, 'Fill all the data!');
                      }
                    }),
              ),
            ],
          ),
        ),
      );
    });
    }

firebaseOperation.dart

import 'package:cloud_firestore/cloud_firestore.dart';
   import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
 import 'package:theGupshup/screens/LandingPage/LandingUtils.dart';
  import 'package:theGupshup/services/Authentication.dart';

   class FirebaseOperations with ChangeNotifier {
      UploadTask imageUploadTask;
      String initUserName, initUserEmail, initUserImage;
      String get getInitUserName => initUserName;
      String get getInitUserEmail => initUserEmail;
      String get getInitUserImage => initUserImage;
      Future uploadUserAvatar(BuildContext context) async {
      Reference imageReference = FirebaseStorage.instance.ref().child(
         'userProfileAvatar/${Provider.of<LandingUtils>(context, listen: 
          false).getUserAvatar.path}/${TimeOfDay.now()}');
      imageUploadTask = imageReference.putFile(
         Provider.of<LandingUtils>(context, listen: false).getUserAvatar);

        await imageUploadTask.whenComplete(() {
        print('Image uploaded!');
         });
        imageReference.getDownloadURL().then((url) {
         Provider.of<LandingUtils>(context, listen: false).userAvatarUrl =
            url.toString();
          print(
             'the user profile avatar url => ${Provider.of<LandingUtils>(context, listen: 
                 false).userAvatarUrl}');
                  notifyListeners();
                          });
                           }

               Future createUserCollection(BuildContext context, dynamic data) async {
                  return FirebaseFirestore.instance
                      .collection('users')
                 .doc(Provider.of<Authentication>(context, listen: false).getUserUid)
                  .set(data);
                       }

                  Future initUserData(BuildContext context) async {
                     return FirebaseFirestore.instance
                      .collection('users')
                       .doc(Provider.of<Authentication>(context, listen: false).getUserUid)
                          .get()
                            .then((doc) {
                                  print('Fetching user data');
                       initUserName = doc.data()['username'];
                       initUserEmail = doc.data()['useremail'];
                        initUserImage = doc.data()['userimage'];
                           print(initUserName);
                            print(initUserEmail);
                               print(initUserImage);
                                    notifyListeners();
                                         });
                                        }
                                   } 

登陆 utils.dart

class LandingUtils with ChangeNotifier {
ConstantColors constantColors = ConstantColors();
 final picker = ImagePicker();
 File userAvatar;
  File get getUserAvatar => userAvatar;
 String userAvatarUrl;
  String get getUserAvatarUrl => userAvatarUrl;

  Future pickUserAvatar(BuildContext context, ImageSource source) async {
   final pickedUserAvatar = await picker.getImage(source: source);
    pickedUserAvatar == null
         ? print('Select image')
       : userAvatar = File(pickedUserAvatar.path);
         print(userAvatar.path);

            userAvatar != null
            ? Provider.of<LandingService>(context, listen: false)
                 .showUserAvatar(context)
             : print('Image Upload error');
                notifyListeners();
                       }
       
               Future selectAvatarOptionSheet(BuildContext context) async {
return showModalBottomSheet(
    context: context,
    builder: (context) {
      return Container(
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 150.0),
              child: Divider(
                thickness: 4.0,
                color: constantColors.whiteColor,
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                MaterialButton(
                    color: constantColors.blueColor,
                    child: Text('Gallery',
                        style: TextStyle(
                            color: constantColors.whiteColor,
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0)),
                    onPressed: () {
                      pickUserAvatar(context, ImageSource.gallery)
                          .whenComplete(() {
                        Navigator.pop(context);
                        Provider.of<LandingService>(context, listen: false)
                            .showUserAvatar(context);
                      });
                    }),
                MaterialButton(
                    color: constantColors.blueColor,
                    child: Text('Camera',
                        style: TextStyle(
                            color: constantColors.whiteColor,
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0)),
                    onPressed: () {
                      pickUserAvatar(context, ImageSource.camera)
                          .whenComplete(() {
                        Navigator.pop(context);
                        Provider.of<LandingService>(context, listen: false)
                            .showUserAvatar(context);
                      });
                    }),
              ],
            ),
          ],
        ),
        height: MediaQuery.of(context).size.height * 0.1,
        width: MediaQuery.of(context).size.width,
        decoration: BoxDecoration(
            color: constantColors.blueGreyColor,
            borderRadius: BorderRadius.circular(12.0)),
      );
    });
           }
           }

谁能帮忙看看下面的错误图片

谁能帮忙

【问题讨论】:

    标签: android firebase flutter google-cloud-firestore firebase-storage


    【解决方案1】:

    在您的密码LessSignIn 页面中,当用户图像为空时,尝试为圆形头像提供默认图像-

    例子-

     leading: CircleAvatar(
                  backgroundColor: constantColors.transperant,
                  backgroundImage:
                      NetworkImage(documentSnapshot.data()['userimage'] ?? "https://i.guim.co.uk/img/media/7a633730f5f90db3c12f6efc954a2d5b475c3d4a/0_138_5544_3327/master/5544.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=27c09d27ccbd139fd0f7d1cef8f7d41d"),
                ),
    

    【讨论】:

    • 感谢您的回复,但是为什么它没有得到用户图像?为什么它显示为空,当所有事情都完成时,当我单击浮动按钮继续时,它会将页面更改为主页,但它在主页上显示相同的错误。
    • 您是否检查过图片上传是否成功完成,您是否获得了相同的下载网址
    • 我是新来的颤振..但是当我点击继续它只显示用户名 useremail 和 userpassword ,用户图像显示为空......我把图像放在第一个上面显示用户图像是空的
    • 您是否检查过您的 Firebase 存储是否有图像?
    • 不,先生,我已经检查过了,但看不到图像
    猜你喜欢
    • 1970-01-01
    • 2020-07-01
    • 2021-07-02
    • 2021-05-04
    • 2021-04-12
    • 2020-12-14
    • 2020-03-01
    • 2022-06-27
    • 2021-06-18
    相关资源
    最近更新 更多