dev-ruman
dev-ruman

Reputation: 21

How to add a null value on a list of <Offsets>? null cant be added because flutter null safety

I'm creating a drawing app using flutter. I've used gesturedetector onpanstart, onpanend, onpanupdate. But I have to close the array of offsets. Because of null safety I am not able to use 'null'. how can I add a null value on the List or end up the list somehow. or any other ways to make a drawing app using flutter.

onPanEnd:(details){setState((){drawingPoints.add(null!);});}

Upvotes: 2

Views: 2025

Answers (2)

Malek26
Malek26

Reputation: 1

You can copy what you did with onPanStart , onPanUpdate , but in theonPanEnd instead of writing details.globalPosition just write Offset.infinite

Upvotes: 0

Diwyansh
Diwyansh

Reputation: 3514

To clear the available data in your List use .clear() or to assign a null value simply assign null to it

onPanEnd:(details){setState((){drawingPoints = null;});} // to assign null

onPanEnd:(details){setState((){drawingPoints.clear();});} // to clear the data

Upvotes: 0

Related Questions