Флаттер - бесконечность контейнер - PullRequest
1 голос
/ 10 апреля 2020

Я пытаюсь создать тест с несколькими вариантами ответов во флаттере. Я хочу, чтобы 4 варианта ответа всегда были внизу страницы, независимо от размера вопроса. Проблема в том, что если вопрос достаточно длинный, чтобы «pu sh» 4 варианта ответа у боттима, это нормально, но если вопрос небольшой (как вы можете видеть на скриншоте), 4 варианта ответа «идут вверх», а не от вопроса. Поэтому я подумал, что было бы неплохо использовать бесконечный контейнер, но это не сработало. Есть ли у вас какие-либо идеи, что я должен сделать, чтобы "заблокировать" 4 варианта ответа в нижней части страницы? Спасибо. короткое текстовое изображение

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

class questionpage extends StatefulWidget {
  @override
  _questionpageState createState() => _questionpageState();
}

class _questionpageState extends State<questionpage> {

  int qnum = 0;
  int score = 0;
  int seconds = 10;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.indigoAccent[700],
        title: SafeArea(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Container(
                child: Text(
                  '$qnum/10        ',
                  style: TextStyle(
                    fontSize: 28,
                  ),
                ),
              ),
              Container(
                child: Text(
                  '$seconds',
                  style: TextStyle(
                    fontSize: 28,
                  ),
                ),
              ),
              Container(
                child: Text(
                  'Score: $score',
                  style: TextStyle(
                    fontSize: 28,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
      body: Column(children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
              child: Text(
                'Question $qnum:',
                style: new TextStyle(
                  color: Colors.black,
                  fontSize: 32.0,
                  fontWeight: FontWeight.bold,
                  decoration: TextDecoration.underline,
                  decorationThickness: 3.0,
                ),
              ),
            ),
          ],
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Flexible(
//              margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
              child: Container(
                margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
                //padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new Text(
                      'This is a short question:',
                      style: new TextStyle(
                          color: Colors.black,
                          fontSize: 26.0,
                          fontWeight: FontWeight.bold,
                      ),
                      textAlign: TextAlign.center,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
        Container(
          height: 80.0,
          margin: EdgeInsets.fromLTRB(10, 20, 10, 5),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(20.0),
            child: RaisedButton(
              onPressed: () {},
              child: Text(
                'Να αγωνίζονται σε ποδοσφαιρικές ομάδες όποιας χώρας ήθελαν',
                style: new TextStyle(
                    color: Colors.black,
                    fontSize: 21.0,
                    fontWeight: FontWeight.bold
                ),
                textAlign: TextAlign.center,
              ),
              color: Colors.amberAccent,
            ),
          ),
        ),
        Container(
          height: 80.0,
          margin: EdgeInsets.fromLTRB(10, 5, 10, 5),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(20.0),
            child: RaisedButton(
              onPressed: () {},
              child: Text(
                'Να επιλέξουν την υπηκοότητα που προτιμούσαν',
                style: new TextStyle(
                    color: Colors.black,
                    fontSize: 21.0,
                    fontWeight: FontWeight.bold
                ),
                textAlign: TextAlign.center,
              ),
              color: Colors.amberAccent,
            ),
          ),
        ),
        Container(
          height: 80.0,
          margin: EdgeInsets.fromLTRB(10, 5, 10, 5),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(20.0),
            child: RaisedButton(
              onPressed: () {},
              child: Text(
                'Να διακινούνται χωρίς έλεγχο διαβατηρίων στα σύνορα',
                style: new TextStyle(
                    color: Colors.black,
                    fontSize: 21.0,
                    fontWeight: FontWeight.bold
                ),
                textAlign: TextAlign.center,
              ),
              color: Colors.amberAccent,
            ),
          ),
        ),
        Container(
          height: 80.0,
          margin: EdgeInsets.fromLTRB(10, 5, 10, 5),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(20.0),
            child: RaisedButton(
              onPressed: () {},
              child: Text(
                'Να επιλέγουν τη χώρα στην οποία θα πληρώνουν φόρο εισοδήματος',
                style: new TextStyle(
                    color: Colors.black,
                    fontSize: 21.0,
                    fontWeight: FontWeight.bold
                ),
                textAlign: TextAlign.center,
              ),
              color: Colors.amberAccent,
            ),
          ),
        ),
      ],),
    );
  }
}

1 Ответ

0 голосов
/ 10 апреля 2020

Расширенный виджет может решить вашу проблему.

Добавить следующую строку после второго виджета строки.

      Expanded(child: Container()),

Следующий код также проясняет идею.

    Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Flexible(
//              margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
                child: Container(
                  margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
                  //padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      new Text(
                        'This is a short question:',
                        style: new TextStyle(
                          color: Colors.black,
                          fontSize: 26.0,
                          fontWeight: FontWeight.bold,
                        ),
                        textAlign: TextAlign.center,
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
          Expanded(child: Container()), // added line
          Container(
            height: 80.0,
            margin: EdgeInsets.fromLTRB(10, 20, 10, 5),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(20.0),
              child: RaisedButton(
                onPressed: () {},
                child: Text(
                  'Να αγωνίζονται σε ποδοσφαιρικές ομάδες όποιας χώρας ήθελαν',
                  style: new TextStyle(
                      color: Colors.black,
                      fontSize: 21.0,
                      fontWeight: FontWeight.bold),
                  textAlign: TextAlign.center,
                ),
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...