loadPreset method
- ViewPreset preset
Loads preset from Json Row
Implementation
Future<void> loadPreset(ViewPreset preset) async {
setNumViews(preset.views.length);
resetSizes();
for(var i = 0; i < preset.views.length; i++){
replaceView(i, preset.views[i], ignoreErrors: true);
}
// This delay is needed to prevent an error
//
// While [setNumViews] does update the number of views in the view model,
// it does not cause a build to occur. This small delay allows the next frame to be
// built, the UI to update, and *then* updates the ratios. This is necessary because
// the controllers listed below are directly tied to the UI.
await Future<void>.delayed(const Duration(milliseconds: 200));
if (preset.horizontal1.isNotEmpty) horizontalController1.setRatios(preset.horizontal1);
if (preset.horizontal2.isNotEmpty) horizontalController2.setRatios(preset.horizontal2);
if (preset.horizontal3.isNotEmpty) horizontalController3.setRatios(preset.horizontal3);
if (preset.horizontal4.isNotEmpty) horizontalController4.setRatios(preset.horizontal4);
if (preset.vertical1.isNotEmpty) verticalController.setRatios(preset.vertical1);
if (preset.vertical2.isNotEmpty) verticalController2.setRatios(preset.vertical2);
}