我是Flutter的初学者,如何修复此代码?

时间:2019-10-12 19:34:33

标签: debugging flutter dart

a

我在这里得到加,减,乘的问题的随机数

b

这里我根据数学运算创建了不同类型的小部件

    import 'dart:math';

import 'package:dart_random_choice/dart_random_choice.dart';
import 'package:flutter/material.dart';

gameWin告知玩家是否通过数学运算并可以进入下一个级别

int num1 = Random().nextInt(100); 
int num2 = Random().nextInt(100);

List<String> typeOfQuestions = [
  'Addition',
  'Subtraction',
  'Multiplication',
  'Division'
];

Widget question;

初始化游戏是每当新游戏开始并选择一个 随机数学方程式

Map questions = {
  "Addition": AdditionWidget(
    num1: num1,
    num2: num2,
  ),
  "Subtraction": SubtractionWidget(
    num1: num1,
    num2: num2,
  ),
  "Multiplication": MultiplicationWidget(
    num1: num1,
    num2: num2,
  )
};

我不确定这里是否需要初始化,我只是以防万一

bool gameWin = false;

TextEditingController answerController;

checkansweriscorrect实际上表示答案正确,因为 玩家赢得了这场比赛,他可以进入下一个级别

initializeGame() {
  String typeOfQuestion = randomChoice(typeOfQuestions);

  switch (typeOfQuestion) {
    case 'Addition':
      {
        question = questions['Addition'];
      }
      break;
    case 'Subtraction':
      {
        question = questions['Subtraction'];
      }
      break;
    case 'Multiplication':
      {
        question = questions['Addition'];
      }
      break;
    default:
      {
        question = questions['Subtraction'];
      }
      break;
  }
}

class Game extends StatefulWidget {
  _GameState createState() => _GameState();
}

class _GameState extends State<Game> {

0 个答案:

没有答案