如何将按钮对齐到屏幕底部? [扑]

How to Align Buttons To The Bottom of Screen? [Flutter]

无论底部是一个按钮还是两个按钮,我都希望将它们对齐到屏幕底部,在所有屏幕尺寸中,Android 或 iOS。

如果屏幕是可滚动的,它仍将保留在那里。我没有使用 BottomNavigation Bar 来实现该功能,因为我认为它不合适。

我用过

Scaffold(
            floatingActionButton: FloatingActionButton.extended(
              onPressed: () {},
              isExtended: true,
              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              label: Text('Hello World',
                
            ),
            floatingActionButtonLocation:
                FloatingActionButtonLocation.centerDocked,
            body:...

此方法用于固定单个按钮的目的。但是,这不允许使用 2 个按钮。有时我想为用户提供一个选项,例如本页的选项 A,下一页的选项 B。

你对此有何看法?

        Scaffold(
             body: Column(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children:[ 
                        floatingActionButton: FloatingActionButton.extended(
                        onPressed: () {},
                        isExtended: true,
                        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                        label: Text('Hello World',
                        ...
                    ),
                    floatingActionButtonLocation:
                        FloatingActionButtonLocation.centerDocked,
                    ...
                ]

您可以为 floatingActionButton 属性提供一个 Row 小部件,并根据您的意愿对齐按钮。

例子

   Scaffold(
      floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
            onPressed: () {},
            child: Text("Button 1"),
          ),
          ElevatedButton(
            onPressed: () {},
            child: Text("Button 2"),
          ),
        ],
      ),
    );