ApplicationModel constructor

ApplicationModel(
  1. WidgetModel parent, {
  2. String? key,
  3. required String url,
  4. String? title,
  5. String? icon,
  6. String? page,
  7. int? order,
  8. String? jwt,
})

Implementation

ApplicationModel(WidgetModel parent,
    {String? key,
    required this.url,
    this.title,
    this.icon,
    this.page,
    this.order,
    String? jwt})
    : super(parent, myId, scope: Scope(id: myId)) {
  // parse to url into its parts
  Uri? uri = Uri.tryParse(url);
  if (uri == null) return;

  // set database key
  _dbKey = key ?? url;

  // no scheme provided
  if (!uri.hasScheme) uri = Uri.tryParse("https://${uri.url}");
  if (uri == null) return;

  _scheme = uri.scheme;
  _host = uri.host;

  // set the start page
  String? fragment = uri.hasFragment ? uri.fragment : null;
  if (fragment != null && fragment.toLowerCase().contains(".xml")) {
    var myUri = Uri.tryParse(fragment);
    if (myUri != null) {
      _queryParameters = myUri.hasQuery ? myUri.queryParameters : null;
      _startPage = myUri.removeQuery().url;
    }
  } else {
    _queryParameters = uri.queryParameters;
  }

  // base domain
  _domain = uri
      .removeFragment()
      .removeQuery()
      .replace(userInfo: null)
      .removeEmptySegments()
      .url;

  // active user
  _user = UserModel(this, jwt: jwt);

  // load the config
  initialized = initialize();
}