toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  return '''
Error: Could not find the correct `ReactterProvider<$valueType>` above this `$widgetType` Widget

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

- You added a new `ReactterProvider` in your `main.dart` and perform a hot-restart.

- The instance you are trying to read is in a different route.

`ReactterProvider` is a "scoped". So if you insert of `ReactterProvider` inside a route, then
other routes will not be able to access that instance.

- You used a `BuildContext` that is an ancestor of the `ReactterProvider` you are trying to read.

Make sure that `$widgetType` is under your `ReactterProvider<$valueType>`.
This usually happens when you are creating a instance and trying to read it immediately.

For example, instead of:

```
Widget build(BuildContext context) {
  return ReactterProvider(
    () => AppController(),
    // Will throw a `ReactterInstanceNotFoundException`,
    // because `context` is out of `ReactterProvider`'s scope.
    child: Text(context.watch<AppController>().state.value),
  ),
}
```

Try to use `builder` propery of `ReactterProvider` to access the instance inmedately as it created, like so:

```
Widget build(BuildContext context) {
  return ReactterProvider(
    () => AppController(),
    // we use `builder` to obtain a new `BuildContext` that has access to the provider
    builder: (context, appController, child) {
      // No longer throws
      context.watch<AppController>();
      return Text(appController.state.value),
    }
  ),
}
```

If none of these solutions work, consider asking for help on StackOverflow:
https://stackoverflow.com/questions/tagged/flutter
''';
}