经过可能的问题后,我问这个问题。 我已经尝试了很多答案。但是没有一个人在为我工作!
SO中的大多数问题都在使用MaterialApp,但我返回的是普通的Material类bcoz,我不想要Actionbar或类似的东西。
我要实现的目标? 我正在尝试创建一个简单的登录屏幕,其中“应用程序”图标位于顶部,然后“用户名”,“密码”和“登录按钮”紧随该应用程序图标。
但是a!未在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
答案 0 :(得分:1)
当您尝试引用图像资产时,代码中存在一些错字,例如“ assets / applogo .jpg”或“ assets /app_logo.jpg”。尝试以下示例:
Image.asset(
"assets/app_logo.jpg",
height: 60.0,
fit: BoxFit.cover
),