guard 1.0.2 guard: ^1.0.2 copied to clipboard
Evauluates the function wrapping the body with try/catch and returns default value if error was raised
guard #
Evauluates the function wrapping the body with try/catch and returns default value if error was raised
Installation #
pubspec.yaml:
dependencies:
guard: ^1.0.2
Example #
import 'package:guard/guard.dart';
class User {
final String name;
User(this.name);
}
void main() {
final items = [];
guard(() => items.first, null); // null
User user;
guard(() => Text(user.name), Text('Loading...')); // Loading...
user = User('John Brown');
guard(() => Text(user.name), Text('Loading...')); // John Brown
}
License #
MIT