sliding_up_panel icon indicating copy to clipboard operation
sliding_up_panel copied to clipboard

Set MinHeight of panel to fit content

Open chuabingquan opened this issue 5 years ago • 14 comments

Hello, is it possible to set the MinHeight of the panel based on content that's being revealed? (Like collapsed except the content in it doesn't fade away on drag up)

chuabingquan avatar Dec 30 '19 14:12 chuabingquan

any update about this?

brizaldi avatar Feb 24 '20 04:02 brizaldi

Interested in this as well. I got around this by tapping into the build function of the Panel Body and getting the content height at runtime but a less hacky way would be nice.

asiamov avatar Apr 13 '20 15:04 asiamov

Yep, I need this one too...

ghost avatar Apr 22 '20 12:04 ghost

Interested in this as well. I got around this by tapping into the build function of the Panel Body and getting the content height at runtime but a less hacky way would be nice.

Hey, could you please share your code snippet to make this change? I know it's dirty but as maintainer does not update this package, it might be a good solution for me. Thanks!

houdayec avatar Jul 16 '20 09:07 houdayec

Interested in this as well. I got around this by tapping into the build function of the Panel Body and getting the content height at runtime but a less hacky way would be nice.

Hey, could you please share your code snippet to make this change? I know it's dirty but as maintainer does not update this package, it might be a good solution for me. Thanks!

Sure, in my PanelContent Widget I add a call like this in the build function:


 @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance
        .addPostFrameCallback((_) => onBuildCompleted(context));

...

void onBuildCompleted(BuildContext context) {
    if (widget._containerKey.currentContext != null) {
      final RenderBox containerRenderBox =
          widget._containerKey.currentContext.findRenderObject();

      double containerSize = containerRenderBox.size.height;
      
      // only set if it actually changed
      if (_lastHeight != containerSize) {
        setState(() {
          _lastHeight = containerSize;
        });
        Provider.of<PanelProvider>(context).changePanelHeight(containerSize);
      }
    }
  }

I pass the GlobalKey from the main widget: GlobalKey _containerKey = GlobalKey();

The SlidingUpPanel then listens for the Provider change and sets maxHeight

I additionally animated the height change:

  @override
  void didChangeDependencies() {
    controller.reset();
    double begin = panelHeight;
    double end = Provider.of<PanelProvider>(context).currentPanelHeight;
    panelHeightTween.begin = begin;
    panelHeightTween.end = end;
    setState(() {
      panelHeight = end;
    });
    controller.forward();
    super.didChangeDependencies();
  }

asiamov avatar Jul 16 '20 09:07 asiamov

Interested in this as well. I got around this by tapping into the build function of the Panel Body and getting the content height at runtime but a less hacky way would be nice.

Hey, could you please share your code snippet to make this change? I know it's dirty but as maintainer does not update this package, it might be a good solution for me. Thanks!

Sure, in my PanelContent Widget I add a call like this in the build function:

 @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance
        .addPostFrameCallback((_) => onBuildCompleted(context));

...

void onBuildCompleted(BuildContext context) {
    if (widget._containerKey.currentContext != null) {
      final RenderBox containerRenderBox =
          widget._containerKey.currentContext.findRenderObject();

      double containerSize = containerRenderBox.size.height;
      
      // only set if it actually changed
      if (_lastHeight != containerSize) {
        setState(() {
          _lastHeight = containerSize;
        });
        Provider.of<PanelProvider>(context).changePanelHeight(containerSize);
      }
    }
  }

I pass the GlobalKey from the main widget: GlobalKey _containerKey = GlobalKey();

The SlidingUpPanel then listens for the Provider change and sets maxHeight

I additionally animated the height change:

  @override
  void didChangeDependencies() {
    controller.reset();
    double begin = panelHeight;
    double end = Provider.of<PanelProvider>(context).currentPanelHeight;
    panelHeightTween.begin = begin;
    panelHeightTween.end = end;
    setState(() {
      panelHeight = end;
    });
    controller.forward();
    super.didChangeDependencies();
  }

Thanks mate, it helped me! At first, using a provider was a bad approach to me, but couldn't find any other solution.. however it's working pretty well.

