Use Type with Flutter Hooks

Issue

I was trying to add different useState in my page with Flutter hook but i can’t find a way to do it by giving them a type first, because of the inital value requested.

i can’t initialize my useState with :

QRViewController? controller = useState();

or

final controller = useState<QRViewController>()

or

QRViewController? controller = useState(null);

How can i initialized controller with custom type ?

Solution

final ValueNotifier<QRViewController?> controller = useState(null);

Or

final controller = useState<QRViewController?>(null);

You were very close.

Answered By – Tim Jacobs

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *