i have an error on my emulator and I haven’t found a solution
the error is “NoSuchMethodError was thrown. The getter ‘screenRoute’ was called on null flutter
tried calling:screenRoute”
and idk what shoud i do
the code:-
import 'package:flutter/material.dart';
import 'package:traveling_trip/models/trip.dart';
import 'package:traveling_trip/screens/trip_detalls_screen.dart';
class TripItem extends StatelessWidget {
final String id;
final String title;
final String imageUrl;
final int duration;
final Season season;
final TripType tripType;
final Function removeItem;
const TripItem({
Key? key,
required this.title,
required this.imageUrl,
required this.duration,
required this.season,
required this.tripType,
required this.id,
required this.removeItem,
}) : super(key: key);
String get seasontext {
switch (season) {
case Season.Winter:
return "winter";
case Season.Summer:
return "summer";
case Season.Spring:
return "spring";
case Season.Autumn:
return "autumn";
}
}
String get tripTypetext {
switch (tripType) {
case TripType.Recovery:
return "Recovery";
case TripType.Therapy:
return "Therapy";
case TripType.Activities:
return "Activities";
case TripType.Exploration:
return "Exploration";
}
}
void selectTrip(BuildContext context) {
Navigator.of(context)
.pushNamed(TripDetallsScreen.screenRoute, arguments: id)
.then((result) {
print(result);
});
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () => selectTrip(context),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 7,
margin: EdgeInsets.all(10),
child: Column(
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
),
child: Image.network(
imageUrl,
height: 250,
width: double.infinity,
fit: BoxFit.cover,
),
),
Container(
height: 250,
alignment: Alignment.bottomRight,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.black.withAlpha(0),
Colors.black.withOpacity(0.80),
],
stops: [0.6, 1],
),
),
child: Text(
title,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: Colors.white,
),
overflow: TextOverflow.fade,
),
),
],
),
Container(
padding: EdgeInsets.all(15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Icon(
Icons.today,
size: 30,
color: Colors.amber,
),
SizedBox(width: 7),
Text(
"$duration أيام",
style: TextStyle(fontSize: 20),
),
],
),
Row(
children: [
Icon(
Icons.wb_sunny,
size: 30,
color: Colors.amber,
),
SizedBox(width: 7),
Text(
"$seasontext",
style: TextStyle(fontSize: 20),
),
],
),
Row(
children: [
Icon(Icons.family_restroom,
color: Colors.amber, size: 30),
SizedBox(width: 7),
Text(
"$tripTypetext",
style: TextStyle(fontSize: 20),
),
],
),
],
),
),
],
),
),
);
}
}
I was trying to write the code, as you saw in my course, to learn how to delete a travel page with one button. The code is full of pages, and I have made many modifications in many pages, but this is the most modified page.
zpi123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.