Jonatas

deprecated isNull extension and improve tests

## [3.23.1]
- Fix allowSelfSigned
## [3.23.1]
- Fix allowSelfSigned on Flutter web
## [3.23.0]
... ...
... ... @@ -113,8 +113,7 @@ class GetHttpClient {
//TODO check this implementation
if (contentType != null) {
if (contentType.toLowerCase() == 'application/x-www-form-urlencoded') {
var paramName = 'param';
jsonString = '$paramName=${Uri.encodeQueryComponent(jsonString)}';
jsonString = Uri.encodeQueryComponent(jsonString);
}
}
} else if (body is String) {
... ...
import '../get_utils/get_utils.dart';
extension GetDynamicUtils on dynamic {
@Deprecated('isNull is deprecated and cannot be used, use "==" operator')
bool get isNull => GetUtils.isNull(this);
bool get isBlank => GetUtils.isBlank(this);
@Deprecated(
'isNullOrBlank is deprecated and cannot be used, use "isBlank" instead')
bool get isNullOrBlank => GetUtils.isNullOrBlank(this);
void printError(
... ...
... ... @@ -5,8 +5,14 @@ import '../../../get_core/get_core.dart';
/// standard dart types that contains it.
///
/// This is here to for the 'DRY'
bool _hasIsEmpty(dynamic value) {
return value is Iterable || value is String || value is Map;
bool _isEmpty(dynamic value) {
if (value is String) {
return value.toString().trim().isEmpty;
}
if (value is Iterable || value is Map) {
return value.isEmpty as bool;
}
return false;
}
/// Returns whether a dynamic value PROBABLY
... ... @@ -70,13 +76,14 @@ class GetUtils {
return true;
}
if (value is String) {
return value.toString().trim().isEmpty;
}
// Pretty sure that isNullOrBlank should't be validating
// iterables... but I'm going to keep this for compatibility.
return _hasIsEmpty(value) ? value.isEmpty as bool : false;
return _isEmpty(value);
}
/// Checks if data is null or blank (empty or only contains whitespace).
static bool isBlank(dynamic value) {
return _isEmpty(value);
}
/// Checks if string is int or double.
... ... @@ -584,3 +591,10 @@ class GetUtils {
Get.log('$prefix $value $info'.trim(), isError: isError);
}
}
typedef PrintFunctionCallback = void Function(
String prefix,
dynamic value,
String info, {
bool isError,
});
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:get/utils.dart';
class TestClass {
final name = "John";
}
class EmptyClass {}
void main() {
group('isNullOrBlank on dynamic', () {
// Identity util to convert to iterables
dynamic _id(dynamic e) => e;
test('null isNullOrBlank should be true for null', () {
expect((null).isNullOrBlank, true);
});
test('isNullOrBlank should be false for unsupported types', () {
expect(5.isNullOrBlank, false);
expect(0.isNullOrBlank, false);
expect(5.0.isNullOrBlank, equals(false));
expect(0.0.isNullOrBlank, equals(false));
TestClass testClass;
expect(testClass.isNullOrBlank, equals(true));
expect(TestClass().isNullOrBlank, equals(false));
expect(EmptyClass().isNullOrBlank, equals(false));
});
test('isNullOrBlank should validate strings', () {
expect("".isNullOrBlank, true);
expect(" ".isNullOrBlank, true);
expect("foo".isNullOrBlank, false);
expect(" foo ".isNullOrBlank, false);
expect("null".isNullOrBlank, false);
});
test('isNullOrBlank should validate iterables', () {
expect([].map(_id).isNullOrBlank, true);
expect([1].map(_id).isNullOrBlank, false);
});
test('isNullOrBlank should validate lists', () {
expect([].isNullOrBlank, true);
expect(['oi', 'foo'].isNullOrBlank, false);
expect([{}, {}].isNullOrBlank, false);
expect(['foo'][0].isNullOrBlank, false);
});
test('isNullOrBlank should validate sets', () {
expect((<dynamic>{}).isNullOrBlank, true);
expect(({1}).isNullOrBlank, false);
expect({'fluorine', 'chlorine', 'bromine'}.isNullOrBlank, false);
});
test('isNullOrBlank should validate maps', () {
expect(({}).isNullOrBlank, true);
expect(({1: 1}).isNullOrBlank, false);
expect({"other": "thing"}.isNullOrBlank, false);
final map = {"foo": 'bar', "one": "um"};
expect(map["foo"].isNullOrBlank, false);
expect(map["other"].isNullOrBlank, true);
});
});
test('String test', () {
var value = 'string';
var expected = '';
... ...
... ... @@ -9,7 +9,7 @@ void main() {
final alphaNumeric = "123asd";
final numbers = "123";
final letters = "foo";
String notInitializedVar;
// String notInitializedVar;
test('var.isNum', () {
expect(digit.isNum, true);
... ... @@ -31,7 +31,7 @@ void main() {
test('var.isBool', () {
final trueString = 'true';
expect(notInitializedVar.isBool, false);
// expect(notInitializedVar.isBool, false);
expect(letters.isBool, false);
expect(trueString.isBool, true);
});
... ...
... ... @@ -5,7 +5,7 @@ import 'package:get/utils.dart';
void main() {
group('Group test for PaddingX Extension', () {
testWidgets('Test of paddingAll', (tester) async {
Widget containerTest;
Widget containerTest = Container();
expect(find.byType(Padding), findsNothing);
... ... @@ -15,7 +15,7 @@ void main() {
});
testWidgets('Test of paddingOnly', (tester) async {
Widget containerTest;
Widget containerTest = Container();
expect(find.byType(Padding), findsNothing);
... ... @@ -25,7 +25,7 @@ void main() {
});
testWidgets('Test of paddingSymmetric', (tester) async {
Widget containerTest;
Widget containerTest = Container();
expect(find.byType(Padding), findsNothing);
... ... @@ -35,7 +35,7 @@ void main() {
});
testWidgets('Test of paddingZero', (tester) async {
Widget containerTest;
Widget containerTest = Container();
expect(find.byType(Padding), findsNothing);
... ... @@ -47,7 +47,7 @@ void main() {
group('Group test for MarginX Extension', () {
testWidgets('Test of marginAll', (tester) async {
Widget containerTest;
Widget containerTest = Container();
await tester.pumpWidget(containerTest.marginAll(16));
... ... @@ -55,7 +55,7 @@ void main() {
});
testWidgets('Test of marginOnly', (tester) async {
Widget containerTest;
Widget containerTest = Container();
await tester.pumpWidget(containerTest.marginOnly(top: 16));
... ... @@ -63,7 +63,7 @@ void main() {
});
testWidgets('Test of marginSymmetric', (tester) async {
Widget containerTest;
Widget containerTest = Container();
await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16));
... ... @@ -71,7 +71,7 @@ void main() {
});
testWidgets('Test of marginZero', (tester) async {
Widget containerTest;
Widget containerTest = Container();
await tester.pumpWidget(containerTest.marginZero);
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:get/get.dart';
// Identity util to convert to iterables
dynamic _id(dynamic e) => e;
class TestClass {
final name = "John";
}
class EmptyClass {}
void main() {
// Tests for GetUtils.isNullOrBlank are located at dynamic extensions
dynamic _id(dynamic e) => e;
Null _test;
test('null isNullOrBlank should be true for null', () {
expect(GetUtils.isNullOrBlank(_test), true);
});
test('isNullOrBlank should be false for unsupported types', () {
expect(GetUtils.isNullOrBlank(5), false);
expect(GetUtils.isNullOrBlank(0), false);
expect(GetUtils.isNullOrBlank(5.0), equals(false));
expect(GetUtils.isNullOrBlank(0.0), equals(false));
TestClass testClass;
expect(GetUtils.isNullOrBlank(testClass), equals(true));
expect(GetUtils.isNullOrBlank(TestClass()), equals(false));
expect(GetUtils.isNullOrBlank(EmptyClass()), equals(false));
});
test('isNullOrBlank should validate strings', () {
expect(GetUtils.isNullOrBlank(""), true);
expect(GetUtils.isNullOrBlank(" "), true);
expect(GetUtils.isNullOrBlank("foo"), false);
expect(GetUtils.isNullOrBlank(" foo "), false);
expect(GetUtils.isNullOrBlank("null"), false);
});
test('isNullOrBlank should validate iterables', () {
expect(GetUtils.isNullOrBlank([].map(_id)), true);
expect(GetUtils.isNullOrBlank([1].map(_id)), false);
});
test('isNullOrBlank should validate lists', () {
expect(GetUtils.isNullOrBlank(const []), true);
expect(GetUtils.isNullOrBlank(['oi', 'foo']), false);
expect(GetUtils.isNullOrBlank([{}, {}]), false);
expect(GetUtils.isNullOrBlank(['foo'][0]), false);
});
test('isNullOrBlank should validate sets', () {
expect(GetUtils.isNullOrBlank(<dynamic>{}), true);
expect(GetUtils.isNullOrBlank({1}), false);
expect(GetUtils.isNullOrBlank({'fluorine', 'chlorine', 'bromine'}), false);
});
test('isNullOrBlank should validate maps', () {
expect(GetUtils.isNullOrBlank({}), true);
expect(GetUtils.isNullOrBlank({1: 1}), false);
expect(GetUtils.isNullOrBlank({"other": "thing"}), false);
final map = {"foo": 'bar', "one": "um"};
expect(GetUtils.isNullOrBlank(map["foo"]), false);
expect(GetUtils.isNullOrBlank(map["other"]), true);
});
group('GetUtils.isLength* functions', () {
test('isLengthEqualTo should validate iterable lengths', () {
// iterables should cover list and set
... ...