I'm trying to route to specific id /product/:id but when i click on my card to navigate it shows an error , but when i do hot reload it works.
**Here is the error **> type 'Null' is not a subtype of type 'String'
go-router in main.dart
final GoRouter _router = GoRouter(
debugLogDiagnostics: true,
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) {
return const MainPage();
},
),
GoRoute(
path: '/product/:id',
builder: (BuildContext context, GoRouterState state)=> DetailsView(id:state.params["id"]!)
),
GoRoute(
path: '/homepage',
builder: (BuildContext context, GoRouterState state) {
return const HomePage();
},
),
],
);
here is how i route to my product/:id (I'm using Carousel Slider).
Widget buildImage(String urlImage, String title, int price, double padding,
int index, String id, BuildContext context) =>
GestureDetector(
**onTap: () {
context.push("/product/$id");
},**
child: Container(
............))) etc
and here is my detailsView page which when navigating to the error appears.
class DetailsView extends StatefulWidget {
final String id;
/// Constructs a [DetailsScreen]
const DetailsView({super.key, required this.id});
@override
State<DetailsView> createState() => _DetailsViewState();
}
class _DetailsViewState extends State<DetailsView> {
var urlImage;
var description;
var price;
var title;
getProductInfo(id) async {
devtools.log(id);
var productRef = await FirebaseFirestore.instance
.collection('products')
.doc(id)
.get()
.then((doc) => {
urlImage = doc.get("urlImage"),
description = doc.get("description"),
price = doc.get("price"),
title = doc.get("title"),
});
}
@override
void initState() {
var id = widget.id;
getProductInfo(id);
super.initState();
}
@override
Widget build(BuildContext context) {
.....}
type 'Null' is not a subtype of type 'String' , this error appears when i navigate to my page using go-router package