У меня проблема с итерацией для l oop для индекса json, и я ожидаю получить виджет для l oop. Я сохранил данные Json файла в переменной «mydata», а json имеет 3 индекса. В индексе 0 есть 17 вопросов, и ответы в индексе 2 соответственно. Я хочу напечатать их на карточке в следующем порядке: карточка 1: вопрос 1: «данные вопроса 1» ответ: «ответ на вопрос 1»
карточка 2: вопрос 2: «данные вопроса 2» ответ: Вопрос 2 Ответ "
Вот данные файла JSON:
[
{
"1": "Conjugation is facilitated by",
"2": "Bacterial endospores function in",
"3": "Pasteur's main achievements are the development of vaccines for diseases",
"4": "Germ theory of disease was formulated by",
"5": "The major locomotory structures in bacteria are",
"6": "Plasmid is",
"7": "Which of the following is a primary bacterial cell wall function",
"8": "When flagella surround the whole cell, the condition is called",
"9": "Bacterial membrane also contain enzyme for",
"10": "Which of the following is not found in all bacteria is",
"11": "Greater pathogenicity to bacteria and protection against phagocytosis is provided by",
"12": "Mesosomes are internal extensions of the",
"13": "Bacterial membrane differs from eukaryotic membrane in",
"14": "Which one of following class of bacteria has the smallest size",
"15": "Which of the following is present in both gram-positive and gram-negative cell walls",
"16": "Gram negaive cell wall has",
"17": "One of the following has flagella rarely"
},
{
"1": {
"a": "Capsule",
"b": "Pili",
"c": "Flagella",
"d": "Both pili and flagella"
},
"2": {
"a": "Reproduction",
"b": "Protein synthesis",
"c": "Survival",
"d": "Stronge"
},
"3": {
"a": "Cholera, rabies only",
"b": "Anthrax, rabies only",
"c": "Anthrax, fowl cholera and rabies",
"d": "None of the above"
},
"4": {
"a": "Antone Van Leeuwenhoek",
"b": "Pasteur",
"c": "Robert Koch",
"d": "none of above"
},
"5": {
"a": "Flagella",
"b": "Pili",
"c": "Both a and b",
"d": "None of these"
},
"6": {
"a": "Essential for bacterial growth and metabolism",
"b": "Drug resistant having disease and insect resistant gene",
"c": "Essential for bacterial growth only",
"d": "All of above"
},
"7": {
"a": "Transport",
"b": "Support",
"c": "Motility",
"d": "Adhesion"
},
"8": {
"a": "Peritrichous",
"b": "Atrichous",
"c": "Amphitrichous",
"d": "None of above"
},
"9": {
"a": "Respiration",
"b": "Photosynthesis",
"c": "Protein synthesis",
"d": "None of the above"
},
"10": {
"a": "Cell membrane",
"b": "A nucleoid",
"c": "Flygella",
"d": "None of these"
},
"11": {
"a": "Capsule",
"b": "Slime",
"c": "Cell wall",
"d": "Mesosomes"
},
"12": {
"a": "Cell wall",
"b": "Cell membrane",
"c": "Chromatin body",
"d": "Capsule"
},
"13": {
"a": "Lacking protein",
"b": "Lacking lipids",
"c": "Lacking polysaccharides",
"d": "Lacking sterol i.e. cholesterol"
},
"14": {
"a": "Bacillus subtilis",
"b": "Mycoplasma",
"c": "E-coli",
"d": "Straptococci"
},
"15": {
"a": "An outer membrane",
"b": "Peptidoglycan",
"c": "Techoic acid",
"d": "Lipopolysaccharides"
},
"16": {
"a": "Only lipids",
"b": "Only protein",
"c": "More lipids and less protein",
"d": "Less lipids and more protein"
},
"17": {
"a": "Diplobacilli",
"b": "Spiral",
"c": "Cocci",
"d": "All of above"
}
},
{
"1": "Pili",
"2": "Survival",
"3": "None of the above",
"4": "Robert Koch",
"5": "Flagella",
"6": "Drug resistant having disease and insect resistant gene",
"7": "Support",
"8": "Peritrichous",
"9": "Respiration",
"10": "Flygella",
"11": "Slime",
"12": "Cell membrane",
"13": "Lacking sterol i.e. cholesterol",
"14": "Mycoplasma",
"15": "Peptidoglycan",
"16": "More lipids and less protein",
"17": "Cocci"
}
]
Вот мой код:
class ResultPage extends StatelessWidget {
int marks;
int i = 1;
var mydata;
var length;
ResultPage(this.marks, this.mydata, this.length);
@override
Widget build(BuildContext context) {
return FinalResultCard(marks: marks, mydata: mydata, length: length,);
}
}
class FinalResultCard extends StatefulWidget {
int marks;
int i = 1;
var mydata;
var length;
FinalResultCard({Key key, this.length, this.mydata, this.marks} ) : super(key: key);
@override
_FinalResultCardState createState() => _FinalResultCardState(length, mydata, marks);
}
class _FinalResultCardState extends State<FinalResultCard> {
int marks;
int i = 1;
var mydata;
var length;
_FinalResultCardState(this.length, this.mydata, this.marks);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Appbar ")
),
body: Container(
color: Colors.red,
child: ListView.builder
(
itemCount: 1,
itemBuilder: (BuildContext ctxt, int index) {
for(int i = 1; i<length; i++){
var data = mydata[0][i.toString()];
}
return Text(data);
}),
),
);
}
}
I не то, что я делаю здесь неправильно. Нужна помощь и заранее спасибо.