Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlay can't be the root overlay when persistent is false #3

Closed
alizera opened this issue Feb 3, 2020 · 3 comments
Closed

overlay can't be the root overlay when persistent is false #3

alizera opened this issue Feb 3, 2020 · 3 comments
Labels
question Further information is requested

Comments

@alizera
Copy link

alizera commented Feb 3, 2020

I'm calling the sample showTopFlash() inside my app and get following error:

overlay can't be the root overlay when persistent is false
'package:flash/flash.dart':
Failed assertion: line 99 pos 14: 'overlay != rootOverlay'

This is my simple code to reproduce:

class _TestScreenState extends State<TestScreen> {
  int which = 0;

  @override
  Widget build(BuildContext context) {
    GlobalKey<ScaffoldState> _key = GlobalKey<ScaffoldState>();
    FlashHelper.init(context);
    return Scaffold(
      key: _key,
      body: Center(child: FlatButton(onPressed: (){
        _showTopFlash();
      }, child: Text('show Flash')),),
    );
  }
  void _showTopFlash({FlashStyle style = FlashStyle.floating}) {
    showFlash(
      context: context,
      duration: const Duration(seconds: 5),
      persistent: false,
      builder: (_, controller) {
        return Flash(
          controller: controller,
          backgroundColor: Colors.white,
          brightness: Brightness.light,
          boxShadows: [BoxShadow(blurRadius: 4)],
          barrierBlur: 3.0,
          barrierColor: Colors.black38,
          barrierDismissible: true,
          style: style,
          position: FlashPosition.bottom,
          child: FlashBar(
            title: Text('Title'),
            message: Text('Hello world!'),
            showProgressIndicator: true,
            primaryAction: FlatButton(
              onPressed: () => controller.dismiss(),
              child: Text('DISMISS', style: TextStyle(color: Colors.amber)),
            ),
          ),
        );
      },
    );
  }

}

When I set the persistent:true it works without Blur effect.
Thanks for your nice lib.

@sososdk
Copy link
Owner

sososdk commented Feb 20, 2020

Hi, @alizera
You need warp you TestScreen with Overlay. Please refer to the example

@sososdk sososdk added the question Further information is requested label Feb 20, 2020
@sososdk sososdk closed this as completed Apr 26, 2020
@fernando-s97
Copy link

Do I really need to wrap every single screen that uses Flash with an Overlay or there's a better alternative?

@sososdk
Copy link
Owner

sososdk commented May 8, 2021

@fernando-s97 When the persistent is false, you need warp the screen of the context with an Overlay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants