Flutter 颤振在自定义用户界面上使用水平中心
下面的屏幕截图是我设计的自定义ui,我想在Flutter 颤振在自定义用户界面上使用水平中心,flutter,flutter-layout,Flutter,Flutter Layout,下面的屏幕截图是我设计的自定义ui,我想在flatter 在下面的颤振中实现的代码中,我无法使卡 import 'package:flutter/material.dart'; void main() => runApp(LoginApp()); class LoginApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp(
flatter
在下面的颤振中实现的代码中,我无法使卡
import 'package:flutter/material.dart';
void main() => runApp(LoginApp());
class LoginApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.indigo,
accentColor: Colors.indigoAccent),
home: MaterialApp(
title: 'instaCheeta',
home: Scaffold(
body: Login(),
),
),
);
}
}
class Login extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
overflow: Overflow.visible,
children: <Widget>[
Container(
height: 200.0,
color: Colors.indigo,
),
Positioned(
child: Card(
margin: new EdgeInsets.fromLTRB(20, 90, 20, 70),
elevation: 2.0,
color: Colors.white,
child: Container(
decoration: BoxDecoration(color: Colors.white12),
),
)),
Positioned(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: new EdgeInsets.only(top: 50),
height: 100.0,
width: 100.0,
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: new BorderRadius.circular(50.0),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 2.0,
// has the effect of softening the shadow
spreadRadius: 1.0,
// has the effect of extending the shadow
offset: Offset(
0.0, // horizontal, move right 10
0.0, // vertical, move down 10
),
)
],
),
)
],
)),
],
);
}
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(LoginApp());
类LoginApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主题:主题数据(
亮度:亮度。暗,
原色:颜色。靛蓝,
accentColor:Color.indigoAccent),
主页:MaterialApp(
标题:“instaCheeta”,
家:脚手架(
正文:Login(),
),
),
);
}
}
类登录扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回堆栈(
溢出:溢出。可见,
儿童:[
容器(
高度:200.0,
颜色:颜色,靛蓝,
),
定位(
孩子:卡片(
边距:LTRB(20,90,20,70)的新边距集,
标高:2.0,
颜色:颜色,白色,
子:容器(
装饰:盒子装饰(颜色:Colors.white12),
),
)),
定位(
子:列(
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
容器(
边距:仅限新边集(顶部:50),
高度:100.0,
宽度:100.0,
装饰:新盒子装饰(
颜色:颜色,白色,
形状:BoxShape.rectangle,
边界半径:新边界半径。圆形(50.0),
boxShadow:[
箱形阴影(
颜色:颜色。灰色,
半径:2.0,
//具有软化阴影的效果
扩展半径:1.0,
//具有延伸阴影的效果
偏移量:偏移量(
0.0,//水平,向右移动10
0.0,//垂直,向下移动10
),
)
],
),
)
],
)),
],
);
}
}
您可以从这段代码中得到一些提示
class SO extends StatelessWidget {
var mainHeight = 200.0;
var circularHeight = 100.0;
@override
Widget build(BuildContext context) {
var shiftFraction = -(circularHeight) / (mainHeight - circularHeight);
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: 150,
),
Stack(
alignment: Alignment.topCenter.add(Alignment(0, shiftFraction)),
children: [
Container(
color: Colors.amber,
height: mainHeight,
),
ClipRRect(
borderRadius: BorderRadius.circular(circularHeight),
child: Container(
color: Colors.red,
width: circularHeight,
height: circularHeight,
),
),
],
),
],
),
);
}
}
类因此扩展了无状态小部件{
var mainHeight=200.0;
var circularHeight=100.0;
@凌驾
小部件构建(构建上下文){
var移位分数=-(循环光)/(主高度-循环光);
返回脚手架(
正文:专栏(
儿童:[
大小盒子(
身高:150,
),
堆叠(
对齐:对齐.topCenter.add(对齐(0,shiftFraction)),
儿童:[
容器(
颜色:颜色。琥珀色,
高度:主高度,
),
ClipRRect(
边界半径:边界半径。圆形(圆形右侧),
子:容器(
颜色:颜色,红色,
宽度:圆形光,
高度:圆形高度,
),
),
],
),
],
),
);
}
}
这给了我
实际上,圆形容器在柱内水平居中
问题是列的宽度等于圆的大小,而列本身位于堆栈的左上角。因此,有两种可能的解决方案:
- 使该列保持全宽
或
- 通过传递使柱自身居中
alignment:alignment.topCenter
到堆栈构造函数