prepareWidget function

Widget prepareWidget(
  1. dynamic object, {
  2. dynamic parameter = const NotGiven(),
  3. BuildContext? context,
  4. Function? stringToWidgetFunction,
})

Implementation

Widget prepareWidget(dynamic object,
    {dynamic parameter = const NotGiven(),
    BuildContext? context,
    Function? stringToWidgetFunction}) {
  if (object == null) {
    return (object);
  }
  if (object is Widget) {
    return (object);
  }
  if (object is String) {
    if (stringToWidgetFunction == null) {
      return (Text(object));
    } else {
      return (stringToWidgetFunction(object));
    }
  }
  if (object is Function) {
    if (parameter is NotGiven) {
      if (context == null) {
        return (prepareWidget(object(),
            stringToWidgetFunction: stringToWidgetFunction));
      } else {
        return (prepareWidget(object(context),
            stringToWidgetFunction: stringToWidgetFunction));
      }
    }
    if (context == null) {
      return (prepareWidget(object(parameter),
          stringToWidgetFunction: stringToWidgetFunction));
    }
    return (prepareWidget(object(parameter, context),
        stringToWidgetFunction: stringToWidgetFunction));
  }
  return (Text("Unknown type: ${object.runtimeType.toString()}"));
}