gpt4 book ai didi

Flutter button alignment(颤振按钮对齐)

转载 作者:bug小助手 更新时间:2023-10-24 20:49:13 25 4
gpt4 key购买 nike



I am very new to Flutter development. I am trying to make a button that would be on the bottom right of the page, but it is not working.

我对扑翼的开发还很陌生。我正在尝试做一个按钮,将在页面的右下角,但它不工作。


import 'package:flutter/material.dart';
class GoBack extends StatelessWidget {
const GoBack({required this.onGoBack, super.key});

final void Function() onGoBack;

@override
Widget build(context) {
return OutlinedButton(
onPressed: onGoBack,
style: OutlinedButton.styleFrom(
backgroundColor: const Color.fromARGB(208, 93, 0, 255),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
minimumSize: const Size(60, 60),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.arrow_circle_left_rounded),
]),
);
}
}

I tried adding:

我试着添加:


alignment: Alignment.bottomRight,

I am probably using this wrong tho.

我可能用错了这个tho。


更多回答
优秀答案推荐

I think it is better for you to use floatingActionButtonLocation property of Scaffold widget. You can customize the button style with the FloatingActionButton widget.

我认为最好使用Scaffold小部件的FloatingActionButtonLocation属性。您可以使用FloatingActionButton小部件来自定义按钮样式。


return Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: FloatingActionButton.small(
onPressed: () {},
child: Icon(Icons.arrow_circle_left_rounded),
),
body: ...
);

You can visit https://blog.logrocket.com/flutter-floatingactionbutton-a-complete-tutorial-with-examples/ or https://api.flutter.dev/flutter/material/FloatingActionButton-class.html to see more details.

你可以访问https://blog.logrocket.com/flutter-floatingactionbutton-a-complete-tutorial-with-examples/或https://api.flutter.dev/flutter/material/FloatingActionButton-class.html查看更多详细信息。



you might use FloatingActionButton within Scaffold.

您可以在Scaffold中使用FloatingActionButton。


Scaffold(
floatingActionButton: FloatingActionButton(),)

It is located at right bottom by default.

默认情况下,它位于右下方。


Check documentation here :
https://api.flutter.dev/flutter/material/FloatingActionButton-class.html

请在此处查看文档:https://api.flutter.dev/flutter/material/FloatingActionButton-class.html


You can also use

您还可以使用


floatingActionButtonLocation: FloatingActionButtonLocation.endFloat

Therefore you can play with button location.

因此,您可以玩按钮位置。



Here you go. I believe this is what you want. It is the minimum viable code, under 30 lines. I hope it works. Feel free to provide acknowledgement in the comment below.

这就是你要的。我相信这就是你想要的。这是最小的可行代码,不超过30行。我希望它能起作用。请随时在下面的评论中提供确认。


class GoBack extends StatelessWidget {
const GoBack({required this.onGoBack, super.key});
final void Function() onGoBack;

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Align(
alignment: Alignment.bottomRight,
child: ElevatedButton(
onPressed: onGoBack,
style: OutlinedButton.styleFrom(
backgroundColor: const Color.fromARGB(208, 93, 0, 255),
shape: const RoundedRectangleBorder(),
minimumSize: const Size(60, 60),
),
child: const Icon(Icons.arrow_circle_left_rounded),
),
),
),
);
}
}

更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com