setLocale method

Future<void> setLocale(
  1. String languageCode,
  2. String countryCode
)

Artificially calls dispatchLocalesChanged on the Widget binding, then flushes microtasks.

Passes only one single Locale. Use setLocales to pass a full preferred locales list.

Implementation

Future<void> setLocale(String languageCode, String countryCode) {
  return TestAsyncUtils.guard<void>(() async {
    assert(inTest);
    final Locale locale = Locale(languageCode, countryCode == '' ? null : countryCode);
    dispatchLocalesChanged(<Locale>[locale]);
  });
}