Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter web button size issue

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?

like image 514
Michal Kubizna Avatar asked Oct 18 '25 05:10

Michal Kubizna


1 Answers

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):

Mobile

Web:

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.

like image 54
cubuspl42 Avatar answered Oct 20 '25 16:10

cubuspl42