【问题标题】:Flutter - Infinity containerFlutter - 无限容器
【发布时间】:2020-07-23 03:50:51
【问题描述】:

我正在尝试在 Flutter 中创建多项选择测验。我希望 4 个答案选项始终位于页面底部,无论问题大小如何。问题是如果问题足够长“推”底部的 4answer 选项很好,但如果问题很小(如您在屏幕截图中看到的),则 4 个答案选项是“上升”,从问题下降。所以我认为使用无限容器是个好主意,但它没有用。你有什么想法我应该做些什么来“锁定”页面底部的 4 个答案选项?谢谢你。 short text image

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,
            ),
          ),
        ),
      ],),
    );
  }
}

【问题讨论】:

    标签: flutter dart widget containers infinity


    【解决方案1】:

    扩展的小部件可以解决您的问题。

    在第二个 Row 小部件之后添加以下行。

          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,
                    ),
    

    【讨论】:

      猜你喜欢
      • 2021-03-08
      • 2020-05-06
      • 2017-09-27
      • 1970-01-01
      • 2021-12-22
      • 2014-03-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多