我应该怎么做才能在我的项目中应用我的背景图片?我错过了什么?我在 lib/assets/background.jpg 下找到的背景图片
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Util flameUtil = Util();
await flameUtil.fullScreen();
await flameUtil.setOrientation(DeviceOrientation.portraitUp);
LangawGame game = LangawGame();
runApp(game.widget);
}
langaw-game.dart
class LangawGame extends Game {
Size screenSize;
double tileSize;
@override
void render(Canvas canvas) {
body:
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.jpg"),
fit: BoxFit.cover,
),
),
);
}
@override
void update(double t) {}
@override
void resize(Size size) {
super.resize(size);
screenSize = size;
tileSize = screenSize.width / 9;
}
}
这是结果
这是背景
我没有收到错误,但图像没有反映