| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- import 'dart:convert';
- import 'dart:math' as math;
- import 'package:flutter/material.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:intl/intl.dart';
- import 'package:timeago/timeago.dart' as timeago;
- import 'lat_lng.dart';
- import 'place.dart';
- import 'uploaded_file.dart';
- import '/backend/schema/structs/index.dart';
- import '/auth/custom_auth/auth_util.dart';
- String? kortDatum(String? rawDatum) {
- if (rawDatum == null || rawDatum.trim().isEmpty) {
- return rawDatum;
- }
- const weekdagen = {
- 'maandag': 'ma',
- 'dinsdag': 'di',
- 'woensdag': 'wo',
- 'donderdag': 'do',
- 'vrijdag': 'vr',
- 'zaterdag': 'za',
- 'zondag': 'zo',
- };
- const maandVolledig = {
- 'januari': 'jan',
- 'februari': 'feb',
- 'maart': 'mrt',
- 'april': 'apr',
- 'mei': 'mei',
- 'juni': 'jun',
- 'juli': 'jul',
- 'augustus': 'aug',
- 'september': 'sep',
- 'oktober': 'okt',
- 'november': 'nov',
- 'december': 'dec',
- };
- const maandKort = {
- 'jan',
- 'feb',
- 'mrt',
- 'apr',
- 'mei',
- 'jun',
- 'jul',
- 'aug',
- 'sep',
- 'okt',
- 'nov',
- 'dec',
- };
- // Alles vanaf de komma (bv. ", 15:00") negeren.
- final zonderTijd = rawDatum.split(',').first.trim().toLowerCase();
- final delen = zonderTijd.split(RegExp(r'\s+'));
- if (delen.length < 3) {
- return rawDatum;
- }
- final weekdag = weekdagen[delen[0]];
- final dag = delen[1];
- final maandRuw = delen[2].replaceAll('.', '');
- final maand = maandVolledig[maandRuw] ??
- (maandKort.contains(maandRuw) ? maandRuw : null);
- if (weekdag == null || maand == null) {
- return rawDatum;
- }
- final tijdDelen = rawDatum.split(',');
- final tijd =
- tijdDelen.length > 1 ? tijdDelen.sublist(1).join(',').trim() : '';
- return tijd.isNotEmpty
- ? '$weekdag $dag $maand $tijd'
- : '$weekdag $dag $maand';
- }
- String? provincieNaamById(
- List<ProvincieModelStruct>? lijst,
- String? id,
- ) {
- return lijst
- ?.firstWhere((e) => e.provincieid == id,
- orElse: () => ProvincieModelStruct())
- .provinciename;
- }
- /// id
- String? gemeenteNaamById(
- List<GemeenteModelStruct>? lijst,
- String? id,
- ) {
- return lijst
- ?.firstWhere((e) => e.gemeenteid == id,
- orElse: () => GemeenteModelStruct())
- .gemeentename;
- }
- String? favorietenBodyNode(String nid) {
- return '{"entity_id": ' + nid + ', "entity_type": "node"}';
- }
- String googleMapsUrl(
- String adres,
- String plaats,
- ) {
- return 'https://www.google.com/maps/search/?api=1&query=' +
- Uri.encodeComponent('$adres, $plaats');
- }
- List<dynamic> filterHorecagelegenheden(
- List<dynamic> items,
- String zoekterm,
- String? categorieFilter,
- String titelPad,
- String categoriePad,
- ) {
- final titelKey =
- titelPad.startsWith(r'$.') ? titelPad.substring(2) : titelPad;
- final categorieKey =
- categoriePad.startsWith(r'$.') ? categoriePad.substring(2) : categoriePad;
- final term = zoekterm
- .trim()
- .toLowerCase()
- .replaceAll('à', 'a')
- .replaceAll('á', 'a')
- .replaceAll('ä', 'a')
- .replaceAll('â', 'a')
- .replaceAll('è', 'e')
- .replaceAll('é', 'e')
- .replaceAll('ë', 'e')
- .replaceAll('ê', 'e')
- .replaceAll('ì', 'i')
- .replaceAll('í', 'i')
- .replaceAll('ï', 'i')
- .replaceAll('î', 'i')
- .replaceAll('ò', 'o')
- .replaceAll('ó', 'o')
- .replaceAll('ö', 'o')
- .replaceAll('ô', 'o')
- .replaceAll('ù', 'u')
- .replaceAll('ú', 'u')
- .replaceAll('ü', 'u')
- .replaceAll('û', 'u')
- .replaceAll('ñ', 'n')
- .replaceAll('ç', 'c');
- final catFilter = categorieFilter?.trim();
- return items.where((item) {
- final map = item is Map ? item : null;
- if (term.isNotEmpty) {
- final titelRaw = map?[titelKey]?.toString() ?? '';
- final titel = titelRaw
- .toLowerCase()
- .replaceAll('à', 'a')
- .replaceAll('á', 'a')
- .replaceAll('ä', 'a')
- .replaceAll('â', 'a')
- .replaceAll('è', 'e')
- .replaceAll('é', 'e')
- .replaceAll('ë', 'e')
- .replaceAll('ê', 'e')
- .replaceAll('ì', 'i')
- .replaceAll('í', 'i')
- .replaceAll('ï', 'i')
- .replaceAll('î', 'i')
- .replaceAll('ò', 'o')
- .replaceAll('ó', 'o')
- .replaceAll('ö', 'o')
- .replaceAll('ô', 'o')
- .replaceAll('ù', 'u')
- .replaceAll('ú', 'u')
- .replaceAll('ü', 'u')
- .replaceAll('û', 'u')
- .replaceAll('ñ', 'n')
- .replaceAll('ç', 'c');
- if (!titel.contains(term)) {
- return false;
- }
- }
- if (catFilter != null && catFilter.isNotEmpty) {
- final categorie = map?[categorieKey];
- final lijst = (categorie is List) ? categorie : <dynamic>[];
- final match = lijst
- .any((c) => c.toString().toLowerCase() == catFilter.toLowerCase());
- if (!match) {
- return false;
- }
- }
- return true;
- }).toList();
- }
- String? datumVoorApi(String? datum) {
- String datumVoorApi(String? datum) {
- if (datum == null) return '';
- final s = datum.trim();
- if (s.isEmpty) return '';
- final punt = s.indexOf('.');
- return punt == -1 ? s : s.substring(0, punt);
- }
- }
- String? buildStempel() {
- String buildStempel() {
- return const String.fromEnvironment('BUILD_TS', defaultValue: 'onbekend');
- }
- }
|