Flutter SnackBarAction cannot set height

37 Views Asked by At

Cannot set height for snack bar. I need to use snack bar action. But the action label affect snack bar height, when give a long action label text. Does anyone face the same issue ?

long label text affect snackbar height:

enter image description here

short label text is normal:

enter image description here

Reproduce code:

final snackBar = SnackBar(
  shape: const StadiumBorder(),
  content: const Text('Alamat belum lengkap.',
    style: TextStyle(color: Colors.white)),
      action: SnackBarAction(
        label: 'Lengkapi Alamat',
        onPressed: () {},
    ),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
1

There are 1 best solutions below

0
MendelG On

It seems like the SnackBar will be as big as its child.

As an alternative, you can use the another_flushbar package.

There's also a mainButton property as an alternative to your SnackBarAction.

enter image description here

Here's a complete example:

import 'package:another_flushbar/flushbar.dart';
import 'package:flutter/material.dart';

void main() => runApp(
      MaterialApp(
        home: Scaffold(
          body: MyApp(),
        ),
      ),
    );

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: MaterialButton(
          onPressed: () {
            Flushbar(
              mainButton: ElevatedButton(
                onPressed: () {},
                child: Text(
                  'Lengkapi Alamat',
                  style: TextStyle(color: Colors.amber),
                ),
              ),
              message: "Alamat belum lengkap\n very long message to show",
              duration: Duration(seconds: 3),
            )..show(context);
          },
          child: Text('Show Flushbar'),
        ),
      ),
    );
  }
}