houdayec avatar Jul 16 '20 12:07 houdayec

Interested in this as well. I got around this by tapping into the build function of the Panel Body and getting the content height at runtime but a less hacky way would be nice.

Hey, could you please share your code snippet to make this change? I know it's dirty but as maintainer does not update this package, it might be a good solution for me. Thanks!

Sure, in my PanelContent Widget I add a call like this in the build function:


 @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance
        .addPostFrameCallback((_) => onBuildCompleted(context));

...

void onBuildCompleted(BuildContext context) {
    if (widget._containerKey.currentContext != null) {
      final RenderBox containerRenderBox =
          widget._containerKey.currentContext.findRenderObject();

      double containerSize = containerRenderBox.size.height;
      
      // only set if it actually changed
      if (_lastHeight != containerSize) {
        setState(() {
          _lastHeight = containerSize;
        });
        Provider.of<PanelProvider>(context).changePanelHeight(containerSize);
      }
    }
  }

I pass the GlobalKey from the main widget: GlobalKey _containerKey = GlobalKey();

The SlidingUpPanel then listens for the Provider change and sets maxHeight

I additionally animated the height change:

  @override
  void didChangeDependencies() {
    controller.reset();
    double begin = panelHeight;
    double end = Provider.of<PanelProvider>(context).currentPanelHeight;
    panelHeightTween.begin = begin;
    panelHeightTween.end = end;
    setState(() {
      panelHeight = end;
    });
    controller.forward();
    super.didChangeDependencies();
  }

What does this look like? Any chance of a gif?

ghenry avatar Aug 02 '20 09:08 ghenry

Interested in this as well. I got around this by tapping into the build function of the Panel Body and getting the content height at runtime but a less hacky way would be nice.

Hey, could you please share your code snippet to make this change? I know it's dirty but as maintainer does not update this package, it might be a good solution for me. Thanks!

Sure, in my PanelContent Widget I add a call like this in the build function:

 @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance
        .addPostFrameCallback((_) => onBuildCompleted(context));

...

void onBuildCompleted(BuildContext context) {
    if (widget._containerKey.currentContext != null) {
      final RenderBox containerRenderBox =
          widget._containerKey.currentContext.findRenderObject();

      double containerSize = containerRenderBox.size.height;
      
      // only set if it actually changed
      if (_lastHeight != containerSize) {
        setState(() {
          _lastHeight = containerSize;
        });
        Provider.of<PanelProvider>(context).changePanelHeight(containerSize);
      }
    }
  }

I pass the GlobalKey from the main widget: GlobalKey _containerKey = GlobalKey(); The SlidingUpPanel then listens for the Provider change and sets maxHeight I additionally animated the height change:

  @override
  void didChangeDependencies() {
    controller.reset();
    double begin = panelHeight;
    double end = Provider.of<PanelProvider>(context).currentPanelHeight;
    panelHeightTween.begin = begin;
    panelHeightTween.end = end;
    setState(() {
      panelHeight = end;
    });
    controller.forward();
    super.didChangeDependencies();
  }

What does this look like? Any chance of a gif?

You have the same sliding sheet as in the examples or reade.me, but the height is simply adapted to the content.

houdayec avatar Aug 02 '20 19:08 houdayec

@asiamov Hi, can you please show some full working example? I did not understand where exactly the codes above are used. Thanks in advance

JRakhimov avatar Mar 08 '21 10:03 JRakhimov

@houdayec

JRakhimov avatar Mar 08 '21 12:03 JRakhimov

Hello, is it implemented?

c0c4i avatar Aug 02 '21 21:08 c0c4i

Still need this

ghost avatar May 11 '22 17:05 ghost

I think it could be closed, already have

maxHeight: ...
minHeight: ...

cenyG avatar Dec 20 '22 06:12 cenyG

I think it could be closed, already have

maxHeight: ...
minHeight: ...

Read the issue carefully, basically author want SlidingUpPanel to have minHeight based on content's height, this is like collapsed widget, but it will not fade away while expanding.

IDK I think we're have no chances to resolve this, project is abandoned :smiling_face_with_tear:

ghost avatar Dec 24 '22 12:12 ghost