i'm using flutter flame library and got this error
The argument type 'Future<Image>' can't be assigned to the parameter type 'Widget'.
my code is:
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'),
);
}
}
how to fix it? and what's the problem? thank's to all
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,
);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.