handler

);

Why BuildContext requires extra attention

An example of a large, short-living object that
might squeeze into a long-living area and thus cause leaks,
is the context parameter passed to Flutter’s 
build method.

The following code is leak prone,
as useHandler might store the handler
in a long-living area:

// BAD: DO NOT DO THIS

// This code is leak prone:

@override

Widget

build

BuildContext

context

final

handler

()

apply

Theme

of

context

));

useHandler

handler

);

How to fix leak prone code?