-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
2,927 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/extensions/example/example_dependency_injection.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'dart:collection'; | ||
|
||
import 'package:extensions/dependency_injection.dart'; | ||
|
||
void main() { | ||
var collection = ServiceCollection(); | ||
collection.addSingleton<String>((services) => '1'); | ||
collection.addSingleton<String>((services) => '2'); | ||
collection.addSingleton<int>((services) => 3); | ||
collection.addSingleton<int>((services) => 4); | ||
collection.addSingleton<int>((services) => 5); | ||
var sp = collection.buildServiceProvider(); | ||
|
||
var result = sp.getService<int>(); | ||
|
||
print(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
library extensions.diagnostics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Mixin to create Enum for bitflags uses. | ||
mixin EnumFlags on Enum { | ||
// value receive a bitwise shift operation. It means "shift the | ||
// bits of 1 to the left by index places". | ||
// | ||
//So, "1,10,100,1000..." == 1,2,4,8,16.... | ||
int get value => 1 << index; | ||
// Creates a operator "|" for enum. | ||
int operator |(other) => value | other.value; | ||
|
||
int operator &(other) => value & other.value; | ||
|
||
int operator ^(other) => value ^ other.value; | ||
} | ||
|
||
// Extension "int" to verify that value contains the enum flag. | ||
extension EnumFlagsExtension on int { | ||
bool hasFlag(EnumFlags flag) => this & flag.value == flag.value; | ||
} | ||
|
||
void main() { | ||
final x = Car.ford | Car.honda; | ||
print(x); | ||
print(x.hasFlag(Car.honda)); | ||
final y = Car.ford & Car.subaru; | ||
print(y); | ||
print(y.hasFlag(Car.ford)); | ||
} | ||
|
||
enum Car with EnumFlags { | ||
ford, | ||
honda, | ||
subaru, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
bool isNullOrEmpty(String? value) { | ||
if (value == null || value.isEmpty) return true; | ||
if (value.isEmpty) return true; | ||
return false; | ||
} | ||
|
||
bool isNullOrWhitespace(String? value) { | ||
if (value == null) return true; | ||
return value.trim().isEmpty; | ||
} | ||
|
||
bool equals(String value1, String value2, {bool ignoreCase = true}) => | ||
ignoreCase | ||
? value1.toLowerCase() == value2.toLowerCase() | ||
: value1 == value2; |
Oops, something went wrong.