guard 1.0.4 copy "guard: ^1.0.4" to clipboard
guard: ^1.0.4 copied to clipboard

discontinued

Evauluates the function wrapping the body with try/catch and returns default value if error was raised or return value is null

example/lib/main.dart

import 'package:flutter/material.dart';
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(() => user, 'No user found'); // No User found
  guard(() => Text(user.name), Text('Loading...')); // Loading...;

  asyncGuard(() async {
    await Future.error(null);
  }, 42); // Future(42);
}
7
likes
40
pub points
6%
popularity

Publisher

verified publisherlesnitsky.dev

Evauluates the function wrapping the body with try/catch and returns default value if error was raised or return value is null

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on guard