ensureLiveScenarioBinding function
The live binding, created once, for a folder that runs on the real clock
under bare flutter test. runScenarios(time: real) calls it; a config
that initializes a binding itself must call this rather than
TestWidgetsFlutterBinding.ensureInitialized(), because a binding already
built is the one the folder gets — and the wrong one is refused here by
name rather than found later as a scenario settling in fake seconds on a
real clock.
Implementation
LiveTestWidgetsFlutterBinding ensureLiveScenarioBinding({
double animations = 0.1,
}) {
switch (_currentTestBinding()) {
case LiveTestWidgetsFlutterBinding live:
return live;
case null:
return LiveHarnessBinding(
animations: animations,
wrapMessenger: (inner) => inner,
);
case var other:
throw StateError(
'runScenarios(time: real) needs the live binding, but '
"${other.runtimeType} is already initialized. In this folder's "
'flutter_test_config.dart call `ensureLiveScenarioBinding()` instead '
'of `TestWidgetsFlutterBinding.ensureInitialized()`, or call neither '
'and let runScenarios initialize the right one.',
);
}
}