Search code examples
gouser-interfacewidgetextendsfyne

How do I extend a widget.Button so that it has a new method ID in fyne?


I did this but it doesn't work

type buttonWithID struct {
    widget.ListItemID
}

func newButtonWithID(button widget.Button) *buttonWithID {
    newButton := &buttonWithID{}
    newButton.ExtendBaseWidget(newButton)
    newButton.ListItemID = 0

    return newButton
}

and it returns this error:

newButton.ExtendBaseWidget undefined (type *buttonWithID has no field or method ExtendBaseWidget)

Solution

  • If you want to extend Button then your struct must embed the widget.Button type. Extra fields would be added below that. See the tutorial at https://developer.fyne.io/tutorial/extending-widgets