Mobx.dart: Fail to generate Store with State in StatefulWidget.

Created on 20 Mar 2020  路  3Comments  路  Source: mobxjs/mobx.dart

This fail a regression that happened after I pump mobx version from 0.4 to be 1.0.

The build runner fail to generate Store with State in StatefulWidget like so:

part 'test_widget.g.dart';

class TestWidget extends StatefulWidget {
  @override
  _TestWidgetState createState() => _TestWidgetState();
}

class _TestWidgetState = _TestWidgetStore with _$_TestWidgetState;

abstract class _TestWidgetStore extends State<TestWidget> with Store {

  @observable
  int counter;

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Here is the error

Most helpful comment

You can turn it off with @storeConfig(toString: false) on the Store class

All 3 comments

This because we have toString() method in _$_TestWidgetState which conflict with toString({DiagnosticLevel minLevel}) in Diagnosable (State implement Diagnosable).

I guess we couldn't change toString() to toString({DiagnosticLevel minLevel}) cause this will make MobX itself depending on Flutter.

You can turn it off with @storeConfig(toString: false) on the Store class

You can turn it off with @storeConfig(toString: false) on the Store class

In case anyone else finds this issue with a similar problem, I believe that the syntax is @StoreConfig(hasToString: false) (note the capitalization as well as the parameter).

Was this page helpful?
0 / 5 - 0 ratings