Nipodemos
Committed by GitHub

Merge branch 'master' into master

... ... @@ -4,7 +4,7 @@
[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
[![Gitter](https://badges.gitter.im/flutter_get/community.svg)](https://gitter.im/flutter_get/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Discord Shield](https://discordapp.com/api/guilds/722900883784073290/widget.png?style=shield)](https://discord.com/invite/9Hpt99N)
<a href="https://github.com/Solido/awesome-flutter">
<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
</a>
... ... @@ -40,7 +40,7 @@
[**Slack (English)**](https://communityinviter.com/apps/getxworkspace/getx)
[**Discord (English and Portuguese)**](https://discord.com/invite/9Hpt99N)
[**Discord (English, Spanish and Portuguese)**](https://discord.com/invite/9Hpt99N)
[**Telegram (Portuguese)**](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
... ...
... ... @@ -466,6 +466,19 @@ Get.config(
)
```
Opcjonalnie możesz przekierować wszystkie logi z Get by używać swojej ulubionej paczki i zbierać w niej logi.
```dart
GetMaterialApp(
enableLog: true,
logWriterCallback: localLogWriter,
);
void localLogWriter(String text, {bool isError = false}) {
// tutaj przekaż wiadomosci do ulubionej paczki
// pamiętaj że nawet jeśli "enableLog: false" logi i tak będą wysłane w tym callbacku
// Musisz sprawdzić konfiguracje flag jeśli chcesz przez GetConfig.isLogEnable
}
## Video tłumaczące inne funkcjonalności GetX
... ...
... ... @@ -154,7 +154,7 @@ packages:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "2.1.4"
csslib:
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:
... ...

26.7 KB | W: | H:

115 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
import 'package:get/instance_manager.dart';
import 'dart:developer' as developer;
typedef LogWriterCallback = void Function(String text, {bool isError});
void defaultLogWriterCallback(String value, {bool isError = false}) {
if (isError || GetConfig.isLogEnable) print(value);
if (isError || GetConfig.isLogEnable) developer.log(value, name: 'GETX');
}
... ...
import 'package:flutter/cupertino.dart';
import 'package:get/src/core/log.dart';
import 'package:get/src/navigation/root/smart_management.dart';
import 'package:get/src/state_manager/rx/rx_interface.dart';
... ... @@ -154,7 +155,7 @@ class GetInstance {
final i = _singl[key].getDependency();
if (i is DisposableInterface) {
i.onStart();
GetConfig.log('[GETX] $key has been initialized');
GetConfig.log('$key has been initialized');
}
}
... ... @@ -202,7 +203,7 @@ class GetInstance {
if (!_factory.containsKey(key))
throw "$S not found. You need call put<$S>($S()) before";
GetConfig.log('[GETX] $S instance was created at that time');
GetConfig.log('$S instance was created at that time');
S _value = put<S>(_factory[key].builder() as S);
_initDependencies<S>(name: tag);
... ... @@ -248,15 +249,15 @@ class GetInstance {
return queue.add<bool>(() async {
if (!_singl.containsKey(newKey)) {
GetConfig.log('[GETX] Instance "$newKey" already removed.',
isError: true);
GetConfig.log('Instance $newKey already been removed.', isError: true);
return false;
}
FcBuilder builder = _singl[newKey] as FcBuilder;
if (builder.permanent && !force) {
GetConfig.log(
'[GETX] "$newKey" has been marked as permanent, SmartManagement is not authorized to delete it.',
'[$newKey] has been marked as permanent, SmartManagement is not authorized to delete it.',
isError: true);
return false;
}
... ... @@ -267,14 +268,14 @@ class GetInstance {
}
if (i is DisposableInterface) {
await i.onClose();
GetConfig.log('[GETX] "$newKey" onClose() called');
GetConfig.log('onClose of $newKey called');
}
_singl.removeWhere((oldKey, value) => (oldKey == newKey));
if (_singl.containsKey(newKey)) {
GetConfig.log('[GETX] error removing object "$newKey"', isError: true);
GetConfig.log('error on remove object $newKey', isError: true);
} else {
GetConfig.log('[GETX] "$newKey" deleted from memory');
GetConfig.log('$newKey deleted from memory');
}
// _routesKey?.remove(key);
return true;
... ...
... ... @@ -72,13 +72,13 @@ class GetObserver extends NavigatorObserver {
String routeName = name(route);
if (isSnackbar) {
GetConfig.log("[GETX] OPEN SNACKBAR $routeName");
GetConfig.log("OPEN SNACKBAR $routeName");
} else if (isBottomSheet) {
GetConfig.log("[GETX] OPEN $routeName");
GetConfig.log("OPEN $routeName");
} else if (isDialog) {
GetConfig.log("[GETX] OPEN $routeName");
GetConfig.log("OPEN $routeName");
} else if (isGetPageRoute) {
GetConfig.log("[GETX] GOING TO ROUTE $routeName");
GetConfig.log("GOING TO ROUTE $routeName");
}
GetConfig.currentRoute = routeName;
... ... @@ -107,13 +107,13 @@ class GetObserver extends NavigatorObserver {
String routeName = name(route);
if (isSnackbar) {
GetConfig.log("[GETX] CLOSE SNACKBAR $routeName");
GetConfig.log("CLOSE SNACKBAR $routeName");
} else if (isBottomSheet) {
GetConfig.log("[GETX] CLOSE $routeName");
GetConfig.log("CLOSE $routeName");
} else if (isDialog) {
GetConfig.log("[GETX] CLOSE $routeName");
GetConfig.log("CLOSE $routeName");
} else if (isGetPageRoute) {
GetConfig.log("[GETX] CLOSE TO ROUTE $routeName");
GetConfig.log("CLOSE TO ROUTE $routeName");
}
GetConfig.currentRoute = routeName;
... ... @@ -136,8 +136,8 @@ class GetObserver extends NavigatorObserver {
void didReplace({Route newRoute, Route oldRoute}) {
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
GetConfig.log("[GETX] REPLACE ROUTE ${oldRoute?.settings?.name}");
GetConfig.log("[GETX] NEW ROUTE ${newRoute?.settings?.name}");
GetConfig.log("REPLACE ROUTE ${oldRoute?.settings?.name}");
GetConfig.log("NEW ROUTE ${newRoute?.settings?.name}");
GetConfig.currentRoute = name(newRoute);
... ... @@ -158,7 +158,7 @@ class GetObserver extends NavigatorObserver {
@override
void didRemove(Route route, Route previousRoute) {
super.didRemove(route, previousRoute);
GetConfig.log("[GETX] REMOVING ROUTE ${route?.settings?.name}");
GetConfig.log("REMOVING ROUTE ${route?.settings?.name}");
_routeSend.update((value) {
value.route = previousRoute;
... ...
... ... @@ -100,7 +100,7 @@ class Worker {
final String type;
void _message() {
GetConfig.log('[Getx] Worker $type disposed');
GetConfig.log('Worker $type disposed');
}
void dispose() {
... ...
import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:get/src/state_manager/rx/rx_interface.dart';
import 'rx_impl.dart';
Widget obx(Widget Function() builder) {
final b = builder;
return Obxx(b);
}
/// it's very very very very experimental
class Obxx extends StatelessWidget {
final Widget Function() builder;
Obxx(this.builder, {Key key}) : super(key: key);
final RxInterface _observer = Rx();
@override
Widget build(_) {
_observer.subject.stream.listen((data) => (_ as Element)..markNeedsBuild());
final observer = getObs;
getObs = _observer;
final result = builder();
getObs = observer;
return result;
}
}
/// The simplest reactive widget in GetX.
///
... ... @@ -96,7 +74,7 @@ class _ObxState extends State<Obx> {
/// false.obs,
/// ),
// TODO: change T to a proper Rx interfase, that includes the accessor for ::value
// TODO: change T to a proper Rx interface, that includes the accessor for ::value
class ObxValue<T extends RxInterface> extends StatefulWidget {
final Widget Function(T) builder;
final T data;
... ...
... ... @@ -36,6 +36,6 @@ class MixinBuilder<T extends GetxController> extends StatelessWidget {
id: id,
didChangeDependencies: didChangeDependencies,
didUpdateWidget: didUpdateWidget,
builder: (controller) => obx(() => builder.call(controller)));
builder: (controller) => Obx(() => builder.call(controller)));
}
}
... ...
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.isWord(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 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);
}
... ...
import 'package:get/src/utils/regex/regex.dart';
class GetUtils {
/// Checks if data is null.
static bool isNull(dynamic s) => s == null;
... ... @@ -27,13 +25,11 @@ class GetUtils {
}
/// Checks if string consist only numeric.
/// Numeric only doesnt accepting "." which double data type have
static bool isNumericOnly(String s) =>
RegexValidation.hasMatch(s, regex.numericOnly);
/// Numeric only doesn't accepting "." which double data type have
static bool isNumericOnly(String s) => hasMatch(s, r'^\d+$');
/// Checks if string consist only Alphabet. (No Whitespace)
static bool isAlphabetOnly(String s) =>
RegexValidation.hasMatch(s, regex.alphabetOnly);
static bool isAlphabetOnly(String s) => hasMatch(s, r'^[a-zA-Z]+$');
/// Checks if string is boolean.
static bool isBool(String s) {
... ... @@ -41,81 +37,133 @@ class GetUtils {
return (s == 'true' || s == 'false');
}
/// Checks if string is an vector file.
static bool isVector(String s) => RegexValidation.hasMatch(s, regex.vector);
/// Checks if string is an video file.
static bool isVideo(String filePath) {
String ext = filePath.toLowerCase();
return (((((ext.endsWith(".mp4") || ext.endsWith(".avi")) ||
ext.endsWith(".wmv")) ||
ext.endsWith(".rmvb")) ||
ext.endsWith(".mpg")) ||
ext.endsWith(".mpeg")) ||
ext.endsWith(".3gp");
}
/// Checks if string is an image file.
static bool isImage(String s) => RegexValidation.hasMatch(s, regex.image);
static bool isImage(String filePath) {
String ext = filePath.toLowerCase();
return (((ext.endsWith(".jpg") || ext.endsWith(".jpeg")) ||
ext.endsWith(".png")) ||
ext.endsWith(".gif")) ||
ext.endsWith(".bmp");
}
/// Checks if string is an audio file.
static bool isAudio(String s) => RegexValidation.hasMatch(s, regex.audio);
static bool isAudio(String filePath) {
String ext = filePath.toLowerCase();
return (((ext.endsWith(".mp3") || ext.endsWith(".wav")) ||
ext.endsWith(".wma")) ||
ext.endsWith(".amr")) ||
ext.endsWith(".ogg");
}
/// Checks if string is an video file.
static bool isVideo(String s) => RegexValidation.hasMatch(s, regex.video);
/// Checks if string is an powerpoint file.
static bool isPPT(String filePath) {
String ext = filePath.toLowerCase();
return ext.endsWith(".ppt") || ext.endsWith(".pptx");
}
/// Checks if string is an txt file.
static bool isTxt(String s) => RegexValidation.hasMatch(s, regex.txt);
/// Checks if string is an word file.
static bool isWord(String filePath) {
String ext = filePath.toLowerCase();
return ext.endsWith(".doc") || ext.endsWith(".docx");
}
/// Checks if string is an Doc file.
static bool isDocument(String s) => RegexValidation.hasMatch(s, regex.doc);
/// Checks if string is an excel file.
static bool isExcel(String filePath) {
String ext = filePath.toLowerCase();
return ext.endsWith(".xls") || ext.endsWith(".xlsx");
}
/// Checks if string is an Excel file.
static bool isExcel(String s) => RegexValidation.hasMatch(s, regex.excel);
/// Checks if string is an apk file.
static bool isAPK(String filePath) {
return filePath.toLowerCase().endsWith(".apk");
}
/// Checks if string is an PPT file.
static bool isPPT(String s) => RegexValidation.hasMatch(s, regex.ppt);
/// Checks if string is an pdf file.
static bool isPDF(String filePath) {
return filePath.toLowerCase().endsWith(".pdf");
}
/// Checks if string is an APK file.
static bool isAPK(String s) => RegexValidation.hasMatch(s, regex.apk);
/// Checks if string is an txt file.
static bool isTxt(String filePath) {
return filePath.toLowerCase().endsWith(".txt");
}
/// Checks if string is an video file.
static bool isPDF(String s) => RegexValidation.hasMatch(s, regex.pdf);
/// Checks if string is an chm file.
static bool isChm(String filePath) {
return filePath.toLowerCase().endsWith(".chm");
}
/// Checks if string is an HTML file.
static bool isHTML(String s) => RegexValidation.hasMatch(s, regex.html);
/// Checks if string is a vector file.
static bool isVector(String filePath) {
return filePath.toLowerCase().endsWith(".svg");
}
/// Checks if string is an html file.
static bool isHTML(String filePath) {
return filePath.toLowerCase().endsWith(".html");
}
/// Checks if string is a valid username.
static bool isUsername(String s) =>
hasMatch(s, r'^[a-zA-Z0-9][a-zA-Z0-9_.]+[a-zA-Z0-9]$');
/// Checks if string is URL.
static bool isURL(String s) => RegexValidation.hasMatch(s, regex.url);
static bool isURL(String s) => hasMatch(s,
r"^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;%\$#\=~_\-]+))*$");
/// Checks if string is email.
static bool isEmail(String s) => RegexValidation.hasMatch(s, regex.email);
static bool isEmail(String s) => hasMatch(s,
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$');
/// Checks if string is phone number.
static bool isPhoneNumber(String s) =>
RegexValidation.hasMatch(s, regex.phone);
static bool isPhoneNumber(String s) => hasMatch(s,
r'^(0|\+|(\+[0-9]{2,4}|\(\+?[0-9]{2,4}\)) ?)([0-9]*|\d{2,4}-\d{2,4}(-\d{2,4})?)$');
/// Checks if string is DateTime (UTC or Iso8601).
static bool isDateTime(String s) =>
RegexValidation.hasMatch(s, regex.basicDateTime);
hasMatch(s, r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}.\d{3}Z?$');
/// Checks if string is MD5 hash.
static bool isMD5(String s) => RegexValidation.hasMatch(s, regex.md5);
static bool isMD5(String s) => hasMatch(s, r'^[a-f0-9]{32}$');
/// Checks if string is SHA1 hash.
static bool isSHA1(String s) => RegexValidation.hasMatch(s, regex.sha1);
static bool isSHA1(String s) =>
hasMatch(s, r'(([A-Fa-f0-9]{2}\:){19}[A-Fa-f0-9]{2}|[A-Fa-f0-9]{40})');
/// Checks if string is SHA256 hash.
static bool isSHA256(String s) => RegexValidation.hasMatch(s, regex.sha256);
/// Checks if string is ISBN 10 or 13.
static bool isISBN(String s) => RegexValidation.hasMatch(s, regex.isbn);
static bool isSHA256(String s) =>
hasMatch(s, r'([A-Fa-f0-9]{2}\:){31}[A-Fa-f0-9]{2}|[A-Fa-f0-9]{64}');
/// Checks if string is SSN (Social Security Number).
static bool isSSN(String s) => RegexValidation.hasMatch(s, regex.ssn);
static bool isSSN(String s) => hasMatch(s,
r'^(?!0{3}|6{3}|9[0-9]{2})[0-9]{3}-?(?!0{2})[0-9]{2}-?(?!0{4})[0-9]{4}$');
/// Checks if string is binary.
static bool isBinary(String s) => RegexValidation.hasMatch(s, regex.binary);
static bool isBinary(String s) => hasMatch(s, r'^[0-1]*$');
/// Checks if string is IPv4.
static bool isIPv4(String s) => RegexValidation.hasMatch(s, regex.ipv4);
static bool isIPv4(String s) =>
hasMatch(s, r'^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$');
/// Checks if string is IPv6.
static bool isIPv6(String s) => RegexValidation.hasMatch(s, regex.ipv6);
static bool isIPv6(String s) => hasMatch(s,
r'^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$');
/// Checks if string is hexadecimal.
/// Example: HexColor => #12F
static bool isHexadecimal(String s) =>
RegexValidation.hasMatch(s, regex.hexadecimal);
hasMatch(s, r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$');
/// Checks if string is Palindrom.
static bool isPalindrom(String s) {
... ... @@ -151,11 +199,11 @@ class GetUtils {
/// Checks if string is Passport No.
static bool isPassport(String s) =>
RegexValidation.hasMatch(s, regex.passport);
hasMatch(s, r'^(?!^0+$)[a-zA-Z0-9]{6,9}$');
/// Checks if string is Currency.
static bool isCurrency(String s) =>
RegexValidation.hasMatch(s, regex.currency);
static bool isCurrency(String s) => hasMatch(s,
r'^(S?\$|\₩|Rp|\¥|\€|\₹|\₽|fr|R$|R)?[ ]?[-]?([0-9]{1,3}[,.]([0-9]{3}[,.])*[0-9]{3}|[0-9]+)([,.][0-9]{1,2})?( ?(USD?|AUD|NZD|CAD|CHF|GBP|CNY|EUR|JPY|IDR|MXN|NOK|KRW|TRY|INR|RUB|BRL|ZAR|SGD|MYR))?$');
/// Checks if length of data is LOWER than maxLength.
static bool isLengthLowerThan(dynamic s, int maxLength) {
... ... @@ -425,11 +473,6 @@ class GetUtils {
return numericOnlyStr;
}
static Regex regex = Regex();
}
class RegexValidation {
/// Returns whether the pattern has a match in the string [input].
static bool hasMatch(String s, Pattern p) =>
(s == null) ? false : RegExp(p).hasMatch(s);
}
... ...
... ... @@ -10,7 +10,7 @@ extension GetStringUtils on String {
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 isDocumentFileName => GetUtils.isWord(this);
bool get isExcelFileName => GetUtils.isExcel(this);
bool get isPPTFileName => GetUtils.isPPT(this);
bool get isAPKFileName => GetUtils.isAPK(this);
... ... @@ -23,7 +23,6 @@ extension GetStringUtils on String {
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);
... ... @@ -53,22 +52,6 @@ extension GetNumUtils on num {
}
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);
}
... ...
class Regex {
/// Username regex
Pattern username = r'^[a-zA-Z0-9][a-zA-Z0-9_.]+[a-zA-Z0-9]$';
/// Email regex
Pattern email =
r'^[a-z0-9]+([-+._][a-z0-9]+){0,2}@.*?(\.(a(?:[cdefgilmnoqrstuwxz]|ero|(?:rp|si)a)|b(?:[abdefghijmnorstvwyz]iz)|c(?:[acdfghiklmnoruvxyz]|at|o(?:m|op))|d[ejkmoz]|e(?:[ceghrstu]|du)|f[ijkmor]|g(?:[abdefghilmnpqrstuwy]|ov)|h[kmnrtu]|i(?:[delmnoqrst]|n(?:fo|t))|j(?:[emop]|obs)|k[eghimnprwyz]|l[abcikrstuvy]|m(?:[acdeghklmnopqrstuvwxyz]|il|obi|useum)|n(?:[acefgilopruz]|ame|et)|o(?:m|rg)|p(?:[aefghklmnrstwy]|ro)|qa|r[eosuw]|s[abcdeghijklmnortuvyz]|t(?:[cdfghjklmnoprtvwz]|(?:rav)?el)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])\b){1,2}$';
/// URL regex
Pattern url =
r"^((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\://)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&amp;%\$#\=~_\-]+))*$";
/// Phone Number regex
/// Must started by either, "0", "+", "+XX <X between 2 to 4 digit>", "(+XX <X between 2 to 3 digit>)"
/// Can add whitespace separating digit with "+" or "(+XX)"
/// Example: 05555555555, +555 5555555555, (+123) 5555555555, (555) 5555555555, +5555 5555555555
Pattern phone =
r'^(0|\+|(\+[0-9]{2,4}|\(\+?[0-9]{2,4}\)) ?)([0-9]*|\d{2,4}-\d{2,4}(-\d{2,4})?)$';
/// Hexadecimal regex
Pattern hexadecimal = r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$';
/// Image vector regex
Pattern vector = r'.(svg)$';
/// Image regex
Pattern image = r'.(jpeg|jpg|gif|png|bmp)$';
/// Audio regex
Pattern audio = r'.(mp3|wav|wma|amr|ogg)$';
/// Video regex
Pattern video = r'.(mp4|avi|wmv|rmvb|mpg|mpeg|3gp)$';
/// Txt regex
Pattern txt = r'.txt$';
/// Document regex
Pattern doc = r'.(doc|docx)$';
/// Excel regex
Pattern excel = r'.(xls|xlsx)$';
/// PPT regex
Pattern ppt = r'.(ppt|pptx)$';
/// Document regex
Pattern apk = r'.apk$';
/// PDF regex
Pattern pdf = r'.pdf$';
/// HTML regex
Pattern html = r'.html$';
/// DateTime regex (UTC)
/// Unformatted date time (UTC and Iso8601)
/// Example: 2020-04-27 08:14:39.977, 2020-04-27T08:14:39.977, 2020-04-27 01:14:39.977Z
Pattern basicDateTime = r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}.\d{3}Z?$';
/// Binary regex
/// Consist only 0 & 1
Pattern binary = r'^[0-1]*$';
/// MD5 regex
Pattern md5 = r'^[a-f0-9]{32}$';
/// SHA1 regex
Pattern sha1 = r'(([A-Fa-f0-9]{2}\:){19}[A-Fa-f0-9]{2}|[A-Fa-f0-9]{40})';
/// SHA256 regex
Pattern sha256 = r'([A-Fa-f0-9]{2}\:){31}[A-Fa-f0-9]{2}|[A-Fa-f0-9]{64}';
/// SSN (Social Security Number) regex
Pattern ssn =
r'^(?!0{3}|6{3}|9[0-9]{2})[0-9]{3}-?(?!0{2})[0-9]{2}-?(?!0{4})[0-9]{4}$';
/// IPv4 regex
Pattern ipv4 = r'^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$';
/// IPv6 regex
Pattern ipv6 =
r'^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$';
/// ISBN 10 & 13 regex
Pattern isbn =
r'(ISBN(\-1[03])?[:]?[ ]?)?(([0-9Xx][- ]?){13}|([0-9Xx][- ]?){10})';
/// Passport No. regex
Pattern passport = r'^(?!^0+$)[a-zA-Z0-9]{6,9}$';
/// Currency regex
Pattern currency =
r'^(S?\$|\₩|Rp|\¥|\€|\₹|\₽|fr|R$|R)?[ ]?[-]?([0-9]{1,3}[,.]([0-9]{3}[,.])*[0-9]{3}|[0-9]+)([,.][0-9]{1,2})?( ?(USD?|AUD|NZD|CAD|CHF|GBP|CNY|EUR|JPY|IDR|MXN|NOK|KRW|TRY|INR|RUB|BRL|ZAR|SGD|MYR))?$';
/// Numeric Only regex (No Whitespace & Symbols)
Pattern numericOnly = r'^\d+$';
/// Alphabet Only regex (No Whitespace & Symbols)
Pattern alphabetOnly = r'^[a-zA-Z]+$';
/// Password (Easy) Regex
/// Allowing all character except 'whitespace'
/// Minimum character: 8
Pattern passwordEasy = r'^\S{8,}$';
/// Password (Easy) Regex
/// Allowing all character
/// Minimum character: 8
Pattern passwordEasyAllowedWhitespace = r'^[\S ]{8,}$';
/// Password (Normal) Regex
/// Allowing all character except 'whitespace'
/// Must contains at least: 1 letter & 1 number
/// Minimum character: 8
Pattern passwordNormal1 = r'^(?=.*[A-Za-z])(?=.*\d)\S{8,}$';
/// Password (Normal) Regex
/// Allowing all character
/// Must contains at least: 1 letter & 1 number
/// Minimum character: 8
Pattern passwordNormal1AllowedWhitespace =
r'^(?=.*[A-Za-z])(?=.*\d)[\S ]{8,}$';
/// Password (Normal) Regex
/// Allowing LETTER and NUMBER only
/// Must contains at least: 1 letter & 1 number
/// Minimum character: 8
Pattern passwordNormal2 = r'^(?=.*[A-Za-z])(?=.*\d)[a-zA-Z0-9]{8,}$';
/// Password (Normal) Regex
/// Allowing LETTER and NUMBER only
/// Must contains: 1 letter & 1 number
/// Minimum character: 8
Pattern passwordNormal2AllowedWhitespace =
r'^(?=.*[A-Za-z])(?=.*\d)[a-zA-Z0-9 ]{8,}$';
/// Password (Normal) Regex
/// Allowing all character except 'whitespace'
/// Must contains at least: 1 uppercase letter, 1 lowecase letter & 1 number
/// Minimum character: 8
Pattern passwordNormal3 = r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)\S{8,}$';
/// Password (Normal) Regex
/// Allowing all character
/// Must contains at least: 1 uppercase letter, 1 lowecase letter & 1 number
/// Minimum character: 8
Pattern passwordNormal3AllowedWhitespace =
r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\S ]{8,}$';
/// Password (Hard) Regex
/// Allowing all character except 'whitespace'
/// Must contains at least: 1 uppercase letter, 1 lowecase letter, 1 number, & 1 special character (symbol)
/// Minimum character: 8
Pattern passwordHard = r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])\S{8,}$';
/// Password (Hard) Regex
/// Allowing all character
/// Must contains at least: 1 uppercase letter, 1 lowecase letter, 1 number, & 1 special character (symbol)
/// Minimum character: 8
Pattern passwordHardAllowedWhitespace =
r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])[\S ]{8,}$';
}
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';
... ...
... ... @@ -33,7 +33,7 @@ void main() {
child: Text("increment"),
onPressed: () => controller.increment(),
),
obx(() => Text(
Obx(() => Text(
'Obx: ${controller.map.value.length}',
))
]),
... ...
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);
});
});
}
... ...