Files
HiddingselAppOriginal/lib/appflow/model/represented_organisations.dart
2026-02-13 15:53:22 +01:00

80 lines
3.2 KiB
Dart

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<String> _tags;
List<String> get tags => [name]..addAll(_tags)..addAll(person.tags)..addAll(contact.tags);
Future<bool> 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<String, dynamic> 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<String, dynamic>),
ContactModel.fromJson(json['contact'] as Map<String, dynamic>),
json['text'] as String?,
(json['tags'] as List<dynamic>).cast<String>(),
(json['ical'] as String?) != null
? Uri.parse(json['ical'] as String)
: null,
);
}
static RepresentedOrganisationModel? fromWordpressId(int wordpressId) =>
RepresentedOrganisationModel.values.cast<RepresentedOrganisationModel?>().firstWhere((o) => o?.wordpressId == wordpressId, orElse: () => null);
static List<RepresentedOrganisationModel> values = GetIt.I<List<RepresentedOrganisationModel>>()..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;
}