mcrovero / rubber

An elastic material bottom sheet implementation for Flutter.
BSD 2-Clause "Simplified" License
562 stars 88 forks source link

RubberBottomSheet isn't working in release builds #13

Closed ghost closed 5 years ago

ghost commented 5 years ago

Great library! For now, it's the only way to implement awesome persistent bottom sheet. But there is an annoying bug.

Source code of my application: https://github.com/alexandr2levin/my_mikhailovka

Description of the bug RubberBottomSheet very often expands to full height and can't be collapsed in release builds. Sometimes it works as expected, but it happens very rare. Debug builds works as expected.

To Reproduce

  1. flutter run --release my project
  2. try to collapse the bottom sheet

Screenshots

Release build (incorrect behavior) Debug build (correct behavior)
telegram-cloud-file-2-257120505-20070-2437342557360051043 telegram-cloud-file-2-257033876-20696--9013455571151254205

Smartphone:

Flutter doctor

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.3 18D109, locale en-RU)
ghost commented 5 years ago

The same situation happens even if I replace my complex layout with just Containers

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(AppLocalizations.of(context).homeTitle),
      ),
      body: RubberBottomSheet(
        lowerLayer: Container(
          decoration: BoxDecoration(
              color: Colors.cyan[100]
          ),
        ),
        upperLayer: Container(
          decoration: BoxDecoration(
              color: Colors.cyan
          ),
        ),
        //scrollController: _scrollController,
        animationController: _controller,
      ),
    );
  }
Stalder commented 5 years ago

I haven't explored sources yet, but i guess that reason might be connected with fact, that in release builds Flutter provide size of widget not imidiatly, but after some time. So it's necessary to check all init methods, where height might be used.

mcrovero commented 5 years ago

I'm back on the project! With the latest commits, it seems working on my device give it a try with the latest update. 👍 The first layout on release mode caused me already some headaches and I've already integrated after_layout to avoid these issues. Cool design by the way!

mochar commented 5 years ago

I'm not sure if this is related, but even after the new update I get the following error:

RenderBox was not laid out: RenderStack#78f77 NEEDS-LAYOUT NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1482 pos 12: 'hasSize'

The offending code:

  double get _bottomSheetHeight {
    final RenderBox renderBox = _keyWidget.currentContext.findRenderObject();
    return renderBox.size.height;
  }

Appearently it doesn't have a size yet, which is weird because findRenderObject mentions:

  /// If the render object is a [RenderBox], which is the common case, then the
  /// size of the render object can be obtained from the [size] getter. This is
  /// only valid after the layout phase, and should therefore only be examined
  /// from paint callbacks or interaction event handlers (e.g. gesture
  /// callbacks)

and in the new update you only call _botttomSheetHeight in the afterFirstLayout callback. Any ideas?

mcrovero commented 5 years ago

When do you get that error? And on which device/os?

mochar commented 5 years ago

This is my issue: https://github.com/mcrovero/rubber/issues/18

I get the error as soon as my page builds, when RubberBottomSheet is called for the first time. More specifically when the _bottomSheetHeight getter is called. I should probably mention that running the examples works fine but somehow i get an error in my project... I realize this is quite vague so If its not enough to go by I can try to set up a minimum example

Nazacheres commented 5 years ago

Any updates on this? it stops us from going to production... :(

Nazacheres commented 5 years ago

@alexandr2levin Were you able to resolve this issue?

mcrovero commented 5 years ago

This is my issue: #18

I get the error as soon as my page builds, when RubberBottomSheet is called for the first time. More specifically when the _bottomSheetHeight getter is called. I should probably mention that running the examples works fine but somehow i get an error in my project... I realize this is quite vague so If its not enough to go by I can try to set up a minimum example

I can't reproduce the error, is the example in the library also generating the error?

mcrovero commented 5 years ago

Closing for inactivity