Im trying to pass the String variable Name
which is set in the 4th from bottom line of code (in my Future getProduct()
Class), and display it as text in the body of my testPage
Stateful class. It seems like such a simple thing to do however I have no clue to pass it. If anyone is able to help and kindly explain it would be much appreciated.
my dart file:
class testPage extends StatefulWidget {
String barcodeResult;
testPage({required this.barcodeResult});
@override
_testPageState createState() => _testPageState(barcodeResult);
}
class _testPageState extends State<testPage> {
String barcodeResult;
_testPageState(this.barcodeResult);
@override
Widget build(BuildContext context) {
getProduct();
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal,
title:Text('Found Your Item',
style: TextStyle(
fontFamily: 'Fredoka',
fontSize: 25,
),
),
),
body:Center(
child:
Text(Name,
style: TextStyle(fontSize: 30),
),
),
);
}
Future<Product?> getProduct() async {
ProductQueryConfiguration configuration = ProductQueryConfiguration(
barcodeResult,
fields: [ProductField.NAME]);
ProductResult result = await OpenFoodAPIClient.getProduct(configuration);
if(result.status != 1) {
print("Error retreiving the product : ${result.status}");;
}
String? Name = result.product!.productName;
debugPrint("Test :${Name}");
}
}