processFCPGridButtonPressed method
Implementation
Future<void> processFCPGridButtonPressed(
String elementId, {
String? pressId,
}) async {
CPGridButton? gridButton;
l1:
for (var t in templateHistory) {
// Grid templates can live at top level OR as children of a
// CPTabBarTemplate, so search both.
final List<CPGridTemplate> gridTemplates = [];
if (t is CPTabBarTemplate) {
for (var template in t.templates) {
if (template is CPGridTemplate) {
gridTemplates.add(template);
}
}
} else if (t is CPGridTemplate) {
gridTemplates.add(t);
}
for (var g in gridTemplates) {
for (var b in g.buttons) {
if (b.uniqueId == elementId) {
gridButton = b;
break l1;
}
}
}
}
Future<void>? completion;
Future<void> complete() => completion ??= flutterToNativeModule(
FCPChannelTypes.onGridButtonPressedComplete,
pressId == null
? elementId
: <String, dynamic>{'elementId': elementId, 'pressId': pressId},
).then((_) {});
try {
final loadingHandler = gridButton?.onPressWithCompletion;
if (loadingHandler != null) {
await Future.sync(() => loadingHandler(complete, gridButton!));
} else {
await Future.sync(() => gridButton?.onPress?.call());
await complete();
}
} catch (_) {
await complete();
}
}