我如何更改 ElevatedButton 的位置
how i can change place of ElevatedButton
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: const Icon(Icons.home),
automaticallyImplyLeading: true,
title: const Text('test app'),
foregroundColor: Colors.black,
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.menu),
),
],
),
body: Container(
child: Column(
children: [
Row(
children: [
const Text(
'New',
style: TextStyle(
color: Colors.black54,
fontSize: 40,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
height: 2,
shadows: [
Shadow(color: Colors.black12, offset: Offset(4, 10))
]),
),
ElevatedButton.icon(onPressed: (){}, icon: Icon(Icons.navigate_next),label: Text(' '),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.grey),
),
),
],
),
Row(),
],
),
),
),
);
}
您可以根据需要使用 4 个选项
如果你想要它低于新的你可以使用列而不是行。
如果你想在新的旁边放一些 space 你可以在文本和提升的按钮之间使用 SizedBox(width:X)。
可以在行或列内部使用mainAxisAlignment或crossAxisAlignment来自定义位置
你可以在这里找到关于它们的例子 https://docs.flutter.dev/development/ui/layout
您可以在提升的按钮上使用边距或填充来自定义其自己的位置
使用 Row 小部件属性来布置其子元素
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [....]
)
官方文档在这方面很有帮助
https://api.flutter.dev/flutter/widgets/Row-class.html
- 旁注:如果您不打算使用任何第一个 container() 属性,那么最好去掉它
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: const Icon(Icons.home),
automaticallyImplyLeading: true,
title: const Text('test app'),
foregroundColor: Colors.black,
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.menu),
),
],
),
body: Container(
child: Column(
children: [
Row(
children: [
const Text(
'New',
style: TextStyle(
color: Colors.black54,
fontSize: 40,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
height: 2,
shadows: [
Shadow(color: Colors.black12, offset: Offset(4, 10))
]),
),
ElevatedButton.icon(onPressed: (){}, icon: Icon(Icons.navigate_next),label: Text(' '),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.grey),
),
),
],
),
Row(),
],
),
),
),
);
}
您可以根据需要使用 4 个选项
如果你想要它低于新的你可以使用列而不是行。
如果你想在新的旁边放一些 space 你可以在文本和提升的按钮之间使用 SizedBox(width:X)。
可以在行或列内部使用mainAxisAlignment或crossAxisAlignment来自定义位置 你可以在这里找到关于它们的例子 https://docs.flutter.dev/development/ui/layout
您可以在提升的按钮上使用边距或填充来自定义其自己的位置
使用 Row 小部件属性来布置其子元素
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [....]
)
官方文档在这方面很有帮助 https://api.flutter.dev/flutter/widgets/Row-class.html
- 旁注:如果您不打算使用任何第一个 container() 属性,那么最好去掉它