I have a screen that contains a Slider_up_widget

On the main body I can pass a variable using widget.type.varaible and returns a string

_pageDetails.detailsMainImage(widget.barPage.barBusinessNameMainImage),

On my slide_up_panel I'm trying to do the same but I'm getting an error

  _pageDetails.businessOperating(widget.barPage.barBusinessAddr),

"The getter 'barPage' isn't defined for the type 'PanelWidgetBusiness'."

This is my panel class

class PanelWidgetBusiness extends StatefulWidget {
  final ScrollController controller;
  final PanelController panelController;

  const PanelWidgetBusiness({
    Key? key,
    required this.controller,
    required this.panelController,
  }) : super(key: key);

  @override
  State<PanelWidgetBusiness> createState() => _PanelWidgetBusinessState();
}

class _PanelWidgetBusinessState extends State<PanelWidgetBusiness> {
  final _pageDetails = const BarRestPageWidgets();

  @override
  Widget build(BuildContext context) =>
      ListView(
        padding: EdgeInsets.zero,
        controller: widget.controller,
        children: [
          // _pageDetails.businessOperating(),
          _pageDetails.businessOperating(widget.barPage.barBusinessAddr),
        ],
      );

}

I have tried using

final BarDetails barPage;

which removes the error but then my panelBuilder requires

The named parameter 'barPage' is required, but there's no corresponding argument.

What have I got to put in there to satisfy it.

 panelBuilder: (controller) => PanelWidgetBusiness(
          controller: controller,
          panelController: panelController, 
          barPage: null, // ←← What should I put here 
        ),

Is it possible to make the barpage not required in the Panel Controller.

I've tried

final BarDetails? barPage;

But then I get the error The property 'barBusinessAddr' can't be unconditionally accessed because the receiver can be 'null'.

And adding a ! null type can be added.

Any help appreciated.


Solution 1: Gebes

You are unable to access widget.barPage.barBusinessAddr in your Stateful Widget because you are not parsing any barPage in the constructor.

If you add final BarDetails barPage; to your PanelWidgetBusiness class then you are not setting the value, you are just defining variable. Because it is non-null type it must be a required argument in your constructor or get a different fixed value during initialization. Setting nothing is not an option in this case.

If BarPage is optional, then you can make it nullable by adding an ?, but you need to be careful. Depending on the logic, your code could look something like this, provided your barPage can be null.

if (widget.barPage != null){
    _pageDetails.businessOperating(widget.barPage!.barBusinessAddr);
}


Solution 2: JohnnyQ

I'm posting this as the answer as I will surely come back to it again.

On the panelcontroller you are passing parameters to the PanelWidgetBusiness() class.

 panelBuilder: (controller) => PanelWidgetBusiness(
          controller: controller,
          panelController: panelController, 
          barPage: null, // ←← What should I put here 
        ),

for the barPage you pass the widget.barPage

 panelBuilder: (controller) => PanelWidgetBusiness(
          controller: controller,
          panelController: panelController,
          barPage: widget.barPage // Answer
        ),

Now you can access all of the elements in the barpage model.

Ans can be assessed using

_pageDetails.businessOperating(**widget.barPage.barBusinessAddr**)

widget.barPage.barBusinessAddr is the main part, the rest is a Widget wrapped around it.