无法加载资源:资源/在材质子项<Widget>中



我是在经历了may-SO问题之后问这个问题的。我试过很多答案。但他们中没有一个为我工作!!

SO中的大多数问题都是使用MaterialApp,但我返回的是普通的Material类,因为我不想要Actionbar或类似的东西。

我正在努力实现什么我正在尝试制作一个简单的登录屏幕,应用程序图标在顶部,然后是用户名、密码和;登录按钮在应用程序图标后面。

但是唉!应用程序图标未加载到AssetImage上。

下面是我的代码

class Login extends StatelessWidget{

@override
Widget build(BuildContext context) {
return new Material(
color: Color.fromARGB(255, 0, 68, 178),
child: new Container(
margin: const EdgeInsets.all(5.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
//This will have Login EditTexts....
children: <Widget>[
//Adding Logo on Login Screen....
//NOT WORKING
// new DecoratedBox(
//     decoration: BoxDecoration(
//       image: DecorationImage(
//           image: AssetImage("assets/app_logo.jpg")
//         )
//     ),
// ),
//NOT WORKING
// new ImageIcon(
//   new AssetImage("assests/app_logo.jpg"),
//   size: 24.0,
//   color: Colors.white,
// ),
//NOT WORKING
// new Container(
//   decoration: new BoxDecoration(
//     image: new DecorationImage(
//       colorFilter: new ColorFilter.mode(
//         Colors.black.withOpacity(0.6),
//         BlendMode.dstATop
//       ),
//       image: new AssetImage("assets/applogo.jpg"),
//       fit: BoxFit.contain
//     )
//   )
// ),
//NOT WORKING
// new Image.asset(
//           'assets/applogo.jpg',
//           height: 60.0,
//           fit: BoxFit.cover,
//         ),
//NOT WORKING
new Directionality(
textDirection:TextDirection.ltr,
child: new Image.asset(
"assets/applogo.jpg",
height: 100.0,
width: 100.0,
fit: BoxFit.contain
)
),
//WORKING
new Text("Lets Login....", textDirection: TextDirection.ltr),
//WORKING
//Username TextField goes below....
new Directionality(
textDirection: TextDirection.ltr,
child: new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Username:'
),
)
),

//WORKING
//Password TextField goes below......
new Directionality(
textDirection:TextDirection.ltr,
child: new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText:"Enter Password:"
)
)
),

//WORKING
//Login Button with Inkwell goes below....
new Directionality(
textDirection:TextDirection.ltr,
child: new InkWell(
child : new RaisedButton(
padding: const EdgeInsets.all(8.0),
textColor: Colors.white,
color: Colors.blue,
onPressed: login,
child: new Text("Login", textAlign: TextAlign.center, textDirection: TextDirection.ltr)
)
)
)

],
),//child Column closes here...

),//Container closes here.....
);//return Material closes here....
}//build closes here.....

void login(){
print("Login Pressed...");
}//login closes here....
}//Login class closes here....

下面是我的pubspec.yaml

flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
#  - images/a_dot_burr.jpeg
#  - images/a_dot_ham.jpeg
assets:
- assets/
- assets/app_logo.jpg

当您尝试引用图像资产时,代码中有一些拼写错误,如"assets/applogo.jpg"或">assests/app_logo.jpg"。例如:

Image.asset(
"assets/app_logo.jpg", 
height: 60.0, 
fit: BoxFit.cover
),

相关内容