54 lines
1.2 KiB
Dart
54 lines
1.2 KiB
Dart
import 'package:objectbox/objectbox.dart';
|
|
import 'package:mobdr/objectbox.g.dart';
|
|
import 'package:xml/xml.dart';
|
|
import 'package:mobdr/service/shared_prefs.dart';
|
|
|
|
// ignore_for_file: public_member_api_docs
|
|
|
|
@Entity()
|
|
class PhotoTypology {
|
|
// specify the id
|
|
@Id()
|
|
int id = 0;
|
|
|
|
int id_photo_typologie;
|
|
String libelle;
|
|
int ordre;
|
|
|
|
PhotoTypology({
|
|
this.id = 0,
|
|
required this.id_photo_typologie,
|
|
required this.libelle,
|
|
required this.ordre,
|
|
});
|
|
|
|
PhotoTypology.fromJson(Map<String, dynamic> json)
|
|
: id_photo_typologie = json['id_photo_typologie'],
|
|
libelle = getI18nLabel(json['libelle']),
|
|
ordre = json['ordre'];
|
|
}
|
|
|
|
String getI18nLabel(String label) {
|
|
final langage = SharedPrefs().langage;
|
|
final document = XmlDocument.parse(label);
|
|
|
|
try {
|
|
for (var noeud in document.children[0].children) {
|
|
if (noeud is XmlElement) {
|
|
if (noeud.name.local == langage) {
|
|
return noeud.innerText;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (var noeud in document.children[0].children) {
|
|
if (noeud is XmlElement && noeud.name.local == 'fr') {
|
|
return '(fr) ${noeud.innerText}';
|
|
}
|
|
}
|
|
|
|
return label;
|
|
} catch (e) {}
|
|
return label;
|
|
}
|