大家好,请帮助我。我想制作一个注册页面(设计图片如下)。我尽可能多地编写代码。如果我做任何其他事情都会出错(下面也给出了我的代码和应用程序结果屏幕截图)。所以告诉我我在代码中如何对齐按钮。只需说一下对齐方式/放置位置就可以了
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Travel Budget App",
theme: ThemeData(
primarySwatch: Colors.green,
),
home: FirstView(),
);
}
}
class FirstView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.only(bottom: 100),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
child: Padding(
padding: const EdgeInsets.only(
top: 10.0, bottom: 10.0, left: 30.0, right: 30.0),
),
onPressed: () {},
),
RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
child: Padding(
padding: const EdgeInsets.only(
top: 10.0, bottom: 10.0, left: 30.0, right: 30.0),
),
onPressed: () {},
),
],
),
),
)
);
}
}
有多种方法可以实现。
使用堆栈:脚手架->堆栈-> [已定位(顶部:8,右侧:8),列-> [Raisedbutton1,RaisedButton2]]
使用列支架->列-> [Align(Aligment:Alignment.centerRight),Spacer(),RaisedButton1,RaisedButton2]
如果您不了解第一种选择,请阅读有关堆栈和定位小部件的信息。希望对您有所帮助:)
正如@ saiful-islam-adar所述,有多种方法可以实现我使用了spacer
class FirstView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 100, horizontal: 10.0),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RoundedButton(
color: Colors.white, text: 'Login', onPressed: () {}),
],
),
Spacer(),
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
RoundedButton(
color: Colors.white, text: 'E-mail', onPressed: () {}),
SizedBox(
height: 10,
),
RoundedButton(
color: Colors.white, text: 'Facebook', onPressed: () {}),
],
),
],
),
));
}
}