Skip to content

Instantly share code, notes, and snippets.

@emlanis
Last active March 15, 2020 11:58
Show Gist options
  • Select an option

  • Save emlanis/2a9c2b42354a5fefe42e208c2650c3ee to your computer and use it in GitHub Desktop.

Select an option

Save emlanis/2a9c2b42354a5fefe42e208c2650c3ee to your computer and use it in GitHub Desktop.
Testing Hausa Quiz codes using flutter and dart with no bool. Two options with one correct answer. Will update the code later to a full project
import 'package:flutter/material.dart';
void main() => runApp(Quizzler());
class Quizzler extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('HausaQuiz'),
backgroundColor: Colors.purpleAccent,
),
backgroundColor: Colors.grey.shade900,
body: SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: QuizPage(),
),
),
),
);
}
}
class QuizPage extends StatefulWidget {
@override
_QuizPageState createState() => _QuizPageState();
}
class _QuizPageState extends State<QuizPage> {
List<Icon> scoreKeeper = [];
List<String> questions = [
'Ban ci nanun ba...',
'Dan tuwon gobe...',
'Kowa ya tuna bara...',
'Kallo ya koma Kano...'
];
List<String> answers = [
'nanun ba zata ci ni ba.',
'ake wanke tukunya.',
'bai ji dadin bana ba.',
'ɓarawo ya kori sarki.'
];
List<String> incorrectOptions = [
'nanunta ci ni.',
'ake wanke kwano.',
'bai ji dadin aiki ba.',
'dutsen Dala ya koma Gwale.'
];
int questionNumber = 0;
int answerNumber = 0;
int incorrectOptionNumber = 0;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 5,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
questions[questionNumber],
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25.0,
color: Colors.white,
),
),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(15.0),
child: FlatButton(
textColor: Colors.white,
color: Colors.purpleAccent,
child: Text(
answers[answerNumber],
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: () {
//The user picked true.
String correctAnswer = answers[questionNumber];
// ignore: unrelated_type_equality_checks
if (correctAnswer == answerNumber) {
print('user got it wrong!');
} else {
print('user got it right');
}
setState(() {
questionNumber++;
answerNumber++;
incorrectOptionNumber++;
});
print(questionNumber);
},
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(15.0),
child: FlatButton(
color: Colors.purpleAccent,
child: Text(
incorrectOptions[incorrectOptionNumber],
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
onPressed: () {
//The user picked false.
String incorrectAnswer = incorrectOptions[incorrectOptionNumber];
// ignore: unrelated_type_equality_checks
if (incorrectAnswer == incorrectOptionNumber) {
print('user got it right!');
} else {
print('user got it wrong');
}
setState(() {
questionNumber++;
answerNumber++;
incorrectOptionNumber++;
});
print(questionNumber);
},
),
),
),
Row(
children: scoreKeeper,
),
],
);
}
}
/*
question1: 'Ban ci nanun ba...', 'nanun ba zata ci ni ba.',
question2: 'Dan tuwon gobe...', 'ake wanke tukunya.',,
question3: 'Kowa ya tuna bara...' 'bai ji dadin bana ba.',
question4: 'Kallo ya koma Kano...', 'ɓarawo ya kori sarki.'
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment