init
This commit is contained in:
commit
8e54cfffc5
91 changed files with 2686 additions and 0 deletions
13
lib/features/core/data/extensions/context_extensions.dart
Normal file
13
lib/features/core/data/extensions/context_extensions.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension DarkMode on BuildContext {
|
||||
/// is dark mode currently enabled?
|
||||
///
|
||||
/// Using the context version in release throws exception.
|
||||
bool get isDarkMode =>
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness == Brightness.dark;
|
||||
|
||||
double get width => MediaQuery.of(this).size.width;
|
||||
double get height => MediaQuery.of(this).size.height;
|
||||
}
|
6
lib/features/core/data/extensions/dio_extensions.dart
Normal file
6
lib/features/core/data/extensions/dio_extensions.dart
Normal file
|
@ -0,0 +1,6 @@
|
|||
import 'package:dio/dio.dart';
|
||||
|
||||
extension ResponseExtensions on Response {
|
||||
/// Shorthand for getting response's successful state.
|
||||
bool get isSuccessful => (data as Map)['response'];
|
||||
}
|
3
lib/features/core/data/extensions/list_extensions.dart
Normal file
3
lib/features/core/data/extensions/list_extensions.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
extension ListExtensions<T> on List<T> {
|
||||
List<T> get deepCopy => [...this];
|
||||
}
|
3
lib/features/core/data/extensions/map_extensions.dart
Normal file
3
lib/features/core/data/extensions/map_extensions.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
extension MapExtensions<A, B> on Map<A, B> {
|
||||
Map<A, B> get deepCopy => {...this};
|
||||
}
|
37
lib/features/core/data/extensions/stream_extensions.dart
Normal file
37
lib/features/core/data/extensions/stream_extensions.dart
Normal file
|
@ -0,0 +1,37 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
|
||||
extension StreamExtensions<T> on Stream<T> {
|
||||
ValueListenable<T> toValueNotifier(
|
||||
T initialValue, {
|
||||
bool Function(T previous, T current)? notifyWhen,
|
||||
}) {
|
||||
final notifier = ValueNotifier<T>(initialValue);
|
||||
listen((value) {
|
||||
if (notifyWhen == null || notifyWhen(notifier.value, value)) {
|
||||
notifier.value = value;
|
||||
}
|
||||
});
|
||||
return notifier;
|
||||
}
|
||||
|
||||
ValueListenable<T?> toNullableValueNotifier({
|
||||
bool Function(T? previous, T? current)? notifyWhen,
|
||||
}) {
|
||||
final notifier = ValueNotifier<T?>(null);
|
||||
listen((value) {
|
||||
if (notifyWhen == null || notifyWhen(notifier.value, value)) {
|
||||
notifier.value = value;
|
||||
}
|
||||
});
|
||||
return notifier;
|
||||
}
|
||||
|
||||
Listenable toListenable() {
|
||||
final notifier = ChangeNotifier();
|
||||
listen((_) {
|
||||
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
|
||||
notifier.notifyListeners();
|
||||
});
|
||||
return notifier;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue