Houzi Docs logo Houzi Docs

You can show custom widgets to your home pages sliver appbar easily via hooks.

If you want to show a ‘custom widget’ in Home page sliver appbar, you need to do following things:

For Example: If you have a custom widget named as CustomWidget(), define its height and body and define _bodyHookMap and restart the app.

  @override
  HomeSliverAppBarBodyHook getHomeSliverAppBarBodyHook() {
    HomeSliverAppBarBodyHook _homeSliverAppBarBodyHook = (context) {
      Map<String, dynamic>? _bodyHookMap;
      double? _bodyWidgetHeight;
      Widget? _bodyWidget;

      // _bodyWidgetHeight = 220;
      // _bodyWidget = CustomWidget();
      
      _bodyHookMap = {
        "height" : _bodyWidgetHeight,
        "widget" : _bodyWidget,
      };
      return _bodyHookMap;
    };
    return _homeSliverAppBarBodyHook;
  }
  

Added in version 1.3.0

Previous: Add Custom Widget in Home Next: Add Custom Widget in Property Details