Quantcast
Channel: why do i get error of Undefined name even when the variable is defined? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Md. Yeasin Sheikh for why do i get error of Undefined name even when the variable is defined?

$
0
0

loadedPorduct is not available outside the if(productId!=null).

Place this variable out of it, inside the build context.

late  final loadedProduct ;  final productId = ModalRoute.of(context)?.settings.arguments as String?;if (productId != null) {   loadedProduct = Provider.of<Products>(context)        .items        .firstWhere((prod) => prod.id == productId);  }

And use case will be

Text(loadedProduct?.title?? "default TextOn null case"),

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>