79159568

Date: 2024-11-05 14:50:50
Score: 2.5
Natty:
Report link

in flutter: extracting a widget

"A reference to an enclosing class method can't be extracted," ERROR

this happens when the widget we are trying to extract uses setState

(which is specific to statefull widgets)

and it means = NO ACCESS TO setState method

HOW TO FIX THIS?

  1. Extract as a function
  2. Extract as a widget a-Extract as a stateless widget b-Extract as a statefull widget:

b-1: Extract with a callBack: The widget is stateful, but it communicates state changes to its parent via the callback,this maintains a single source of truth for the state.

b-2: Extract without a callBack in this case every instance will have its own internal state(isolation). which leads to a difficulty for parent widget to control or access the state.

Mostly we either extract as a function, as a stateless widget, or as a statefull widget with a callback.

when to extract as a statefull widget without a callBack?

Reasons:
  • RegEx Blacklisted phrase (1.5): HOW TO FIX THIS?
  • Long answer (-1):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Nour El houda Akhdari