![](/img/trans.png)
[英]How do I ensure that the url of my image in flutter doesn't show up on the screen instead of the image?
[英]Image in container doesn't want to show in my screen Flutter Dart
圖像未顯示在我的屏幕上。 也有人可以告訴我 flatbutton 是怎么回事,矩形也沒有出現。
它應該是這樣的:
這是我的屏幕
我的代碼:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.pink,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center, children: [
new Container(
width: 100,
height: 100,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
image: new AssetImage("Image/Animegirl.jpg"),
fit: BoxFit.fill,
),
),
),
Text(
"Alice Payne",
style: TextStyle(fontSize: 50, color: Colors.white),
),
Text(
"MOBILE DEVELOPER",
style: TextStyle(fontSize: 40, color: Colors.white),
),
FlatButton.icon(
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
color: Colors.white,
label: Text("+212612174968",
style:TextStyle(
color: Colors.grey,
),
),
icon: Icon(Icons.phone,
size: 25,
color: Colors.white,
),
onPressed: (null)
),
FlatButton.icon(
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
color: Colors.white,
label: Text("hda.karima@gmail.com",
style:TextStyle(
color:Colors.grey,
),
),
icon: Icon(Icons.email,
size: 25,
color: Colors.white,
),
onPressed: (null)
),
]),
),),
),
);
}
還包括assets
image: AssetImage("assets/Image/Animegirl.jpg"),
將onPressed: (null)
替換為
onPressed: () {
}
您看到的樣式是禁用按鈕,因為您沒有提供 onTap 方法。
還要根據您的文件夾結構在 pubsub.yaml 中添加資產文件夾(如果圖像文件夾在資產文件夾內),請按照您的文件夾結構進行操作。
assets:
- assets/Image/
- assets/
然后使用image: new AssetImage("assets/Image/Animegirl.jpg")
你的代碼應該是這樣的
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.pink,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center, children: [
new Container(
width: 100,
height: 100,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
image: new AssetImage("Image/Animegirl.jpg"),
fit: BoxFit.fill,
),
),
),
Text(
"Alice Payne",
style: TextStyle(fontSize: 50, color: Colors.white),
),
Text(
"MOBILE DEVELOPER",
style: TextStyle(fontSize: 40, color: Colors.white),
),
FlatButton.icon(
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
color: Colors.white,
label: Text("+212612174968",
style:TextStyle(
color: Colors.grey,
),
),
icon: Icon(Icons.phone,
size: 25,
color: Colors.white,
),
onPressed: () {
}
),
FlatButton.icon(
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
color: Colors.white,
label: Text("hda.karima@gmail.com",
style:TextStyle(
color:Colors.grey,
),
),
icon: Icon(Icons.email,
size: 25,
color: Colors.white,
),
onPressed: () {
}
),
]),
),),
),
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.