ensureRefreshAction method
void
ensureRefreshAction({
- required String page,
- required List<
DslAction> actions, - BrownfieldPatternTarget? trigger,
- bool insertIntoAppBar = false,
- String name = 'RefreshAction',
- String icon = 'refresh',
- FFActionTriggerType triggerType = FFActionTriggerType.ON_TAP,
Ensures an existing trigger or app-bar action performs a refresh flow.
Set trigger to add actions onto an existing widget, or
insertIntoAppBar to insert a new refresh icon into the page app bar.
Implementation
void ensureRefreshAction({
required String page,
required List<DslAction> actions,
BrownfieldPatternTarget? trigger,
bool insertIntoAppBar = false,
String name = 'RefreshAction',
String icon = 'refresh',
FFActionTriggerType triggerType = FFActionTriggerType.ON_TAP,
}) {
raw((project) {
final editor = _pagePatternEditor(page);
final pageSnapshot = _requirePagePatternSnapshot(project, page);
final triggerTarget = trigger;
if (triggerTarget != null && insertIntoAppBar) {
throw ArgumentError(
'ensureRefreshAction(...) cannot use both trigger and '
'insertIntoAppBar=true.',
);
}
if (triggerTarget != null) {
final triggerRef = _resolvePatternTarget(
pageSnapshot,
editor,
triggerTarget,
operation: 'ensureRefreshAction(trigger: ...)',
);
editor.ensureActions(
_selectionForResolvedTarget(editor, triggerRef),
triggerType: triggerType,
actions: actions,
);
} else {
_requireAppBar(pageSnapshot, operation: 'ensureRefreshAction');
editor.ensureInsertedInto(
editor.slot('appBar'),
IconButton(icon, name: name),
slot: 'actions',
index: 0,
);
editor.ensureActions(
editor.findByName(name),
triggerType: triggerType,
actions: actions,
);
}
_applyBrownfieldWidgetClassEdit(project, editor);
});
}