import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: QuizPage(),
);
}
}
class QuizPage extends StatefulWidget {
@override
_QuizPageState createState() => _QuizPageState();
}
class _QuizPageState extends State {
int score = 0;
String question = 'Кез келген адам мобильді қосымша жасай алады ма?';
bool correctAnswer = true;
void checkAnswer(bool userAnswer) {
if (userAnswer == correctAnswer) {
setState(() {
score++;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Тест'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
question,
style: TextStyle(fontSize: 24),
textAlign: TextAlign.center,
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
checkAnswer(true);
},
child: Text('Ия'),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
checkAnswer(false);
},
child: Text('Жоқ'),
),
SizedBox(height: 20),
Text(
'Ұпай: $score',
style: TextStyle(fontSize: 18),
),
],
),
),
);
}
}