guard 1.0.4

Flutter Android iOS web

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

guard #

lesnitsky.dev GitHub stars Twitter Follow

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

Installation #

pubspec.yaml:

dependencies:
  guard: ^1.0.3

Example #

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);
}

License #

MIT

7
likes
100
pub points
72%
popularity

Publisher

lesnitsky.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

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on guard