I want to make a list that shows some different kebab stores. I created a list with all the attributes i needed but flutter cant recognize or display the attribute "name" or any other attribute in the Listview builder and
I can't figure out why I appreciate every helpful command.
the error:
The getter 'image' isn't defined for the type 'List Doener'.
and this Doenerscrollliste class is inside a body container.
class DoenerScrollListe extends StatefulWidget {
const DoenerScrollListe({Key? key}) : super(key: key);
@override
State<DoenerScrollListe> createState() => _DoenerScrollListeState();
}
class _DoenerScrollListeState extends State<DoenerScrollListe> {
late PageController _pageController;
int initialPage = 1;
@override
void initState() {
super.initState();
_pageController = PageController();
}
@override
void dispose() {
super.dispose();
_pageController.dispose();
}
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: Doener_all.length,
scrollDirection: Axis.vertical,
addAutomaticKeepAlives: false,
shrinkWrap: true,
itemBuilder: (context, index) => Container(
height: 120,
width: double.infinity,
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.orange[400],
image: DecorationImage(image: AssetImage(Doener_all.image))),
),
);
}
}
and my model file
import 'package:flutter/material.dart';
class Doener {
final String name;
final String image;
final String ratingImage;
final String price;
final String describtion;
Doener({
required this.name,
required this.image,
required this.ratingImage,
required this.price,
required this.describtion,
});
}
// ignore: non_constant_identifier_names
List<Doener> Doener_all = [
Doener(
name: "Rüyam",
image: "assets/images/Ryam.jpg",
ratingImage: "dsd",
price: "4,10",
describtion: "Sehr guter Döner Top Preis Leistung"),
Doener(
name: "Pamfeliya",
image: "assets/images/Pamfilya.jpg",
ratingImage: "asdaa",
price: "4,10",
describtion: "Bestes Fleisch",
),
Doener(
name: "K'Ups",
image: "assets/images/KUps.jpg",
ratingImage: "sdsd",
price: "4,10",
describtion: "Guter Döner"),
];
CodePudding user response:
You like to get specific image in this case, replace
AssetImage(Doener_all.image)
with
AssetImage(Doener_all[index].image))
More about List
.