import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:get_it/get_it.dart'; import 'package:hiddingsel_app/appflow/model/images.dart'; import 'package:hiddingsel_app/appflow/model/persons.dart'; import 'package:hiddingsel_app/appflow/model/event_organisations.dart'; import '../../constants/constant.dart'; import '../../services/environment.dart'; import '../controller/settings.dart'; import 'contacts.dart'; import 'interfaces.dart'; class RepresentedOrganisationModel extends EventOrganisationModel with Contact, Person, IsFavorable, IsSearchable { final int wordpressId; final ImageModel image; final PersonModel person; final ContactModel contact; InlineSpan get text => stringToInlineSpan(info); final String? info; final List _tags; List get tags => [name]..addAll(_tags)..addAll(person.tags)..addAll(contact.tags); Future get favorized => SettingsController.favorized(this); favorize(bool favorize) { if (favorize) { SettingsController.favorize(this); } else { SettingsController.unfavorize(this); } } InlineSpan stringToInlineSpan(String? text) { final textblocks = text?.split('\\'); return TextSpan(children: textblocks?.map((textblock) { if (textblock.startsWith('link=')) { String link = textblock.substring(5); return TextSpan(text: link, style: UITheme.theme.textTheme.bodyLarge, recognizer: TapGestureRecognizer()..onTap = () => EnvironmentConnector.openBrowser(Uri.parse(link))); } else { return TextSpan(text: textblock, style: UITheme.theme.textTheme.bodyLarge); } }).toList()); } const RepresentedOrganisationModel.withImageModel(id, name, this.wordpressId, this.image, this.person, this.contact, this.info, this._tags, Uri? ical) : super(id, name, ical); RepresentedOrganisationModel(id, name, this.wordpressId, String imageResource, this.person, this.contact, this.info, this._tags, Uri? ical) : image = ImageModel(imageResource), super(id, name, ical); factory RepresentedOrganisationModel.fromJson(Map json) { return RepresentedOrganisationModel( json['id'] as String, json['name'] as String, json['wordpress_id'] as int, json['image'] as String, PersonModel.fromJson(json['person'] as Map), ContactModel.fromJson(json['contact'] as Map), json['text'] as String?, (json['tags'] as List).cast(), (json['ical'] as String?) != null ? Uri.parse(json['ical'] as String) : null, ); } static RepresentedOrganisationModel? fromWordpressId(int wordpressId) => RepresentedOrganisationModel.values.cast().firstWhere((o) => o?.wordpressId == wordpressId, orElse: () => null); static List values = GetIt.I>()..sort((a, b) => a.name.compareTo(b.name)); bool operator ==(Object other) => other is RepresentedOrganisationModel && runtimeType == other.runtimeType && id == other.id; int get hashCode => id.hashCode; }