open method
Implementation
Future<bool> open(Map<String, String?>? parameters,
{bool? refresh = false, WidgetModel? model, String? dependency}) async {
bool ok = true;
parameters ??= <String, String>{};
String url = fromMap(parameters, 'url', defaultValue: "");
bool modal = fromMapAsBool(parameters, 'modal', defaultValue: false) ?? false;
String? transition = fromMap(parameters, 'transition');
String? width = fromMap(parameters, 'width');
String? height = fromMap(parameters, 'height');
int? index = fromMapAsInt(parameters, 'index');
bool? replace = fromMapAsBool(parameters, 'replace', defaultValue: false);
bool? replaceAll =
fromMapAsBool(parameters, 'replaceall', defaultValue: false);
var uri = URI.parse(url);
if (uri == null) return false;
var d1 = uri.host.toLowerCase();
var d2 = System.currentApp?.host?.toLowerCase();
bool sameDomain = d1 == d2;
bool xmlFile = uri.pageExtension == "xml";
bool local = sameDomain && xmlFile;
// We need to keep the file:// prefix as an indicator for fetch() that its a local file
String? template = uri.domain.toLowerCase();
// missing template?
if (isNullOrEmpty(template)) {
//await DialogService().show(type: DialogType.error, title: phrase.missingTemplate, description: url, buttons: [Text(phrase.ok)]);
return ok;
}
// open external url in browser?
if (!local) return _openBrowser(url);
// open new page in modal window?
if (modal && model != null) {
bool ok = false;
var framework = model.findParentOfExactType(FrameworkModel);
if (framework != null) {
var view = FrameworkModel.fromUrl(framework, url,
refresh: refresh ?? false, dependency: dependency)
.getView();
ModalManagerView? manager =
model.context?.findAncestorWidgetOfExactType<ModalManagerView>();
if (manager != null) {
var modal = ModalView(ModalModel(model, null,
child: view, modal: false, width: width, height: height));
manager.model.modals.add(modal);
manager.model.refresh();
ok = true;
}
}
return ok;
}
/* replace */
if (replace! && _pages.isNotEmpty) _pages.removeLast();
/* replace all */
if (replaceAll!) _pages.clear();
/* open a new page */
_open(url, transition: transition, index: index, dependency: dependency);
return ok;
}