Skip to content

Instantly share code, notes, and snippets.

@masterashu
Last active March 24, 2020 09:32
Show Gist options
  • Save masterashu/f917680f60572fe1ca44830da437fcd9 to your computer and use it in GitHub Desktop.
Save masterashu/f917680f60572fe1ca44830da437fcd9 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class Question {
String ques;
List<String> options;
Question(this.ques, this.options);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<Question> data = [
Question("Ques1", <String>["OPt1", "Opt 2"]),
Question("Ques1", <String>["OPt1", "Opt 2", "Opt3"]),
Question("Ques1", <String>["OPt1", "Opt 2"]),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
child: ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
var options = <Widget>[];
for (var x in data[index].options) {
options.add(Text(x));
}
return Card(
child: Column(children: [
Text(data[index].ques),
Divider(),
Column(children: options)
]),
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment