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 `ReactterContext` of your choice.
There are a few common scenarios:

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

- The `ReactterContext` 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 `ReactterContext`.

- 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 `ReactterContext` and trying to read it immediately.

For example, instead of:

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

consider using `builder` like so:

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

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