I see this error The argument type 'List?' can't be assigned to the parameter type 'List'. I try to fix this using a different way but I am not able to fix this issue.
import packages here
class Homepage extends StatefulWidget {
const Homepage({Key? key}) : super(key: key);
@override
_HomepageState createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
final apiURL = Uri.parse(
'api url here');
ExerciseJson? exerciseJson;
@override
void initState() {
setState(() {
getExercises();
});
super.initState();
}
void getExercises() async {
http.Response response = await http.get(apiURL);
var body = response.body;
var decodeJson = jsonDecode(body);
// print(body);
// return decodeJson();
exerciseJson = ExerciseJson.fromJson(decodeJson);
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Testing..."),
),
body: Container(
child: exerciseJson != null
? ListView(
// "${exerciseJson?.exercises?[index].thumbnail}"
children: exerciseJson?.exercises?.map((e) {
return InkWell(
onTap: () {},
child: Container(
margin: EdgeInsets.all(10),
// decoration:
// BoxDecoration(borderRadius: BorderRadius.circular(16)),
child: Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(6),
child: FadeInImage(
image: NetworkImage(
e.thumbnail),
placeholder: AssetImage(""),
width: MediaQuery.of(context).size.width,
height: 250,
fit: BoxFit.cover,
),
),
],
),
),
);
}).toList(),
)
: LinearProgressIndicator(),
),
);
}
}
I see this error The argument type 'List?' can't be assigned to the parameter type 'List'. I try to fix this using a different way but I am not able to fix this issue.
try replacing exerciseJson?.exercises?.map
with exerciseJson!.exercises.map
, does it solve the error. else can you share the model.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.