generateWidget method

Widget generateWidget(
  1. BuildContext context,
  2. String widgetName, {
  3. Map<String, dynamic> arguments = const {},
  4. Widget? child,
})

Generate widget You can use the widget of other modules without import module

Implementation

Widget generateWidget(
  BuildContext context,
  String widgetName, {
  Map<String, dynamic> arguments = const {},
  Widget? child,
}) {
  BlocWidgetBuilder? widgetBuilder = widgetMap['$widgetName@$pageLayoutType'];
  widgetBuilder ??= widgetMap[widgetName];
  if (widgetBuilder != null) {
    String? parentModelName = ModelNameProvider.of(context);
    Widget? realChild = child;
    if (parentModelName != null && parentModelName.isNotEmpty && child != null) {
      realChild = ModelNameProvider(
        blocName: parentModelName,
        child: Builder(
          builder: (BuildContext context) {
            return child;
          },
        ),
      );
    }

    return ModelNameProvider(
      blocName: widgetName.split('/')[0],
      child: widgetBuilder(arguments, realChild),
    );
  } else {
    return Container(
      color: Colors.yellow,
      child: Center(
        child: Text(
          'Wrong Widget',
          style: TextStyle(fontSize: 14.0),
        ),
      ),
    );
  }
}