I am trying to create a circular button, but there is an error when I try to use ElevatedButton:
This is the code:
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,
),
),
),
)
);
}
}
I have also tried to create a FloatingActionButton, but it didn't worked.
CodePudding user response:
Container provide child
and you need to use style
for decoration.
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,
),
),
),
));
}
}