return a value to parent widget in flutter code example

Example 1: flutter conditional parent widget

import 'package:flutter/widgets.dart';

class ConditionalParentWidget extends StatelessWidget {
  const ConditionalParentWidget({
    Key key,
     this.condition,
     this.child,
     this.conditionalBuilder,
  }) : super(key: key);

  final Widget child;
  final bool condition;
  final Widget Function(Widget child) conditionalBuilder;

  
  Widget build(BuildContext context) {
    return condition ? this.conditionalBuilder(this.child) : this.child;
  }
}

Example 2: flutter conditional parent widget

return includeBlueContainer  ? blueWidget() : redWidget();

Widget blueWidget() {
return Container(
  color: Colors.blue,
  child: Container(
    child: Text("Child"),
  ),
)
}

Widget redWidget() {
return Container(
  color: Colors.red,
  child: Container(
    child: Text("Child"),
  ),
)
}

Tags:

Dart Example