[英]Circular button - flutter
我正在尝试创建一个圆形按钮,但是当我尝试使用 ElevatedButton 时出现错误:
这是代码:
import 'package:flutter/material.dart';
void main() => runApp(Menu());
class Menu extends StatefulWidget {
const Menu({super.key});
@override
State<Menu> createState() => _MenuState();
}
class _MenuState extends State<Menu> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
),
body: Center(
child: Container(
ElevatedButton(
backgroundColor: Colors.amberAccent,
onPressed: () {},
child: Icon(
Icons.train,
size: 35,
color: Colors.black,
),
),
),
)
);
}
}
我也曾尝试创建一个 FloatingActionButton,但没有成功。
Container 提供child
,你需要使用style
来装饰。
class _MenuState extends State<Menu> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Container(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.amberAccent,
),
onPressed: () {},
child: Icon(
Icons.train,
size: 35,
color: Colors.black,
),
),
),
));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.