'Sliding up panel controller open null

Im using sliding_up_panel package 2.0.0+1, im making google maps and everything is done then i want to add function if i press search button the panel will open but when i use this panelController.open(); it return null in debug console

Controller i put it above Widget build

 PanelController panelController;

Error

The method 'open' was called on null.
Receiver: null
Tried calling: open()

Function button

IconButton(
        tooltip: "Search",
        onPressed: () {
          setState(() {
            panelController.open();
          });
        },
        icon: Icon(Icons.search),
      ),

Panel code

 SlidingUpPanel(
                  minHeight: MediaQuery.of(context).size.height * 0.04,
                  maxHeight: MediaQuery.of(context).size.height * 0.55,
                  controller: panelController,
                  defaultPanelState: PanelState.CLOSED,
                  isDraggable: true,
                  color: Colors.transparent,
                  borderRadius: BorderRadius.vertical(
                    top: Radius.circular(25.0),
                  ),
                  boxShadow: [
                    BoxShadow(
                      color: Color.fromRGBO(0, 0, 0, 0.0),
                    )
                  ],
                  panel: Flexible(
                        ... Panel Widget ...
                  ),
                ),


Solution 1:[1]

Based on the documentation

///The controller of sliding up panel
   PanelController panelController = PanelController();

initialise your panel controller before using. like this.

class MyHomePages2 extends HookWidget {
  PanelController panelController = PanelController();

  MyHomePages2({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SlidingUpPanel(
      minHeight: MediaQuery.of(context).size.height * 0.04,
      maxHeight: MediaQuery.of(context).size.height * 0.55,
      controller: panelController,
      defaultPanelState: PanelState.CLOSED,
      isDraggable: true,
      color: Colors.transparent,
      borderRadius: BorderRadius.vertical(
        top: Radius.circular(25.0),
      ),
      boxShadow: [
        BoxShadow(
          color: Color.fromRGBO(0, 0, 0, 0.0),
        )
      ],
      panel: Flexible(
        child: Text(""),
      ),
    );
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1