Nipodemos
Committed by GitHub

Merge pull request #393 from WilliamCunhaCardoso/issue-389

Update extension structure
... ... @@ -15,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.39.10"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
... ... @@ -154,7 +161,7 @@ packages:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "2.1.4"
csslib:
dependency: transitive
description:
... ... @@ -270,6 +277,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
io:
dependency: transitive
description:
... ... @@ -375,6 +389,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
pool:
dependency: transitive
description:
... ... @@ -541,6 +562,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
yaml:
dependency: transitive
description:
... ...
... ... @@ -73,7 +73,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.4.6"
version: "3.5.1"
http_parser:
dependency: transitive
description:
... ...
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
extension ContextExtensionss on BuildContext {
/// The same of [MediaQuery.of(context).size]
Size get mediaQuerySize => MediaQuery.of(this).size;
/// The same of [MediaQuery.of(context).size.height]
/// Note: updates when you rezise your screen (like on a browser or desktop window)
double get height => mediaQuerySize.height;
/// The same of [MediaQuery.of(context).size.width]
/// Note: updates when you rezise your screen (like on a browser or desktop window)
double get width => mediaQuerySize.width;
/// Gives you the power to get a portion of the height.
/// Useful for responsive applications.
///
/// [dividedBy] is for when you want to have a portion of the value you would get
/// like for example: if you want a value that represents a third of the screen
/// you can set it to 3, and you will get a third of the height
///
/// [reducedBy] is a percentage value of how much of the height you want
/// if you for example want 46% of the height, then you reduce it by 56%.
double heightTransformer({double dividedBy = 1, double reducedBy = 0.0}) {
return (mediaQuerySize.height -
((mediaQuerySize.height / 100) * reducedBy)) /
dividedBy;
}
/// Gives you the power to get a portion of the width.
/// Useful for responsive applications.
///
/// [dividedBy] is for when you want to have a portion of the value you would get
/// like for example: if you want a value that represents a third of the screen
/// you can set it to 3, and you will get a third of the width
///
/// [reducedBy] is a percentage value of how much of the width you want
/// if you for example want 46% of the width, then you reduce it by 56%.
double widthTransformer({double dividedBy = 1, double reducedBy = 0.0}) {
return (mediaQuerySize.width - ((mediaQuerySize.width / 100) * reducedBy)) /
dividedBy;
}
/// Divide the height proportionally by the given value
double ratio({
double dividedBy = 1,
double reducedByW = 0.0,
double reducedByH = 0.0,
}) {
return heightTransformer(dividedBy: dividedBy, reducedBy: reducedByH) /
widthTransformer(dividedBy: dividedBy, reducedBy: reducedByW);
}
/// similar to [MediaQuery.of(context).padding]
ThemeData get theme => Theme.of(this);
/// similar to [MediaQuery.of(context).padding]
TextTheme get textTheme => Theme.of(this).textTheme;
/// similar to [MediaQuery.of(context).padding]
EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding;
/// similar to [MediaQuery.of(context).padding]
MediaQueryData get mediaQuery => MediaQuery.of(this);
/// similar to [MediaQuery.of(context).viewPadding]
EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding;
/// similar to [MediaQuery.of(context).viewInsets]
EdgeInsets get mediaQueryViewInsets => MediaQuery.of(this).viewInsets;
/// similar to [MediaQuery.of(context).orientation]
Orientation get orientation => MediaQuery.of(this).orientation;
/// check if device is on landscape mode
bool get isLandscape => orientation == Orientation.landscape;
/// check if device is on portrait mode
bool get isPortrait => orientation == Orientation.portrait;
/// similar to [MediaQuery.of(this).devicePixelRatio]
double get devicePixelRatio => MediaQuery.of(this).devicePixelRatio;
/// similar to [MediaQuery.of(this).textScaleFactor]
double get textScaleFactor => MediaQuery.of(this).textScaleFactor;
/// get the shortestSide from screen
double get mediaQueryShortestSide => mediaQuerySize.shortestSide;
/// True if width be larger than 800
bool get showNavbar => (width > 800);
/// True if the shortestSide is smaller than 600p
bool get isPhone => (mediaQueryShortestSide < 600);
/// True if the shortestSide is largest than 600p
bool get isSmallTablet => (mediaQueryShortestSide >= 600);
/// True if the shortestSide is largest than 720p
bool get isLargeTablet => (mediaQueryShortestSide >= 720);
/// True if the current device is Tablet
bool get isTablet => isSmallTablet || isLargeTablet;
/// Returns a specific value according to the screen size
/// if the device width is higher than or equal to 1200 return [desktop] value.
/// if the device width is higher than or equal to 600 and less than 1200
/// return [tablet] value.
/// if the device width is less than 300 return [watch] value.
/// in other cases return [mobile] value.
T responsiveValue<T>({
T mobile,
T tablet,
T desktop,
T watch,
}) {
double deviceWidth = mediaQuerySize.shortestSide;
if (kIsWeb) {
deviceWidth = mediaQuerySize.width;
}
if (deviceWidth >= 1200 && desktop != null) return desktop;
if (deviceWidth >= 600 && tablet != null) return tablet;
if (deviceWidth < 300 && watch != null) return watch;
return mobile;
}
}
... ...
import 'dart:math';
extension Precision on double {
double toPrecision(int fractionDigits) {
double mod = pow(10, fractionDigits.toDouble());
return ((this * mod).round().toDouble() / mod);
}
}
... ...
import '../regex/get_utils.dart';
extension GetDynamicUtils on dynamic {
/// It's This is overloading the IDE's options. Only the most useful and popular options will stay here.
bool get isNull => GetUtils.isNull(this);
bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
// bool get isOneAKind => GetUtils.isOneAKind(this);
// bool isLengthLowerThan(int maxLength) =>
// GetUtils.isLengthLowerThan(this, maxLength);
// bool isLengthGreaterThan(int maxLength) =>
// GetUtils.isLengthGreaterThan(this, maxLength);
// bool isLengthGreaterOrEqual(int maxLength) =>
// GetUtils.isLengthGreaterOrEqual(this, maxLength);
// bool isLengthLowerOrEqual(int maxLength) =>
// GetUtils.isLengthLowerOrEqual(this, maxLength);
// bool isLengthEqualTo(int maxLength) =>
// GetUtils.isLengthEqualTo(this, maxLength);
// bool isLengthBetween(int minLength, int maxLength) =>
// GetUtils.isLengthBetween(this, minLength, maxLength);
}
... ...
export 'context_extensions.dart';
export 'double_extensions.dart';
export 'dynamic_extensions.dart';
export 'num_extensions.dart';
export 'string_extensions.dart';
export 'widget_extensions.dart';
... ...
import '../regex/get_utils.dart';
extension GetNumUtils on num {
bool isLowerThan(num b) => GetUtils.isLowerThan(this, b);
bool isGreaterThan(num b) => GetUtils.isGreaterThan(this, b);
bool isEqual(num b) => GetUtils.isEqual(this, b);
}
... ...
import '../regex/get_utils.dart';
extension GetStringUtils on String {
bool get isNum => GetUtils.isNum(this);
bool get isNumericOnly => GetUtils.isNumericOnly(this);
bool get isAlphabetOnly => GetUtils.isAlphabetOnly(this);
bool get isBool => GetUtils.isBool(this);
bool get isVectorFileName => GetUtils.isVector(this);
bool get isImageFileName => GetUtils.isImage(this);
bool get isAudioFileName => GetUtils.isAudio(this);
bool get isVideoFileName => GetUtils.isVideo(this);
bool get isTxtFileName => GetUtils.isTxt(this);
bool get isDocumentFileName => GetUtils.isDocument(this);
bool get isExcelFileName => GetUtils.isExcel(this);
bool get isPPTFileName => GetUtils.isPPT(this);
bool get isAPKFileName => GetUtils.isAPK(this);
bool get isPDFFileName => GetUtils.isPDF(this);
bool get isHTMLFileName => GetUtils.isHTML(this);
bool get isURL => GetUtils.isURL(this);
bool get isEmail => GetUtils.isEmail(this);
bool get isPhoneNumber => GetUtils.isPhoneNumber(this);
bool get isDateTime => GetUtils.isDateTime(this);
bool get isMD5 => GetUtils.isMD5(this);
bool get isSHA1 => GetUtils.isSHA1(this);
bool get isSHA256 => GetUtils.isSHA256(this);
bool get isISBN => GetUtils.isISBN(this);
bool get isBinary => GetUtils.isBinary(this);
bool get isIPv4 => GetUtils.isIPv4(this);
bool get isIPv6 => GetUtils.isIPv6(this);
bool get isHexadecimal => GetUtils.isHexadecimal(this);
bool get isPalindrom => GetUtils.isPalindrom(this);
bool get isPassport => GetUtils.isPassport(this);
bool get isCurrency => GetUtils.isCurrency(this);
bool isCpf(String s) => GetUtils.isCpf(this);
bool isCnpj(String s) => GetUtils.isCnpj(this);
bool isCaseInsensitiveContains(String b) =>
GetUtils.isCaseInsensitiveContains(this, b);
bool isCaseInsensitiveContainsAny(String b) =>
GetUtils.isCaseInsensitiveContainsAny(this, b);
String capitalize(String s, {bool firstOnly = false}) =>
GetUtils.capitalize(this, firstOnly: firstOnly);
String capitalizeFirst(String s) => GetUtils.capitalizeFirst(this);
String removeAllWhitespace(String s) => GetUtils.removeAllWhitespace(this);
String camelCase(String s) => GetUtils.camelCase(this);
String numericOnly(String s, {bool firstWordOnly = false}) =>
GetUtils.numericOnly(this, firstWordOnly: firstWordOnly);
}
... ...
import 'package:flutter/widgets.dart';
extension WidgetPaddingX on Widget {
Widget paddingAll(double padding) =>
Padding(padding: EdgeInsets.all(padding), child: this);
Widget paddingSymmetric({double horizontal = 0.0, double vertical = 0.0}) =>
Padding(
padding:
EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
child: this);
Widget paddingOnly({
double left = 0.0,
double top = 0.0,
double right = 0.0,
double bottom = 0.0,
}) =>
Padding(
padding: EdgeInsets.only(
top: top, left: left, right: right, bottom: bottom),
child: this);
Widget get paddingZero => Padding(padding: EdgeInsets.zero, child: this);
}
extension WidgetMarginX on Widget {
Widget marginAll(double margin) =>
Container(margin: EdgeInsets.all(margin), child: this);
Widget marginSymmetric({double horizontal = 0.0, double vertical = 0.0}) =>
Container(
margin:
EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
child: this);
Widget marginOnly({
double left = 0.0,
double top = 0.0,
double right = 0.0,
double bottom = 0.0,
}) =>
Container(
margin: EdgeInsets.only(
top: top, left: left, right: right, bottom: bottom),
child: this);
Widget get marginZero => Container(margin: EdgeInsets.zero, child: this);
}
... ...
... ... @@ -27,7 +27,7 @@ class GetUtils {
}
/// Checks if string consist only numeric.
/// Numeric only doesnt accepting "." which double data type have
/// Numeric only doesn't accepting "." which double data type have
static bool isNumericOnly(String s) =>
RegexValidation.hasMatch(s, regex.numericOnly);
... ...
export 'src/utils/context_extensions/extensions.dart';
export 'src/utils/extensions/export.dart';
export 'src/utils/queue/get_queue.dart';
export 'src/utils/platform/platform.dart';
export 'src/utils/regex/get_utils.dart';
export 'src/utils/regex/get_utils_extensions.dart';
... ...
import 'package:flutter_test/flutter_test.dart';
void main() {
test('', () {});
}
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
void main() {
test('Test for toPrecision on Double', () {
double testVar = 5.4545454;
expect(testVar.toPrecision(2), equals(5.45));
});
}
... ...
import 'package:flutter_test/flutter_test.dart';
void main() {
test('', () {});
}
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
void main() {
num x = 5;
num y = 7;
test('Test for var.isLowerThan(value)', () {
expect(x.isLowerThan(y), true);
expect(y.isLowerThan(x), false);
});
test('Test for var.isGreaterThan(value)', () {
expect(x.isGreaterThan(y), false);
expect(y.isGreaterThan(x), true);
});
test('Test for var.isGreaterThan(value)', () {
expect(x.isEqual(y), false);
expect(y.isEqual(x), false);
expect(x.isEqual(5), true);
expect(y.isEqual(7), true);
});
}
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
void main() {
group('Test group for extension: isNullOrBlank', () {
String testString;
test('String extension: isNullOrBlank', () {
expect(testString.isNullOrBlank, equals(true));
});
test('String extension: isNullOrBlank', () {
testString = 'Not null anymore';
expect(testString.isNullOrBlank, equals(false));
});
test('String extension: isNullOrBlank', () {
testString = '';
expect(testString.isNullOrBlank, equals(true));
});
});
}
... ...
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
void main() {
group('Group test for PaddingX Extension', () {
testWidgets('Test of paddingAll', (WidgetTester tester) async {
Widget containerTest;
expect(find.byType(Padding), findsNothing);
await tester.pumpWidget(containerTest.paddingAll(16));
expect(find.byType(Padding), findsOneWidget);
});
testWidgets('Test of paddingOnly', (WidgetTester tester) async {
Widget containerTest;
expect(find.byType(Padding), findsNothing);
await tester.pumpWidget(containerTest.paddingOnly(top: 16));
expect(find.byType(Padding), findsOneWidget);
});
testWidgets('Test of paddingSymmetric', (WidgetTester tester) async {
Widget containerTest;
expect(find.byType(Padding), findsNothing);
await tester.pumpWidget(containerTest.paddingSymmetric(vertical: 16));
expect(find.byType(Padding), findsOneWidget);
});
testWidgets('Test of paddingZero', (WidgetTester tester) async {
Widget containerTest;
expect(find.byType(Padding), findsNothing);
await tester.pumpWidget(containerTest.paddingZero);
expect(find.byType(Padding), findsOneWidget);
});
});
group('Group test for MarginX Extension', () {
testWidgets('Test of marginAll', (WidgetTester tester) async {
Widget containerTest;
await tester.pumpWidget(containerTest.marginAll(16));
expect(find.byType(Container), findsOneWidget);
});
testWidgets('Test of marginOnly', (WidgetTester tester) async {
Widget containerTest;
await tester.pumpWidget(containerTest.marginOnly(top: 16));
expect(find.byType(Container), findsOneWidget);
});
testWidgets('Test of marginSymmetric', (WidgetTester tester) async {
Widget containerTest;
await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16));
expect(find.byType(Container), findsOneWidget);
});
testWidgets('Test of marginZero', (WidgetTester tester) async {
Widget containerTest;
await tester.pumpWidget(containerTest.marginZero);
expect(find.byType(Container), findsOneWidget);
});
});
}
... ...