Skip to content

Instantly share code, notes, and snippets.

@Davenchy
Created August 1, 2021 20:14
Show Gist options
  • Save Davenchy/d2cf5ffdd745b98cc5aeb87d89622263 to your computer and use it in GitHub Desktop.
Save Davenchy/d2cf5ffdd745b98cc5aeb87d89622263 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class ConditionalBuilder extends StatelessWidget {
const ConditionalBuilder({
Key? key,
required this.condition,
required this.builder,
this.fallback,
}) : super(key: key);
final bool condition;
final WidgetBuilder builder;
final WidgetBuilder? fallback;
@override
Widget build(BuildContext context) {
return condition
? build(context)
: fallback != null
? fallback!.call(context)
: Container();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment