1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import 'package:flutter/material.dart';
- extension MapExt<K, V> on Map<K, V> {
- T? getCheck<T>(K? key) {
- if (key == null || !containsKey(key)) {
- return null;
- }
- var value = this[key];
- if (value is! T) {
- return null;
- }
- return value as T?;
- }
- }
- extension StringExt on String? {
- bool get isNullOrEmpty {
- return this == null || this!.isEmpty;
- }
- }
- extension ListExt<T> on List<T>? {
- bool get isNullOrEmpty {
- return this == null || this!.isEmpty;
- }
- }
- extension DateTimeExt on DateTime {
- String get yyyyMMddHHmmss =>
- "$year-${month < 10 ? "$month".padLeft(2, "0") : month}-$day ${hour < 10 ? "$hour".padLeft(2, "0") : hour}:${minute < 10 ? "$minute".padLeft(2, "0") : minute}:${second < 10 ? "$second".padLeft(2, "0") : second}";
- }
- extension ContextExt on BuildContext {
- ThemeData get theme => Theme.of(this);
- TextTheme get textTheme => theme.textTheme;
- TextStyle? get titleLarge => textTheme.titleLarge;
- TextStyle? get titleMedium => textTheme.titleMedium;
- TextStyle? get titleSmall => textTheme.titleSmall;
- TextStyle? get bodyLarge => textTheme.bodyLarge;
- TextStyle? get bodyMedium => textTheme.bodyMedium;
- TextStyle? get bodySmall => textTheme.bodySmall;
- ColorScheme get colorScheme => theme.colorScheme;
- Color get primaryColor => colorScheme.primary;
- Color get onPrimaryColor => colorScheme.onPrimary;
- Color get surfaceContainerHighColor => colorScheme.surfaceContainerHigh;
- Color get onSurfaceVariantColor => colorScheme.onSurfaceVariant;
- Color get onSurfaceColor => colorScheme.onSurface;
- }
|