mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-07 13:15:55 -06:00
fix: Enable logging in production
This commit is contained in:
48
lib/core/extensions/dart_extensions.dart
Normal file
48
lib/core/extensions/dart_extensions.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
extension NullableMapKey<K, V> on Map<K, V> {
|
||||
V? tryPutIfAbsent(K key, V? Function() ifAbsent) {
|
||||
final value = ifAbsent();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return putIfAbsent(key, () => value);
|
||||
}
|
||||
}
|
||||
|
||||
extension Unique<E, Id> on List<E> {
|
||||
List<E> unique([Id Function(E element)? id, bool inplace = true]) {
|
||||
final ids = <Id>{};
|
||||
var list = inplace ? this : List<E>.from(this);
|
||||
list.retainWhere((x) => ids.add(id != null ? id(x) : x as Id));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
extension DuplicateCheckable<T> on Iterable<T> {
|
||||
bool hasDuplicates() {
|
||||
return toSet().length != length;
|
||||
}
|
||||
}
|
||||
|
||||
extension DateHelpers on DateTime {
|
||||
bool get isToday {
|
||||
final now = DateTime.now();
|
||||
return now.day == day && now.month == month && now.year == year;
|
||||
}
|
||||
|
||||
bool get isYesterday {
|
||||
final yesterday = DateTime.now().subtract(const Duration(days: 1));
|
||||
return yesterday.day == day &&
|
||||
yesterday.month == month &&
|
||||
yesterday.year == year;
|
||||
}
|
||||
|
||||
bool isOnSameDayAs(DateTime other) {
|
||||
return other.day == day && other.month == month && other.year == year;
|
||||
}
|
||||
}
|
||||
|
||||
extension StringNormalizer on String {
|
||||
String normalized() {
|
||||
return trim().toLowerCase();
|
||||
}
|
||||
}
|
||||
18
lib/core/extensions/document_iterable_extensions.dart
Normal file
18
lib/core/extensions/document_iterable_extensions.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
extension DocumentModelIterableExtension on Iterable<DocumentModel> {
|
||||
Iterable<int> get ids => map((e) => e.id);
|
||||
|
||||
Iterable<DocumentModel> withDocumentreplaced(DocumentModel document) {
|
||||
return map((e) => e.id == document.id ? document : e);
|
||||
}
|
||||
|
||||
bool containsDocument(DocumentModel document) {
|
||||
return ids.contains(document.id);
|
||||
}
|
||||
|
||||
Iterable<DocumentModel> withDocumentRemoved(DocumentModel document) {
|
||||
return whereNot((element) => element.id == document.id);
|
||||
}
|
||||
}
|
||||
53
lib/core/extensions/flutter_extensions.dart
Normal file
53
lib/core/extensions/flutter_extensions.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension WidgetPadding on Widget {
|
||||
Widget padded([double all = 8.0]) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(all),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
Widget paddedSymmetrically({
|
||||
double horizontal = 0.0,
|
||||
double vertical = 0.0,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
Widget paddedOnly({
|
||||
double top = 0.0,
|
||||
double bottom = 0.0,
|
||||
double left = 0.0,
|
||||
double right = 0.0,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: top,
|
||||
bottom: bottom,
|
||||
left: left,
|
||||
right: right,
|
||||
),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
Widget paddedLTRB(double left, double top, double right, double bottom) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(left, top, right, bottom),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension WidgetsPadding on List<Widget> {
|
||||
List<Widget> padded([EdgeInsetsGeometry value = const EdgeInsets.all(8)]) {
|
||||
return map((child) => Padding(
|
||||
padding: value,
|
||||
child: child,
|
||||
)).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user