Sie sind auf Seite 1von 4

Main.

dart

1. import 'package:flutter/cupertino.dart';
2. import 'package:flutter/material.dart';
3. import 'package:flutter_app/answer.dart';
4. import './question.dart';
5. import './answer.dart';
6.
7. void main() {
8. runApp(MyApp());
9. }
10.
11. //void main() => runApp(MyApp());
12. class MyApp extends StatefulWidget {
13. @override
14. _MyAppState createState() => _MyAppState();
15. }
16.
17. class _MyAppState extends State<MyApp> {
18. var _questionIndex = 0;
19.
20. void _answerQuestion() {
21. setState(() {
22. _questionIndex = _questionIndex + 1;
23. });
24. }
25.
26. @override
27. Widget build(BuildContext context) {
28. var questions = [
29. {
30. 'questionText': 'What\'s fevourite color?',
31. 'answer': ['black', 'Red', 'Green', 'White'],
32. },
33. {
34. 'questionText': 'WHat\'s your favourite animals?',
35. 'answer': ['Bat', 'Caw,', 'Goat', 'Tiger'],
36. },
37. {
38. 'questionText': 'WHat\'s your favourite Witer?',
39. 'answer': ['Tagor', 'Sarat,', 'Sunil', 'Taslima'],
40. },
41. ];
42. return MaterialApp(
43. home: Scaffold(
44. appBar: AppBar(
45. title: Text('My First App'),
46. ),
47. body: Column(
48. children: [
49. Question(
50. questions[_questionIndex]['questionText'],
51. ),
52. ...(questions[_questionIndex]['answer'] as List<String>)
53. .map((answer) {
54. return Answer(_answerQuestion, answer);
55. }).toList()
56. ],
57. ),
58. ),
59. );
60. }
61. }
62.
Question.dart

1. import 'package:flutter/material.dart';
2.
3. class Question extends StatelessWidget {
4. final String questionText;
5. Question(this.questionText);
6.
7. @override
8. Widget build(BuildContext context) {
9. return Container(
10. width: double.infinity,
11. margin: EdgeInsets.all(10),
12. child: Text(
13. questionText,
14. style: TextStyle(fontSize: 28),
15. textAlign: TextAlign.center,
16. ),
17. );
18. }
19. }
20.
21.
22.
23.
Answer.Dart

1. import 'package:flutter/material.dart';
2.
3. class Answer extends StatelessWidget {
4. final Function selectHandler;
5. final String answerText;
6.
7. Answer(this.selectHandler, this.answerText );
8. @override
9. Widget build(BuildContext context) {
10. return Container(
11. width: double.infinity,
12. child: RaisedButton(
13. color: Colors.pinkAccent,
14. textColor: Colors.white ,
15. child: Text(answerText),
16. onPressed:selectHandler,
17. ),
18. );
19. }
20. }
21.
22.
23.

Das könnte Ihnen auch gefallen