gpt4 book ai didi

dart - flutter 错误 :The argument type 'Future' can't be assigned to the parameter type 'Widget'

转载 作者:IT王子 更新时间:2023-10-29 06:58:37 24 4
gpt4 key购买 nike

我在使用 flutter flame 库时遇到了这个错误

The argument type 'Future<Image>' can't be assigned to the parameter
type 'Widget'.

我的代码是:

import 'package:flutter/material.dart';
import 'package:flame/flame.dart';

class TileMap extends StatefulWidget {
@override
_TileMapState createState() => _TileMapState();
}

class _TileMapState extends State<TileMap> {
@override
Widget build(BuildContext context) {
return Container(
child: Flame.images.load('grass_05.png'),
);
}
}

如何解决?问题是什么?谢谢大家

最佳答案

class _TileMapState extends State<TileMap> {
@override
void initState() {
super.initState();
_loadImage()
}

void _loadImage() async {
var img = await Flame.images.load('grass_05.png');
setState(() => _image = img);
}

Image _image;

@override
Widget build(BuildContext context) {
return Container(
child: _image,
);
}
}

关于dart - flutter 错误 :The argument type 'Future<Image>' can't be assigned to the parameter type 'Widget' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54503378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com