[0.1.0]
This commit is contained in:
8
lib/astromic_extensions.dart
Normal file
8
lib/astromic_extensions.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
library astromic_extensions;
|
||||
|
||||
export './src/border_extensions.dart';
|
||||
export './src/insets_extension.dart';
|
||||
export './src/list_extensions.dart';
|
||||
export 'src/alignment_extensions.dart';
|
||||
export './src/radius_extensions.dart';
|
||||
export './src/string_extensions.dart';
|
||||
16
lib/src/alignment_extensions.dart
Normal file
16
lib/src/alignment_extensions.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension TextAlignVerticalExtension on TextAlignVertical {
|
||||
Alignment toAlignment() {
|
||||
switch (this) {
|
||||
case TextAlignVertical.top:
|
||||
return Alignment.topCenter;
|
||||
case TextAlignVertical.center:
|
||||
return Alignment.center;
|
||||
case TextAlignVertical.bottom:
|
||||
return Alignment.bottomCenter;
|
||||
default:
|
||||
return Alignment.center;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
lib/src/border_extensions.dart
Normal file
7
lib/src/border_extensions.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
import "package:flutter/painting.dart";
|
||||
|
||||
extension BorderExtension on BorderDirectional {
|
||||
BorderDirectional all(BorderSide side) {
|
||||
return BorderDirectional(top: side, bottom: side, start: side, end: side);
|
||||
}
|
||||
}
|
||||
12
lib/src/insets_extension.dart
Normal file
12
lib/src/insets_extension.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension InsetsExtension on EdgeInsetsGeometry {
|
||||
copyWith(EdgeInsetsGeometry g) => add(g);
|
||||
//
|
||||
EdgeInsetsDirectional resolveToDirectional(TextDirection direction) {
|
||||
//
|
||||
return EdgeInsetsDirectional.fromSTEB(direction == TextDirection.ltr ? resolve(direction).left : resolve(direction).right, resolve(direction).top,
|
||||
direction == TextDirection.ltr ? resolve(direction).right : resolve(direction).left, resolve(direction).bottom);
|
||||
//
|
||||
}
|
||||
}
|
||||
20
lib/src/list_extensions.dart
Normal file
20
lib/src/list_extensions.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
extension ListExtension<E> on List<E> {
|
||||
bool containsAll(List<E> otherList) {
|
||||
List<bool> checks = [];
|
||||
//
|
||||
for (E thisElement in otherList) {
|
||||
checks.add(contains(thisElement));
|
||||
}
|
||||
return !checks.contains(false);
|
||||
}
|
||||
|
||||
List<E> getUnique() {
|
||||
List<E> uniqueItems = [];
|
||||
for (E thisElement in this) {
|
||||
if (!uniqueItems.contains(thisElement)) {
|
||||
uniqueItems.add(thisElement);
|
||||
}
|
||||
}
|
||||
return uniqueItems;
|
||||
}
|
||||
}
|
||||
15
lib/src/radius_extensions.dart
Normal file
15
lib/src/radius_extensions.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension RadiusExtension on BorderRadiusGeometry {
|
||||
copyWith(BorderRadiusGeometry g) => add(g);
|
||||
//
|
||||
BorderRadiusDirectional resolveToDirectional(TextDirection direction) {
|
||||
//
|
||||
return BorderRadiusDirectional.only(
|
||||
topStart: direction == TextDirection.ltr ? resolve(direction).topLeft : resolve(direction).topRight,
|
||||
topEnd: direction == TextDirection.rtl ? resolve(direction).topLeft : resolve(direction).topRight,
|
||||
bottomEnd: direction == TextDirection.rtl ? resolve(direction).bottomRight : resolve(direction).bottomRight,
|
||||
bottomStart: direction == TextDirection.ltr ? resolve(direction).bottomLeft : resolve(direction).bottomRight,
|
||||
);
|
||||
}
|
||||
}
|
||||
19
lib/src/string_extensions.dart
Normal file
19
lib/src/string_extensions.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension StringExtensions on String {
|
||||
/// Parse the HexCode to color
|
||||
Color get toColor {
|
||||
if (this == '') return const Color(0xFF000000);
|
||||
String hexColor = replaceAll('#', '');
|
||||
hexColor = hexColor.replaceAll('0x', '');
|
||||
hexColor = hexColor.padLeft(6, '0');
|
||||
hexColor = hexColor.padLeft(8, 'F');
|
||||
final int length = hexColor.length;
|
||||
return Color(int.tryParse('0x${hexColor.substring(length - 8, length)}') ?? 0xFF000000);
|
||||
}
|
||||
|
||||
/// Capitalize the first letter in a string.
|
||||
String get capitalize {
|
||||
return (length > 1) ? this[0].toUpperCase() + substring(1) : toUpperCase();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user