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

ActionMode dismissed callback #2

Closed
imsanjaysah opened this issue Jul 21, 2020 · 4 comments
Closed

ActionMode dismissed callback #2

imsanjaysah opened this issue Jul 21, 2020 · 4 comments

Comments

@imsanjaysah
Copy link

Hi,

First of all thank you for such a nice plugin. It does the job pretty well.

In one of my use case, I need to hide/unhide a view based on ActionMode enabled/disabled status. I tried to figure it out but could not able to identify if the ActionMode is disabled. Though by using the CounterBuilder I identified that the ActionMode is enabled when itemCount >= 0

Looking forward for your help.

Thanks in advance.

@De-Morgan
Copy link
Owner

De-Morgan commented Jul 22, 2020 via email

@De-Morgan
Copy link
Owner

De-Morgan commented Jul 22, 2020 via email

@imsanjaysah
Copy link
Author

@De-Morgan

Thank you for adding the feature.

I tried to use it. Refer the below code:

@override
  void initState() {
    super.initState();
    ActionMode.actionModeEnabledStream<int>(context).listen((bool status) {
      setState(() {
        _actionModeEnabled = status;
      });
    });
  }

But it throws an exception:

`════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following ProviderNotFoundException was thrown building DevicesPage(dirty, state: _DevicesPageState#ac953):
Error: Could not find the correct Provider<ItemsController> above this DevicesPage Widget

This likely happens because you used a BuildContext that does not include the provider
of your choice. There are a few common scenarios:

  • The provider you are trying to read is in a different route.

    Providers are "scoped". So if you insert of provider inside a route, then
    other routes will not be able to access that provider.

  • You used a BuildContext that is an ancestor of the provider you are trying to read.

    Make sure that DevicesPage is under your MultiProvider/Provider<ItemsController>.
    This usually happen when you are creating a provider and trying to read it immediatly.

    For example, instead of:

    Widget build(BuildContext context) {
      return Provider<Example>(
        create: (_) => Example(),
        // Will throw a ProviderNotFoundError, because `context` is associated
        // to the widget that is the parent of `Provider<Example>`
        child: Text(context.watch<Example>()),
      ),
    }
    

    consider using builder like so:

    Widget build(BuildContext context) {
      return Provider<Example>(
        create: (_) => Example(),
        // we use `builder` to obtain a new `BuildContext` that has access to the provider
        builder: (context) {
          // No longer throws
          return Text(context.watch<Example>()),
        }
      ),
    }
    

`

@De-Morgan
Copy link
Owner

This plugin makes use of Provider internally, as a result you can't use the actionModeEnabledStream above the ContextualActionScaffold, please check the Whatsapp example to see how it's being used

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

2 participants