Solved: How to pass a data from dialog view to dialog controller

Question

Asked by Eko M on January 10, 2022 (source).

I need to load API data from controller with parms, but i have don't know how to pass the id from view to controller like arguments

Here is my dialog view:

class ProcessWashingDialog extends BaseWidget<ProcessWashingDialogController> {
  final int id; // the id i need to pass
  final String title;
  final VoidCallback onPressed;
  final VoidCallback onBackPressed;

  ProcessWashingDialog({
    required this.id,
    required this.title,
    required this.onPressed,
    required this.onBackPressed,
  }) : super(AppComponent.getInjector().get());

  @override
  Widget get view => ControlledWidgetBuilder<ProcessWashingDialogController>(
        builder: (context, controller) => Container(
          width: AppSize.DIMEN_324.h,
          height: AppSize.DIMEN_367.h,
          padding: EdgeInsets.all(AppSize.DIMEN_36.h),
          child: controller.isLoading
              ? Center(child: CommonLoading())
              : Column(...

and here is my dialog controller:

class ProcessWashingDialogController extends BaseController {
  ProcessWashingDialogPresenter _presenter;

  ProcessWashingDialogController(this._presenter);
  late TimerRegister _timerRegister;
  TimerRegister get timerRegister => _timerRegister;

  @override
  void initListeners() {
    super.initListeners();

    _initObserver();
    _getTimeRegister();
  }

  void _initObserver() {
    _presenter.onFailure = (e) {};
    _presenter.onFinish = dismissLoading;
    _presenter.onSuccess = (data) {
      _timerRegister = data ?? timerRegister;
    };
  }

  void _getTimeRegister() {
    showLoading();

    _presenter.getTimerRegister(
      <String, String>{
        'Filter[Id]': 104.toString(), // i need to put the variable id here
      },
    );
  }
}

Anyone please help me. Thank you!

Answer

Question answered by Eko M (source).

I have completed with this question, i do like this:

view dialog:

class ProcessWashingDialog extends BaseWidget<ProcessWashingDialogController> {
  final int id;
  final String title;
  final VoidCallback onPressed;
  final VoidCallback onBackPressed;
  final ProcessWashingDialogController _controller;

  ProcessWashingDialog(
  this._controller,
  {
    required this.id,
    required this.title,
    required this.onPressed,
    required this.onBackPressed,
  }) : super(_controller) {
    _controller.setArguments(id);
  };

controller dialog:

void setArguments(int id) {
   _getTimeRegister(id);
}
DART FLUTTER
SHARE: