Created
August 1, 2021 20:14
-
-
Save Davenchy/d2cf5ffdd745b98cc5aeb87d89622263 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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