resolveChildren method
Map<FormFactor, Widget>
resolveChildren(
- Map<
FormFactor, Widget> explicitChildren, - FormFactorsData formFactorsData
override
For given list of supported form factors contained in formFactorsData
and explicitly matched widgets, returns a map of matched widgets for all
supported form factors.
Implementation
@override
Map<FormFactor, Widget> resolveChildren(
Map<FormFactor, Widget> explicitChildren,
FormFactorsData formFactorsData) {
final result = <FormFactor, Widget>{};
final portraitFormFactors = explicitChildren.keys
.where((item) => item.orientation == Orientation.portrait);
final landscapeFormFactors = explicitChildren.keys
.where((element) => element.orientation == Orientation.landscape);
final defaultPortrait =
portraitFormFactors.isEmpty ? null : portraitFormFactors.first;
final defaultLandscape =
landscapeFormFactors.isEmpty ? null : landscapeFormFactors.first;
FormFactor? currentFormFactor;
for (FormFactor formFactor in formFactorsData.formFactors
.where((item) => item.orientation == Orientation.portrait)) {
if (explicitChildren.keys.contains(formFactor)) {
currentFormFactor = formFactor;
}
result[formFactor] = explicitChildren[
currentFormFactor ?? defaultPortrait ?? defaultLandscape]!;
}
currentFormFactor = null;
for (FormFactor formFactor in formFactorsData.formFactors
.where((item) => item.orientation == Orientation.landscape)) {
if (explicitChildren.keys.contains(formFactor)) {
currentFormFactor = formFactor;
}
result[formFactor] = explicitChildren[
currentFormFactor ?? defaultLandscape ?? defaultPortrait]!;
}
return result;
}