【发布时间】:2020-04-11 18:55:56
【问题描述】:
我是Flutter 的新手。我有一个StatefulWidget 和一个default parameter,我已经完成了我的研究,许多人已经用vivid 的例子回答了这个问题,例如izwebtechnologies 和StackOverFlow 我仍然无法让我的代码工作。它给了我错误
Invalid argument(s)
The relevant error-causing widget was:
Gallery file:///xxx/xxx/xxx/xxx/lib/main.dart:241:13
我的第 214 行看起来像
var images = new List<String>();
.
.
.
class NewGallery extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _scafoldkey = GlobalKey<ScaffoldState>();
return Scaffold(
key: _scafoldkey,
backgroundColor: Colors.transparent,
//Where the exception is occurring from main.dart:241:13
body: Gallery(images),
);
}
}
我的画廊课
class Gallery extends StatefulWidget {
final List<String> images;
const Gallery(this.images);
@override
State createState() => new _GalleryState();
}
我的画廊状态类
class _GalleryState extends State<Gallery> {
int currentImageIndex;
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.black,
body: new Dismissible(
//resizeDuration: null,
onDismissed: (DismissDirection direction) {
setState(() {
currentImageIndex +=
direction == DismissDirection.endToStart ? 1 : -1;
if (currentImageIndex < 0) {
currentImageIndex = widget.images.length - 1;
} else if (currentImageIndex >= widget.images.length) {
currentImageIndex = 0;
}
});
},
key: new ValueKey(currentImageIndex),
child: SizedBox.expand(
child: Container(
color: Colors.black,
margin: const EdgeInsets.only(left: 0, top: 40),
child: FadeInImage.assetNetwork(
fit: BoxFit.fitWidth,
placeholder: "assets/images/placeholder.png",
image: widget.images.elementAt(currentImageIndex)))),
),
);
}
}
请注意,我是 Flutter 的新手,很多东西还是不明白,因此我的代码可能没有优化。
【问题讨论】:
-
有什么问题?
-
我的问题是如何修复错误 Invalid argument(s) 相关的导致错误的小部件是:Gallery file:///xxx/xxx/xxx/xxx/lib/main.dart: 241:13