I am creating a cross-platform app for both web and mobile. The buttons however have different default height depending on the platform. How can I make the height of the button to be the same size on both mobile and web without checking the platform?
In my case, a button on the Web was noticeably smaller than on mobile. I was passing padding
explicitly, but it was adjusted inside the Flutter framework.
Mobile (as intended):
Web:
The button code looks like this:
@override
Widget build(BuildContext context) => RaisedButton(
onPressed: onPressed,
color: color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
child: child,
);
I fixed the problem by setting visualDensity
to VisualDensity.standard
in ThemeData
in MaterialApp
initialization. For some reason, the default was VisualDensity.compact
.
class MyApp extends StatelessWidget {
// ...
@override
Widget build(BuildContext context) => MaterialApp(
// ...
theme: ThemeData(
// ...
visualDensity: VisualDensity.standard,
),
// ...
);
}
Now size is as intended also on Web.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With