Мне нужно установить метод для моих карт, чтобы показать правильный ответ перед переходом на следующую страницу - PullRequest
0 голосов
/ 30 октября 2019

У меня есть несколько карточек ответов на моей странице, которые я намерен дать пользователю возможность выбирать 2 раза, а не один раз. Если пользователь выбирает верный ответ, карта становится зеленой и переходит к следующему вопросу, но если она неверна, в первый раз выбранная карта становится красной, второй ответ: если true =>, она становится зеленой и все правильно,если false =>, он становится красным и идет прямо на следующую страницу, вот моя проблема, и я не могу найти способ показать правильный (я хочу, чтобы грин-карту показывали) ответ перед переходом на следующую страницу`

class PageV1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var y = (MediaQuery.of(context).size.height);
    return Container(
        child: MaterialApp(
            home: Scaffold(
                resizeToAvoidBottomPadding: true,
                body: Column(children: <Widget>[
                  //Container(
                  //height: 100.0,
                  //color:Color(0xffa3bb7f),
                  //child:                                                                                           IconTheme(c1:Color(0xff457356),c2:Colors.black38,c3: Colors.black38,),
              //),
              Container(
                  height: y / 2,
                  child: ClipPath(
                      clipper: MyShape(),
                      child: Container(
                          color: Color(0xffa3bb7f),
                          child: Column(children: <Widget>[
                            SizedBox(
                              height: 50.0,
                            ),
                            AnimateTop(),
                            SizedBox(
                              height: 40.0,
                            ),
                            Question(
                                ' 1.$k  ', 'Coming after something else'),
                          ])))),
              Answers(
                'Assessment',
                1,
                Q2(),
              ),
              Answers(
                'Subsequent',
                2,
                Q2(),
              ),
              Answers(
                'Accordance',
                1,
                Q2(),
              ),
              Answers(
                'Controversial',
                1,
                Q2(),
              ),
            ]))));
  }
}



class Answers extends StatefulWidget {
  var ans;
  var j;
  var p;

  Answers(this.ans, this.j, this.p);

  @override
  _AnswersState createState() => _AnswersState();
}

class _AnswersState extends State<Answers> {
  var c;
  var d = Color(0xffa3bb7f);

  @override
  Widget build(BuildContext context) {
    var x = (MediaQuery.of(context).size.width);
    var y = (MediaQuery.of(context).size.height);
    return Container(
        height: y / 11,
        width: x - 40.0,
        color: Colors.transparent,
        child: GestureDetector(
            onTap: () {
              if (widget.j == 1) {
                setState(() {
                  c = Colors.red;
              d = Colors.white;
              q = q + 1;
            });
          }
          if (q % 2 == 0) {
            setState(() {
              c = Colors.red;
              d = Colors.white;
            });
            Future.delayed(const Duration(milliseconds: 300), () {
              setState(() {
                Navigator.push(context,
                    new MaterialPageRoute(builder: (context) =>           widget.p));
                if (widget.j == 2) {
                  c = Colors.green;
                  d = Colors.white;
                }
              });
            });
          } else if (widget.j == 2) {
            setState(() {
              c = Colors.green;
              d = Colors.white;
              q = 0;
            });
            correct = correct + 1;
            Future.delayed(const Duration(milliseconds: 300), () {
              setState(() {
                Navigator.push(context,
                     new MaterialPageRoute(builder: (context) =>     widget.p));
              });
            });
          }
        },
        child: Card(
          color: c,
          child: Container(
              alignment: Alignment.center,
              color: Colors.white60,
              padding: const EdgeInsets.symmetric(horizontal: 20.0),
              child: Wrap(children: <Widget>[
                Text(
                  widget.ans,
                  style: TextStyle(
                      fontSize: 17.0,
                      fontFamily: 'Raleway',
                      fontWeight: FontWeight.w700,
                      color: d), //Colors.black,),
                    )
                  ])),
             )));
      }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...