diff --git a/widget/gridwrap.go b/widget/gridwrap.go index 41d512cf73..3bd6902fd1 100644 --- a/widget/gridwrap.go +++ b/widget/gridwrap.go @@ -152,8 +152,10 @@ func (l *GridWrap) RefreshItem(id GridWrapItemID) { func (l *GridWrap) Resize(s fyne.Size) { l.colCountCache = 0 l.BaseWidget.Resize(s) - l.offsetUpdated(l.scroller.Offset) - l.scroller.Content.(*fyne.Container).Layout.(*gridWrapLayout).updateGrid(true) + if l.scroller != nil { + l.offsetUpdated(l.scroller.Offset) + l.scroller.Content.(*fyne.Container).Layout.(*gridWrapLayout).updateGrid(true) + } } // Select adds the item identified by the given ID to the selection. diff --git a/widget/gridwrap_test.go b/widget/gridwrap_test.go index ec36f50d24..e5f0d2d33f 100644 --- a/widget/gridwrap_test.go +++ b/widget/gridwrap_test.go @@ -242,3 +242,14 @@ func TestGridWrap_Selection(t *testing.T) { assert.Equal(t, -1, selected) assert.Equal(t, 9, unselected) } + +func TestGridWrap_ResizeToSameSizeBeforeRender(t *testing.T) { + g := NewGridWrap( + func() int { return 1 }, + func() fyne.CanvasObject { return NewLabel("") }, + func(gwii GridWrapItemID, co fyne.CanvasObject) { co.(*Label).SetText("foo") }, + ) + // will not create renderer. + // will crash if GridWrap scroller (not yet created) is accessed + g.Resize(fyne.NewSize(0, 0)) +}