2022-10-31 17:32:22 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class ConditionalParent extends StatelessWidget {
|
|
|
|
const ConditionalParent({
|
|
|
|
Key? key,
|
|
|
|
required this.condition,
|
|
|
|
required this.builder,
|
2022-11-02 20:24:41 +00:00
|
|
|
required this.child,
|
2022-10-31 17:32:22 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final bool condition;
|
|
|
|
final Widget Function(Widget) builder;
|
2022-11-02 20:24:41 +00:00
|
|
|
final Widget child;
|
2022-10-31 17:32:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (condition) {
|
|
|
|
return builder(child);
|
|
|
|
} else {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-09 18:58:38 +00:00
|
|
|
|
|
|
|
class BranchedParent extends StatelessWidget {
|
|
|
|
const BranchedParent({
|
|
|
|
Key? key,
|
|
|
|
required this.condition,
|
|
|
|
required this.conditionBranchBuilder,
|
|
|
|
required this.otherBranchBuilder,
|
|
|
|
required this.children,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final bool condition;
|
|
|
|
final Widget Function(List<Widget>) conditionBranchBuilder;
|
|
|
|
final Widget Function(List<Widget>) otherBranchBuilder;
|
|
|
|
final List<Widget> children;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (condition) {
|
|
|
|
return conditionBranchBuilder(children);
|
|
|
|
} else {
|
|
|
|
return otherBranchBuilder(children);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|