varanasi-software-junction / helloflutter Goto Github PK
View Code? Open in Web Editor NEWStarting a Flutter Series
License: MIT License
Starting a Flutter Series
License: MIT License
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'MCQ Quiz';
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: _title,
home: Scaffold(
appBar: AppBar(
title: const Text(_title),
centerTitle: true,
),
body: Center(
child: MyStatefulWidget(),
),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({super.key});
String question = "Which state has the capital Lucknow?";
int questionno = -1;
int correctanswers = 0;
bool isTestOver = false;
List questions = QuestionArray.questions;
Question? currentquestion;
List scores = [];
void setQuestion(bool b) {
//isTestOver=false;
//questionno=-1;
//scores.clear();
if (isTestOver) return;
if (questionno == -1) {
questionno++;
currentquestion = questions[questionno];
return;
}
if (questionno >= questions.length - 1) {
addResult(b);
isTestOver = true;
return;
}
addResult(b);
questionno++;
if (questionno <= questions.length - 1) {
currentquestion = questions[questionno];
}
}
void addResult(bool b) {
bool iscorrect = b == currentquestion!.correctAnswer;
//scores.clear();
if (iscorrect) {
correctanswers++;
scores.add(const Icon(Icons.check, color: Colors.green));
} else {
scores.add(const Icon(Icons.close, color: Colors.red));
}
}
@OverRide
State createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State {
int result = 0;
@OverRide
Widget build(BuildContext context) {
return Column(
children: [
Expanded(child: Text("Result $result")),
Expanded(child: Text(widget.question)),
Row(
children: [
Expanded(
child: ListTile(
title: const Text('Uttar Pradesh'),
leading: Radio(
value: 1,
groupValue: result,
onChanged: (int? value) {
setState(() {
result = value!;
});
},
),
),
),
Expanded(
child: ListTile(
title: const Text('Bihar'),
leading: Radio(
value: 3,
groupValue: result,
onChanged: (int? value) {
setState(() {
result = value!;
});
},
),
),
),
],
),
Row(
children: [
Expanded(
child: ListTile(
title: const Text('Punjab'),
leading: Radio(
value: 2,
groupValue: result,
onChanged: (int? value) {
setState(() {
result = (value == null) ? 0 : value;
});
},
),
),
),
Expanded(
child: ListTile(
title: const Text('Himachal Pradesh'),
leading: Radio(
value: 4,
groupValue: result,
onChanged: (int? value) {
setState(() {
result = value!;
});
},
),
),
),
],
),
SizedBox(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.teal,
minimumSize: const Size.fromHeight(5),
),
child: const Text(
'Submit',
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
onPressed: () {
print("Submitted False");
},
),
),
),
],
);
}
}
class QuestionArray {
static List questions = [
Question("What is the capital of UP?", "Lucknow", "Delhi", "Tokyo",
"Sundarpur", 1),
Question("Who is the prime minister of Japan?", "Donald Trump",
"Puspha Kamal Dahal", "Bhimsen Thapa", "Fumio Kishida", 1),
Question("What is the world largest Economy?", "India", "USA", "Japan",
"Germany", 2),
Question("The World,s best Education system", "United States", "Australia",
"United Kingdom", "Canada", 3),
];
}
class Question {
String question = "";
String opt1 = "", opt2 = "", opt3 = "", opt4 = "";
int correctAnswer = 0;
Question(this.question, this.opt1, this.opt2, this.opt3, this.opt4,
this.correctAnswer);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.