macosui / macos_ui

Flutter widgets and themes implementing the current macOS design language.
https://macosui.github.io/macos_ui/#/
MIT License
1.81k stars 178 forks source link

MacosTextField expand with ResizablePane crashes #413

Closed robaolana closed 1 year ago

robaolana commented 1 year ago

Description

A MacosTextField wrapped with Resizable Pane with expand, no maxlines crashes with the error '''FlutterError (The Scrollbar's ScrollController has no ScrollPosition attached. A Scrollbar cannot be painted without a ScrollPosition. The Scrollbar attempted to use the provided ScrollController. This ScrollController should be associated with the ScrollView that the Scrollbar is being applied to.When providing your own ScrollController, ensure both the Scrollbar and the Scrollable widget use the same one.)'''

Use textfield with generic code like this:

ResizablePane(
  minSize: 50,
  startSize: 60,
  resizableSide: ResizableSide.top,
  maxSize: MediaQuery.of(context).size.height / 2.5,
  builder: (_, __) {
    return MacosTextField(
      prefix: MacosIcon(CupertinoIcons.money_dollar),
      placeholder: 'Type some text here',
      expands: true,
      maxLines: null,
      showCursor: true,
      clearButtonMode: OverlayVisibilityMode.always,
    );
  },
),
stMerlHin commented 1 year ago

Hey @robaolana, I can actually reproduce the issue.

ResizablePane has an internal Scrollable so making any widget a child of ResisablePane is some way wrapping it with Scrollable. You are supposed to give the scrollController of the ResizablePane.builder to the main widget which has a scroll behaviour in your widget tree. Since the MacosTextField like material TextField content can be scrolled when it overflows the view port it has a scroll behaviour.

Also it should not crash the app, you should just have the error stack trace in your console when scrolling the content of the MacosTextField but visually everything should seem to be working fine.

Poposal

Try this...

ResizablePane(
minSize: 50,
startSize: 60,
resizableSide: ResizableSide.top,
maxSize: MediaQuery.of(context).size.height / 2.5,
builder: (_, scrollController) {
   return MacosTextField(
       //Passing the  builder scrollController  to the [MacosTextField]
       scrollController: scrollController,
       prefix: MacosIcon(CupertinoIcons.money_dollar),
       placeholder: 'Type some text here',
       expands: true,
       maxLines: null,
       showCursor: true,
       clearButtonMode: OverlayVisibilityMode.always,
),);
},
)
stMerlHin commented 1 year ago

@GroovinChip, Shouldn't be nice to add a property and maybe a Constructor that would allow the disabling of the scroll behavior of the Resizablepane ?

Sometimes I use scrollable widgets which don't expose their controller, so the only way to avoid this error is to wrap them inside another Scrollable widget which expose his controller.