[英]asset is unable to load in Flutter?
I want to show decoration image in flutter , but there is an error, i don't know why?我想在 flutter 中显示装饰图像,但是出现错误,我不知道为什么? I am new to flutter i want to show image as an background of an activity in Flutter.
我是颤振的新手,我想将图像显示为颤振中活动的背景。 I attached the error message below, is any thing is missing or any thing extra in my code, i am unable to understand.
我在下面附上了错误消息,我的代码中是否缺少任何内容或任何额外内容,我无法理解。
Code代码
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(MaterialApp(
title: "Creating account",
home: new account(),
));
}
class account extends StatefulWidget {
@override
_accountState createState() => _accountState();
}
class _accountState extends State<account> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Container(
/// color: Colors.blueGrey,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/image.jpg'), // <-- BACKGROUND IMAGE
fit: BoxFit.cover,
),
),
padding: EdgeInsets.all(40),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FlutterLogo(
size: 100,
colors: Colors.grey,
),
TextFormField(
obscureText: false,
// keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Icon(Icons.person, color: Colors.grey),
hintText: "Full Name",
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),
),
TextFormField(
obscureText: false,
// keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Icon(Icons.person, color: Colors.grey),
hintText: 'Email',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),
),
TextFormField(
obscureText: false,
keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Icon(Icons.person, color: Colors.grey),
hintText: 'Cell Number',
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),
),
TextFormField(
obscureText: true,
obscuringCharacter: "x",
// keyboardType: TextInputType.number,
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock, color: Colors.white),
hintText: 'Password',
hintStyle: TextStyle(
color: Colors.white, fontWeight: FontWeight.w600),
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),
),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.blue)),
color: Colors.white,
textColor: Colors.red,
padding: EdgeInsets.fromLTRB(40, 8, 40, 8),
onPressed: () => _displaySnackBar(context),
child: Text(
"Create Account",
style: TextStyle(
fontSize: 20.0,
),
),
),
],
),
),
),
);
}
_displaySnackBar(BuildContext context) {
final snackBar = SnackBar(content: Text('Aww SnackBar!'));
_scaffoldKey.currentState.showSnackBar(snackBar);
}
}
Error Message错误信息
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: images/image.jpg
Please check your pubspec.ymal file and add path of your asset folder there.请检查您的 pubspec.ymal 文件并在那里添加您的资产文件夹的路径。 assets>Images its folder in my app where I have icons or images.
assets>Images 在我的应用程序中的文件夹中,我有图标或图像。
assets:
- assets/images/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.