pubspec.yaml
中添加
项目根目录/assets/images/
中是存在该图片的
但图片无论怎么刷新都加载不出来,根据文档反复对了很多次,实在找到不到代码在哪里出了问题。
重点来了…重新启动后,图片出来了……
以下为关键代码:
assets:
- assets/images/
Layout.dart
import 'package:flutter/material.dart';
import 'section/footer.dart';
import 'section/title.dart';
import 'section/reviews.dart';
class Layout extends StatefulWidget {
@override
_LayoutState createState() => _LayoutState();
}
class _LayoutState extends State<Layout> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
// 图片无法加载,
Image.asset(
'assets/images/avatar.png',
width: 200,
height: 200,
fit: BoxFit.cover
),
Reviews(),
titleSection,
textSection,
footerSection(context),
],
)
);
}
Widget headImage() {
}
Widget textSection = Container(
padding: const EdgeInsets.all(32),
child: Text(
'Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese '
'Alps. Situated 1,578 meters above sea level, it is one of the '
'larger Alpine Lakes. A gondola ride from Kandersteg, followed by a '
'half-hour walk through pastures and pine forest, leads you to the '
'lake, which warms to 20 degrees Celsius in the summer. Activities '
'enjoyed here include rowing, and riding the summer toboggan run.',
softWrap: true,
),
);
}