Consumer function

Widget Consumer({
  1. String? id,
  2. String? store,
  3. List<String>? stores,
  4. Function? builder,
  5. Function? childBuilder,
  6. Function? childNotifierBuilder,
  7. Function? notifierBuilder,
  8. Widget? child,
})

Implementation

Widget Consumer({
  String? id,
  String? store,
  List<String>? stores,
  Function? builder,
  Function? childBuilder,
  Function? childNotifierBuilder,
  Function? notifierBuilder,
  Widget? child,
}) {
  // builder requirement
  if (builder == null &&
      childBuilder == null &&
      childNotifierBuilder == null &&
      notifierBuilder == null) {
    throw Exception('Atleast one builder is required.');
  }

  // child requirement
  if (child == null && (childBuilder != null || childNotifierBuilder != null)) {
    throw Exception('No child widget has been provided.');
  }

  bool isSingle = stores == null ? true : false;
  // print('Consumer: ');
  // print(isSingle);

  return _RxWidget(
    id: id,
    requestedStores: isSingle ? [store ?? 'default'] : stores,
    builder: builder,
    childBuilder: childBuilder,
    childNotifierBuilder: childNotifierBuilder,
    notifierBuilder: notifierBuilder,
    child: child,
    isSingle: isSingle,
  );
}