I am getting an undefined name error even when i defined the var in my dart file,Below is the error image
Below is my code
import 'package:flutter/material.dart';import 'package:provider/provider.dart';import '../providers/products.dart';class ProductDetailsScreen extends StatelessWidget { // final String title; // ProductDetailsScreen(this.title); static const routeName = '/product-detail'; @override Widget build(BuildContext context) { final productId = ModalRoute.of(context)?.settings.arguments as String?; if (productId != null) { final loadedProduct = Provider.of<Products>(context) .items .firstWhere((prod) => prod.id == productId); } return Scaffold( appBar: AppBar( title: Text(loadedProduct.title), ), ); }}plus when i try to move the return code-block to the if method like this
import 'package:flutter/material.dart';import 'package:provider/provider.dart';import '../providers/products.dart';class ProductDetailsScreen extends StatelessWidget { // final String title; // ProductDetailsScreen(this.title); static const routeName = '/product-detail'; @override Widget build(BuildContext context) { final productId = ModalRoute.of(context)?.settings.arguments as String?; if (productId != null) { final loadedProduct = Provider.of<Products>(context) .items .firstWhere((prod) => prod.id == productId); return Scaffold( appBar: AppBar( title: Text(loadedProduct.title), ), ); } }}it then throws an error "the body might complete normally, causing null to be returned, but the return type, "widget" is a potentially non-nullable type.
Please i need help as it looks like my unfamiliarity with null-safety is giving me lot of bugs.
