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

Flushbar without context #136

Closed
sm2017 opened this issue May 8, 2020 · 3 comments
Closed

Flushbar without context #136

sm2017 opened this issue May 8, 2020 · 3 comments

Comments

@sm2017
Copy link

sm2017 commented May 8, 2020

How can I show flushbar without context?

@AndreHaueisen
Copy link
Owner

You can't. Flushbar needs a context to push itself into the route stack

@sm2017
Copy link
Author

sm2017 commented May 8, 2020

@AndreHaueisen

In first route, when we navigate to second route, we have a background task, the task may fail, I want to show a message to end user by flush bar, UI is in SecondRoute (or may be another route) and In FirstRoute after (or before , no matter) navigation, background task runned and after a while may be failed

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: 'Navigation Basics',
    home: FirstRoute(),
  ));
}

class FirstRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('First Route'),
      ),
      body: Center(
        child: RaisedButton(
          child: Text('Open route'),
          onPressed: () async {
            await Navigator.pushReplacement(
              context,
              MaterialPageRoute(builder: (context) => SecondRoute()),
            );
            Flushbar(
              title: "Hey Ninja",
              message:
                  "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
              duration: Duration(seconds: 3),
            )..show(context);
          },
        ),
      ),
    );
  }
}

class SecondRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Second Route"),
      ),
      body: Center(
        child: Text(
            "I want to show here Flushbar, Flushbar.show called in FirstRoute"),
      ),
    );
  }
}

@zxl777
Copy link

zxl777 commented Sep 12, 2020

If we don't use context it will be much more convenient.
Like this library https://pub.dev/packages/get or https://github.com/MMMzq/bot_toast, context is not needed.

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

No branches or pull requests

3 participants