首页 > 解决方案 > Flutter:小部件库错误捕获的异常

问题描述

在我正在开发的应用程序中,我不断收到以下错误。错误之后是它指向的代码部分。

Exception caught by widgets library ══════════════════════════════════
'package:flutter/src/painting/_network_image_io.dart': Failed assertion: line 25 pos 14: 
'url != null': is not true.
The relevant error-causing widget was
Homepage
lib/…/LandingPage/landingServices.dart:359

** 第 359 行在 child: Homepage() 下方,我在之前和之后添加了代码。══════════════════════════════════════════════════ ══════════════════════════════

                           .createUserCollection(context, {
                            'userpassword': userPasswordController.text,
                            '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));

我的主页代码在这里:

   class Homepage extends StatefulWidget {
   @override
   _HomepageState createState() => _HomepageState();
 }

  class _HomepageState extends State<Homepage> {
  ConstantColors constantColors = ConstantColors();
  final PageController homepageController = PageController();
  int pageIndex = 0;

 @override
 void initState() {
 Provider.of<FirebaseOperations>(context, listen: false)
    .initUserData(context);
 super.initState();
 }

 @override
 Widget build(BuildContext context) {
 return Scaffold(
    backgroundColor: constantColors.darkColor,
    body: PageView(
      controller: homepageController,
      children: [Feed(), Chatroom(), Profile()],
      physics: NeverScrollableScrollPhysics(),
      onPageChanged: (page) {
        setState(() {
          pageIndex = page;
        });
      },
    ),
    bottomNavigationBar:
        Provider.of<HomepageHelpers>(context, listen: false)
            .bottomNavBar(context, pageIndex, homepageController));
 }
}

任何想法?我想不通。谢谢!

标签: flutter

解决方案


只需将上下文更改为homepageController右侧的内容.. 相信我,它肯定会起作用..


 bottomNavigationBar:
        Provider.of<HomepageHelpers>(context, listen: false)
            .bottomNavBar(pageIndex, homepageController, context));
 }
}

推荐阅读