颤动无法识别列表视图构建器中的列表属性
flutter can't recognize list atributes in listview builder
我想列出一些不同的烤肉店。我创建了一个列表,其中包含我需要的所有属性,但 flutter 无法识别或显示属性“name”或 Listview 构建器中的任何其他属性,
我不明白为什么我很欣赏每一个有用的命令。
错误:
The getter 'image' isn't defined for the type 'List Doener'.
并且此 Doenerscrollliste class 在 body 容器内。
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))),
),
);
}
}
和我的模型文件
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"),
];
你想在这种情况下获得特定图像,
替换
AssetImage(Doener_all.image)
与
AssetImage(Doener_all[index].image))
更多关于 List
。
我想列出一些不同的烤肉店。我创建了一个列表,其中包含我需要的所有属性,但 flutter 无法识别或显示属性“name”或 Listview 构建器中的任何其他属性,
我不明白为什么我很欣赏每一个有用的命令。
错误:
The getter 'image' isn't defined for the type 'List Doener'.
并且此 Doenerscrollliste class 在 body 容器内。
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))),
),
);
}
}
和我的模型文件
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"),
];
你想在这种情况下获得特定图像, 替换
AssetImage(Doener_all.image)
与
AssetImage(Doener_all[index].image))
更多关于 List
。