43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
extension BuildContextExtension on BuildContext {
|
|
ThemeData get theme => Theme.of(this);
|
|
TextTheme get textTheme => Theme.of(this).textTheme;
|
|
ColorScheme get colorScheme => Theme.of(this).colorScheme;
|
|
MediaQueryData get mediaQuery => MediaQuery.of(this);
|
|
Size get screenSize => MediaQuery.sizeOf(this);
|
|
double get screenWidth => screenSize.width;
|
|
double get screenHeight => screenSize.height;
|
|
bool get isMobile => screenWidth < 600;
|
|
bool get isTablet => screenWidth >= 600 && screenWidth < 1200;
|
|
bool get isDesktop => screenWidth >= 1200;
|
|
|
|
void showSnackBar(String message, {bool isError = false}) {
|
|
ScaffoldMessenger.of(this).showSnackBar(
|
|
SnackBar(
|
|
content: Text(message),
|
|
backgroundColor: isError ? colorScheme.error : null,
|
|
behavior: SnackBarBehavior.floating,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
extension StringExtension on String {
|
|
String get capitalize =>
|
|
isEmpty ? this : '${this[0].toUpperCase()}${substring(1)}';
|
|
|
|
bool get isValidEmail => RegExp(
|
|
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
|
|
).hasMatch(this);
|
|
|
|
bool get isValidPassword => length >= 8;
|
|
}
|
|
|
|
extension DateTimeExtension on DateTime {
|
|
String get toFormattedString => '$year-${month.toString().padLeft(2, '0')}-${day.toString().padLeft(2, '0')}';
|
|
|
|
String get toFormattedDateTime =>
|
|
'$toFormattedString ${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}';
|
|
}
|