Open Nobler opened 2 years ago
@Nobler Thanks for the report. Does this issue resemble your case ? https://github.com/flutter/flutter/issues/94123
If not, have you already tried using WidgetsFlutterBinding.ensureInitialized()
as the first code just after main()
to see if it helps ?
94123
Thanks for replying.
Production codes work fine just like you said:
class CustomWidgetFlutterBinding extends WidgetsFlutterBinding
with BinaryMessengerBinding {
static WidgetsBinding ensureInitialized() {
if (WidgetsBinding.instance == null) {
CustomWidgetFlutterBinding();
}
return WidgetsBinding.instance!;
}
}
void main() {
CustomWidgetFlutterBinding.ensureInitialized();
runApp();
}
My question is that the implementation of TestWidgetsFlutterBinding
in flutter_test package does not support testing BinaryMessengerBinding
.
Thanks for the update.
Use case
In my case, I override the
defaultBinaryMessenger
just likeTestDefaultBinaryMessengerBinding
is doing:When I want to test
BinaryMessengerBinding
intestWidget()
, there is no proper way to define a customTestWidgetsFlutterBinding
(test framework needs), because the definition ofTestWidgetsFlutterBinding
mixed withTestDefaultBinaryMessengerBinding
which needs the subclass/mixin also do the same thing (I guess, but am not sure) like:Proposal
So, is there any way to test
BinaryMessengerBinding
above? If not, could please provide a way to define a customTestWidgetsFlutterBinding
that overrides thedefaultBinaryMessenger
but will not break the test behavior.