mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.4k stars 310 forks source link

Add ability to hide 'No observables detected in the build method of Observer' #676

Open Alan-Gomes opened 3 years ago

Alan-Gomes commented 3 years ago

Currently, this package warns the developer if a Observer is being used without any observables inside it's build method. It can be quite useful during development, but it sends a lot of messages during tests, example (the real output have thousands of occurrences):

00:01 +4: ~/test/app/shared/components/timesheet_timer_test.dart: Should not load the timer when disabled                                                                                                                                                  
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build (~/app/shared/components/timesheet/timesheet_timer.dart:75:12)
00:01 +5: ~/test/app/shared/components/timesheet_timer_test.dart: Should have a start timer button when timer is not running                                                                                                                               
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build (~/app/shared/components/timesheet/timesheet_timer.dart:75:12)
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build.<anonymous closure> (~/app/shared/components/timesheet/timesheet_timer.dart:99:13)
00:02 +6: ~/test/app/shared/components/timesheet_timer_test.dart: Should have a stop timer button when timer is running                                                                                                                                    
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build (~/app/shared/components/timesheet/timesheet_timer.dart:75:12)
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build.<anonymous closure> (~/app/shared/components/timesheet/timesheet_timer.dart:99:13)
00:02 +7: ~/test/app/shared/components/timesheet_timer_test.dart: Should start the timer when tap                                                                                                                                                          
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build (~/app/shared/components/timesheet/timesheet_timer.dart:75:12)
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build.<anonymous closure> (~/app/shared/components/timesheet/timesheet_timer.dart:99:13)
00:02 +8: ~/test/app/shared/components/timesheet_timer_test.dart: Should stop the timer when tap                                                                                                                                                           
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build (~/app/shared/components/timesheet/timesheet_timer.dart:75:12)
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build.<anonymous closure> (~/app/shared/components/timesheet/timesheet_timer.dart:99:13)
00:02 +9: ~/test/app/shared/components/timesheet_timer_test.dart: Should reset the timer when tap                                                                                                                                                          
No observables detected in the build method of Observer
#3      _TimesheetTimerState.build (~/app/shared/components/timesheet/timesheet_timer.dart:75:12)
No observables detected in the build method of Observer

While inside a test, the widget actually communicates with a mock rather than an actual observable. There's no way to hide this message, and the test output becomes a lot bigger.

My suggestion is to add an API to disable these messages at runtime, example: FlutterMobx.disableNoObservablesWarning = true;

gabrielguedest commented 2 years ago

Hey! Is there a reason why this suggestion was closed?

pedrox-hs commented 1 year ago

Fixed here: #778

Since flutter_mobx: 2.0.5 we can disable message with:

enableWarnWhenNoObservables = false;