This commit is contained in:
Mehul Ahal 2022-12-19 14:03:38 +01:00
commit 8e54cfffc5
91 changed files with 2686 additions and 0 deletions

View 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;
}

View 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'];
}

View file

@ -0,0 +1,3 @@
extension ListExtensions<T> on List<T> {
List<T> get deepCopy => [...this];
}

View file

@ -0,0 +1,3 @@
extension MapExtensions<A, B> on Map<A, B> {
Map<A, B> get deepCopy => {...this};
}

View 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;
}
}