Flutter 颤振:如何基于坐标定位徽标图像?
我不想使图像和文本居中,但我想为其设置一个特定的坐标。我似乎无法让对齐命令工作 目前,我的徽标图像和文本定位如下: 我希望徽标图像和文本朝向中心,但在y轴上稍微向上,而不是完全垂直居中 这是我的main.dart代码:Flutter 颤振:如何基于坐标定位徽标图像?,flutter,dart,Flutter,Dart,我不想使图像和文本居中,但我想为其设置一个特定的坐标。我似乎无法让对齐命令工作 目前,我的徽标图像和文本定位如下: 我希望徽标图像和文本朝向中心,但在y轴上稍微向上,而不是完全垂直居中 这是我的main.dart代码: import 'package:flutter/material.dart'; import 'login_page.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWid
import 'package:flutter/material.dart';
import 'login_page.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new LoginPage(),
theme: new ThemeData(
primarySwatch: Colors.green
)
);
}
}
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget{
@override
State createState() => new LoginPageState();
}
class LoginPageState extends State<LoginPage>{
@override
Widget build(BuildContext context){
return new Scaffold(
appBar: AppBar(
title: new Text("SMART ID", textAlign: TextAlign.center, style: TextStyle(fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/arrowPNG.png",
scale: 8.0,
)
)
),
backgroundColor: Colors.transparent,
body: Container(
child: Column(
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
}
}
这是我的登录页面。dart代码:
import 'package:flutter/material.dart';
import 'login_page.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new LoginPage(),
theme: new ThemeData(
primarySwatch: Colors.green
)
);
}
}
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget{
@override
State createState() => new LoginPageState();
}
class LoginPageState extends State<LoginPage>{
@override
Widget build(BuildContext context){
return new Scaffold(
appBar: AppBar(
title: new Text("SMART ID", textAlign: TextAlign.center, style: TextStyle(fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/arrowPNG.png",
scale: 8.0,
)
)
),
backgroundColor: Colors.transparent,
body: Container(
child: Column(
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
}
}
导入“包装:颤振/材料.省道”;
类LoginPage扩展StatefulWidget{
@凌驾
State createState()=>new loginpagentate();
}
类LoginPagentate扩展了状态{
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:appBar(
标题:新文本(“智能ID”,textAlign:textAlign.center,style:TextStyle(fontFamily:'Open Sans',fontWeight:fontWeight.bold)),
前导:填充(
填充:常数边集全部(8.0),
子:Image.asset(
“assets/arrowPNG.png”,
比例:8.0,
)
)
),
背景颜色:颜色。透明,
主体:容器(
子:列(
儿童:[
Image.asset('assets/arrowPNG.png',比例:2.5),
尺寸箱(高度:20,),
文本(“SMARTID”,样式:TextStyle(
fontSize:30,颜色:Colors.black,fontFamily:“开放式SAN”,fontWeight:fontWeight.bold,
))
],
),
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('assets/background.png'),
适合:BoxFit.cover,
)
)
)
);
}
}
提前谢谢 如果我理解,我会尽力帮助你: 首先,您可以将ITEN对齐到柱的中心:
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
容器(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
Image.asset('assets/arrowPNG.png',比例:2.5),
尺寸箱(高度:20,),
文本(“SMARTID”,样式:TextStyle(
fontSize:30,颜色:Colors.black,fontFamily:“开放式SAN”,fontWeight:fontWeight.bold,
))
],
),
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('assets/background.png'),
适合:BoxFit.cover,
)
)
)
);
在此之后,您可以使用容器中的填充或边距向上推徽标。你可以试试什么距离对你更合适。这是您的代码:
Container(
padding: EdgeInsets.only(bottom: 25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
容器(
填充:仅限边缘设置(底部:25.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
Image.asset('assets/arrowPNG.png',比例:2.5),
尺寸箱(高度:20,),
文本(“SMARTID”,样式:TextStyle(
fontSize:30,颜色:Colors.black,fontFamily:“开放式SAN”,fontWeight:fontWeight.bold,
))
],
),
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('assets/background.png'),
适合:BoxFit.cover,
)
)
)
);
我希望它能起作用 如果我理解,我会尽力帮助你: 首先,您可以将ITEN对齐到柱的中心:
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
容器(
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
Image.asset('assets/arrowPNG.png',比例:2.5),
尺寸箱(高度:20,),
文本(“SMARTID”,样式:TextStyle(
fontSize:30,颜色:Colors.black,fontFamily:“开放式SAN”,fontWeight:fontWeight.bold,
))
],
),
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('assets/background.png'),
适合:BoxFit.cover,
)
)
)
);
在此之后,您可以使用容器中的填充或边距向上推徽标。你可以试试什么距离对你更合适。这是您的代码:
Container(
padding: EdgeInsets.only(bottom: 25.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.black, fontFamily: 'Open Sans', fontWeight: FontWeight.bold,
))
],
),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/background.png'),
fit: BoxFit.cover,
)
)
)
);
容器(
填充:仅限边缘设置(底部:25.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
Image.asset('assets/arrowPNG.png',比例:2.5),
尺寸箱(高度:20,),
文本(“SMARTID”,样式:TextStyle(
fontSize:30,颜色:Colors.black,fontFamily:“开放式SAN”,fontWeight:fontWeight.bold,
))
],
),
宽度:MediaQuery.of(context).size.width,
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage('assets/background.png'),
适合:BoxFit.cover,
)
)
)
);
我希望它能起作用 您可以在
堆栈中移动背景图像和徽标
,然后使用定位
从垂直位置放置徽标
class LoginState extends State<Login> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("SMARTID", textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset(
"assets/images/appicon.png",
scale: 8.0,
)
)
),
backgroundColor: Colors.transparent,
body: Stack(
children: <Widget>[
Container(
alignment: Alignment(0, -0.5),
width: MediaQuery
.of(context)
.size
.width,
height: MediaQuery
.of(context)
.size
.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/background.jpg'),
fit: BoxFit.cover,
)
)
),
Positioned(
width: MediaQuery.of(context).size.width,
top: MediaQuery.of(context).size.width * 0.30,//TRY TO CHANGE THIS **0.30** value to achieve your goal
child: Container(
margin: EdgeInsets.all(16.0),
child:Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/appicon.png', scale: 2.5),
SizedBox(height: 20,),
Text("SMARTID", style: TextStyle(
fontSize: 30, color: Colors.white,fontFamily: 'Open Sans',
fontWeight: FontWeight.bold))
]
),
))
],
)
);
}
}
类LoginState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:Text(“SMARTID”,textAlign:textAlign.center,