Coder Social home page Coder Social logo

helloflutter's People

Contributors

champaksworld avatar champaksworldcreate avatar

Watchers

 avatar

Forkers

shubhamgitvns

helloflutter's Issues

Simple Assignments

  1. Make an app to enter values shown on the screen
  2. Make an app to add two values if the user enters on textfield
  3. Make an app to show 1,2,3 on the screen if 3 is entered on a textfield
  4. Make an app to change values if the button pressed
  5. Make an app to incrementer or decrementer on icon taps

Current Code1

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);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.