Oui c’est ça @Xababa_Dalabama mais dans un initState
pour initialiser ta var
à la construction de ton State
Si tu veux savoir pourquoi, je te laisse te renseigner dans la doc
Du coup ça te donne ça :
class DetailImageSliderWidget extends StatefulWidget {
final List<String> posterPathList;
const DetailImageSliderWidget({required this.posterPathList, Key? key}) : super(key: key);
@override
State<DetailImageSliderWidget> createState() => _DetailImageSliderWidgetState();
}
class _DetailImageSliderWidgetState extends State<DetailImageSliderWidget> {
late List<String> posterPathListState;
@override
void initState() {
// TODO: implement initState
posterPathListState = widget.posterPathList;
super.initState();
}
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: widget.posterPathList.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(posterPathListState[index]),
);
},
);
}
}