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,35 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
abstract class ConstColours {
/// Smoke Gray => a neutral grey with neutral warmth/cold
static const imageBackgroundColour = Color.fromRGBO(127, 127, 125, 1.0);
static const white = Colors.white;
static const black = Colors.black;
}
abstract class ConstThemes {
static ThemeData get materialLightTheme => ThemeData(
useMaterial3: true,
brightness: Brightness.light,
colorSchemeSeed: ConstColours.white,
);
static ThemeData get materialDarkTheme => ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorSchemeSeed: ConstColours.white,
);
static CupertinoThemeData get cupertinoLightTheme => const CupertinoThemeData(
brightness: Brightness.light,
);
static CupertinoThemeData get cupertinoDarkTheme => const CupertinoThemeData(
brightness: Brightness.dark,
);
static ThemeData get cupertinoThemeLightHack =>
materialLightTheme.copyWith(cupertinoOverrideTheme: cupertinoLightTheme);
static ThemeData get cupertinoThemeDarkHack =>
materialDarkTheme.copyWith(cupertinoOverrideTheme: cupertinoDarkTheme);
}

View file

@ -0,0 +1,6 @@
enum ViewModelState {
isInitialising,
isInitialised,
isBusy,
hasError;
}

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