我正在使用Flutter Flame Library并收到此错误
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'),
);
}
}
如何解决? 有什么问题吗? 谢谢大家
答案 0 :(得分:1)
class _TileMapState extends State<TileMap> {
@override
void initState() {
super.initState();
_loadImage()
}
void _loadImage() await {
var img = await Flame.images.load('grass_05.png');
setState(() => _image = img);
}
Image image;
@override
Widget build(BuildContext context) {
return Container(
child: _image,
);
}
}