在过去的几天里,我只是在尝试Flutter。我正在尝试添加图像,但根本不会显示。 我缺少明显的东西吗?
main.dart
with tempfile.NamedTemporaryFile(mode='wt', dir=F"{os.path.dirname(os.path.dirname(os.path.realpath(__file__)))}/assets/fetch/", delete=False, suffix=".xml") as fp:
fp.write(generate_xml(param))
from time import sleep
sleep(.05)
MODEL_PATH = fp.name
model = mujoco_py.load_model_from_path(MODEL_PATH)
和我的pubspec.yaml
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PicHuntingNigga',
home: Scaffold(
appBar: AppBar(
title: Text('PicHunting-Nigga'),
centerTitle: true,
backgroundColor: Colors.red,
),
body: new Center(
child: new MyCameraWidget(),
),
),
);
}
}
class MyCameraWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
var assetImage = new AssetImage('assets/images/camera1.png');
var image = new Image(image: assetImage, width: 225.0, height: 225.0);
return new Container(child: image);
}
}
我的文件夹结构
运行模拟器后-所有内容都会减去图片。我可以将图像替换为name: flutter_app
description: A new Flutter application.
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/images/camera.png
- assets/images/camera1.png
- assets/images/
子级,它将呈现文本,但不呈现图像。
答案 0 :(得分:0)
另请参见此处示例https://flutter.dev/docs/development/ui/assets-and-images
Widget build(BuildContext context) {
// ...
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/background.png'),
// ...
),
// ...
),
);
// ...
}
答案 1 :(得分:0)
所以我解决了!
不确定如何...。我刚刚关闭笔记本电脑,然后再打开。我也吃过晚饭,现在可以了。
所以,如果您遇到类似的问题,请共进晚餐?看来这对我来说是解决方案。