【发布时间】:2021-06-24 17:28:21
【问题描述】:
我对 Flutter 很陌生,我试图实现这个观点:
所以基本上我只是尝试在中心有一个Row(Image 和Text),在底部有一个Column(2 TextButton 和一个RichText),但我无法做到这一点Align 和 Stack 甚至 Column 和 mainAxisAlignment。
当我尝试使用包含 3 个小部件的 mainAxisAlignement Column 时,它只是没有底部对齐。
当我尝试将Stack 与Align 一起使用时,它也不起作用
也许我不应该使用 Column 作为 Scaffold 的主体?但我不知道如果是这样我应该用什么来替换它。小部件的任何帮助或解释都会有所帮助。
这是我的完整代码
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
//color
final textColorContainer = new Container(color: const Color(0xffff62fa));
final pinkColorContainer = new Container(color: const Color(0xffffe3fe));
final bottomAppBarContainer = new Container(color: const Color(0xfff5f5f5));
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
body: Column(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/pictalio_logo.png'),
Text("Pictalio",
style: TextStyle(
fontFamily: "Sen",
fontWeight: FontWeight.w700,
fontSize: 30))
],
),
Stack(
children: <Widget>[
Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
width: double.infinity,
child: TextButton(
child: Text('Signup with my email',
style: TextStyle(fontWeight: FontWeight.w700)),
style: TextButton.styleFrom(
backgroundColor: pinkColorContainer.color,
primary: textColorContainer.color,
shape: const BeveledRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(5))),
),
onPressed: () {
print('Pressed');
},
)),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
width: double.infinity,
child: TextButton(
child: Text('Signup with my google',
style: TextStyle(fontWeight: FontWeight.w700)),
style: TextButton.styleFrom(
backgroundColor: pinkColorContainer.color,
primary: textColorContainer.color,
shape: const BeveledRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(5))),
),
onPressed: () {
print('Pressed');
},
)),
),
Align(
alignment: Alignment.bottomCenter,
child: RichText(
text: TextSpan(
text: "Already have an account?",
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.w700),
children: <TextSpan>[
TextSpan(
text: ' Sign in!',
style: TextStyle(
color: textColorContainer.color,
fontWeight: FontWeight.w700)),
],
),
),
),
],
),
]),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.videocam_sharp), label: "video"),
BottomNavigationBarItem(
icon: Icon(Icons.add_box_rounded),
label: 'Add',
),
BottomNavigationBarItem(
icon: Icon(Icons.notifications),
label: 'Notification',
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: 'Account',
),
],
showSelectedLabels: false,
showUnselectedLabels: false,
currentIndex: _selectedIndex,
selectedItemColor: pinkColorContainer.color,
unselectedItemColor: Colors.black,
type: BottomNavigationBarType.fixed,
backgroundColor: bottomAppBarContainer.color,
onTap: _onItemTapped,
),
);
}
}
【问题讨论】: