getWidget function

Widget getWidget(
  1. String widgetType,
  2. Color color,
  3. String graphSizeStr,
  4. DateTime referenceTime, {
  5. String timeWindowStr = 'auto',
  6. String tickerTypeStr = 'last',
  7. double height = 100,
  8. dynamic variable,
})

Implementation

Widget getWidget(
  String widgetType,
  Color color,  // ✅ Changed to String // ✅ Changed to String
  String graphSizeStr,
  DateTime referenceTime,   // ✅ Changed to String
  {String timeWindowStr = 'auto', String tickerTypeStr = 'last', double height = 100, dynamic variable}
) {
  variable ??= mockVariable;

  // ✅ Convert Strings to Enums
  MBTimeWindow? timeWindow = stringToTimeWindow(timeWindowStr);
  MBTickerType? tickerType = stringToTickerType(tickerTypeStr);
  MBGraphSize? graphSize = stringToGraphSize(graphSizeStr);

  // ✅ Provide default values if conversion fails
  timeWindow ??= MBTimeWindow.auto;
  tickerType ??= MBTickerType.last;
  graphSize ??= MBGraphSize.half;

  return widgetRegistry[widgetType]?.call(
        variable, color, timeWindow, tickerType, graphSize, height, referenceTime) ??
      const SizedBox(); // Default to empty if not found
}