这是一个电子书应用程序,我从API中获取数据,在这个应用程序中,书籍显示得非常好,但是当我单击图书来读取这个红色屏幕错误时,仍然感到困惑的是,它是应用程序错误,还是位于PHP端,还是在vs代码中的调试面板上,当单击bookview.dart中突出显示的这一行错误时。
if (bookitem[0].bookDescription.isNotEmpty)
Container(
height: MediaQuery.of(context).size.height * 0.2,
color: Colors.black,
child: Row(
children: [
SizedBox(
width: 10,
),
这是在bookview.dart中突出显示错误的第二行。
ScreenUtilInit(
builder: () => Scaffold(
extendBodyBehindAppBar: true,
resizeToAvoidBottomInset: false,
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.of(context).pop();
},
),
centerTitle: true,
title: Text(bookitem[0].authorName),
backgroundColor: _gradientColor1,
),
这是控制台上的错误:
Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building LayoutBuilder:
The getter 'isNotEmpty' was called on null.
Receiver: null
Tried calling: isNotEmpty
The relevant error-causing widget was
ScreenUtilInit
package:ebook/screen/viewbook.dart:652
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:68:5)
#1 _ViewBookScreenState.build.<anonymous closure>
package:ebook/screen/viewbook.dart:846
发布于 2022-01-22 05:09:44
书签是数组,它在本质上是空的,您需要下面的代码来帮助您并检查第一个条件。
if (bookitem != null && bookitem[0].bookDescription.isNotEmpty)
Container(
height: MediaQuery.of(context).size.height * 0.2,
color: Colors.black,
child: Row(
children: [
SizedBox(
width: 10,
),
https://stackoverflow.com/questions/70812793
复制相似问题