I am trying to create a quizapp in which i create cards, like when user click on specific card then it will be redirect to that quizpage.
here is the where i am trying to get json file data which are quiz questions
class getjson extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future:DefaultAssetBundle.of(context).loadString("assets/questions/generalQ.json"),
builder: (context, snapshot) {
List mydata = json.decode(snapshot.data.toString());
print(mydata);
if (mydata == null) {
return Scaffold(
body: Center(
child: Text(
"Loading",
),
),
);
} else {
return quizpage();
}
},
);
}
}
class quizpage extends StatefulWidget {
@override
_quizpageState createState() => _quizpageState();
}
class _quizpageState extends State<quizpage> {
@override
Widget build(BuildContext context) {
return Container(
);
}
}
and here i created cards widgets
Widget customcard(String langname, String image, String des){
return Padding(
padding: EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 30.0,
),
child: InkWell(
onTap: (){
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context)=>getjson(),));
},
i am calling getjson class on the onTap.
when i run the app click on card it shows me "loading", it is returning null on "mydata" of getjson class.
how to fix it? why it's returning null on mydata? Please help!
JSON FILE:
[
{
"1": "What is the world's most populated country?",
"2": "Each year World Red Cross and Red Crescent Day is celebrated on",
"3": "The ozone layer restricts"
},
{
"1": {
"a": "Russia",
"b": "China",
"c": "USA"
},
"2": {
"a": "May 8",
"b": "May 18",
"c": "April 28"
},
"3": {
"a": "Visible light",
"b": "Ultraviolet radiation",
"c": "Infrared radiation"
}
}
]