future_or_builder 1.0.3 future_or_builder: ^1.0.3 copied to clipboard
Builds FutureOrs immediately and otherwise delegates to a FutureBuilder
// Copyright (C) 2019 Wilko Manger
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:future_or_builder/future_or_builder.dart';
FutureOr<bool> doThatThing() {
// Could either return a Future<bool> or a FutureOr<bool>
return true;
}
class SomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureOrBuilder<bool>(
futureOr: doThatThing(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
final didThatThing = snapshot.data;
if (didThatThing) {
return Text('Cool!');
}
return Container();
},
);
}
}