简体   繁体   English

Flutter - 在两个固定容器之间插入一个 Listview

[英]Flutter - Insert a Listview between two fixed containers

This particular screen is composed of a large container (Height of screen): This container is composed of three parts: A header (fixed container: 10% of screen size), a footer (fixed container: 10% of screen size) and a middle part: container: height of 80% of screen size.这个特定的屏幕由一个大容器(屏幕高度)组成:这个容器由三部分组成:一个 header(固定容器:屏幕大小的 10%)、一个页脚(固定容器:屏幕大小的 10%)和一个中间部分:容器:高度为屏幕尺寸的 80%。 I would like the middle container to be scrollable: so I inserted a LISTVIEW as the child of this container... but it keeps telling me I get a RenderFlex overflowed.... Why doesn't the content of the middle container scroll in between the header and the footer??我希望中间容器是可滚动的:所以我插入了一个 LISTVIEW 作为这个容器的子级......但它一直告诉我我得到一个 RenderFlex 溢出......为什么中间容器的内容不滚动header 和页脚之间?

Here is the code:这是代码:

Scaffold(
      backgroundColor: Colors.indigo[900],
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        automaticallyImplyLeading: false,
        leading: IconButton(
            icon: Icon(Icons.arrow_back_ios_rounded,
                color: Colors.red[400], size: 25.0),
            onPressed: () {
              uD.clearSearchList();
              Navigator.pushReplacementNamed(context, StudentHomeScreen.id);
            }),
        title: Text(
          'ETAPE 1 - Découverte',
          style: TextStyle(color: Colors.indigo[900], fontSize: 22),
        ),
        actions: [
          Container(
            margin: const EdgeInsets.only(right: 10),
            child: Icon(Icons.memory, size: 45, color: Colors.red[900]),
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Container(
          height: MediaQuery.of(context).size.height,
          decoration: BoxDecoration(
            color: Colors.orange[50],
            borderRadius: BorderRadius.circular(10.0),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                height: (MediaQuery.of(context).size.height) * 0.12,
                padding: const EdgeInsets.fromLTRB(12, 12, 12, 0),
                decoration: BoxDecoration(
                  color: Colors.orange[100],
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10),
                    topRight: Radius.circular(10),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          'Activité 1',
                          style: TextStyle(
                              color: Colors.red[900],
                              fontSize: 30,
                              fontWeight: FontWeight.bold),
                        ),
                        Text(
                          'Mot n°1/24',
                          style: TextStyle(
                            color: Colors.indigo[900],
                            fontSize: 17.0,
                          ),
                        ),
                      ],
                    ),
                    SleekCircularSlider(
                      appearance: CircularSliderAppearance(
                          infoProperties: InfoProperties(
                            modifier: (reussite) {
                              return '${reussite.toInt()} / 5';
                            },
                            bottomLabelText: 'Réussite',
                            bottomLabelStyle:
                                TextStyle(fontSize: 12, color: Colors.red[900]),
                          ),
                          size: 90,
                          customColors: CustomSliderColors(
                              progressBarColor: Colors.green[900]),
                          customWidths:
                              CustomSliderWidths(progressBarWidth: 8)),
                      min: 0,
                      max: 5,
                      initialValue: reussite <= 5 ? reussite : 5,
                    )
                  ],
                ),
              ),
              Container(
                height: (MediaQuery.of(context).size.height) * 0.8,
                child: ListView(
                  shrinkWrap: true,
                  children: [
                    Container(
                      padding: EdgeInsets.all(12.0),
                      margin: const EdgeInsets.only(top: 8),
                      child: Text(
                        'Ecoute et répète 5 fois le mot en anglais.',
                        style:
                            TextStyle(color: Colors.indigo[700], fontSize: 17),
                      ),
                    ),
                    Container(
                      margin: const EdgeInsets.all(12),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        border: Border.all(
                          width: 1.0,
                        ),
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                      padding: const EdgeInsets.only(top: 16),
                      child: Row(
                        children: [
                          Container(
                            height: 200,
                            child: Image.asset(
                              'images/avatar_teacher.jpeg',
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.all(24.0),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Container(
                                  child: Text(
                                    'An adult',
                                    style: TextStyle(
                                      color: Colors.red[900],
                                      fontSize: 23,
                                    ),
                                  ),
                                ),
                                Container(
                                  margin: const EdgeInsets.only(bottom: 60),
                                  child: Text(
                                    'Un adulte',
                                    style: TextStyle(
                                      color: Colors.indigo[900],
                                      fontSize: 15,
                                    ),
                                  ),
                                ),
                                GestureDetector(
                                  child: Container(
                                    height: 45,
                                    margin:
                                        EdgeInsets.fromLTRB(0, 5.0, 0, 15.0),
                                    alignment: Alignment.topRight,
                                    child: Icon(
                                      Icons.volume_up,
                                      color: Colors.indigo[500],
                                      size: 55.0,
                                    ),
                                  ),
                                  onTap: () {
                                    Tts.speak(
                                        phrase: 'little',
                                        langue: Language.english);
                                  },
                                ),
                                Container(
                                  alignment: Alignment.topRight,
                                  child: Text('/adult/'),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      height: 80,
                      margin: const EdgeInsets.symmetric(vertical: 20),
                      alignment: Alignment.center,
                      child: IconButton(
                          icon: Icon(
                            Icons.mic,
                            color: Colors.red[900],
                            size: 50,
                          ),
                          onPressed: () async {
                            uD.checkSpokenWords('adult', reussite);
                          }),
                    ),
                    Container(
                      alignment: Alignment.center,
                      child: Text(
                        'Clique sur le micro et répète le mot',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                          color: Colors.black45,
                          fontSize: 15.0,
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 50.0,
                    ),
                    Container(
                      width: double.infinity,
                      alignment: Alignment.centerLeft,
                      margin: const EdgeInsets.only(top: 12),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        border: Border.all(
                          width: 1.0,
                        ),
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Row(
                          children: [
                            Text('Voici ce que j\'ai compris : '),
                            Text(uD.spokenWords),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                height: (MediaQuery.of(context).size.height) * 0.08,
                padding: const EdgeInsets.all(12),
                decoration: BoxDecoration(
                  color: Colors.orange[100],
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(10),
                    bottomRight: Radius.circular(10),
                  ),
                ),
                margin: const EdgeInsets.only(top: 8),
                child: RoundedProgressBar(
                    milliseconds: 1000,
                    childLeft: Text(
                      'Réussite de l\'activité : ',
                      style: TextStyle(color: Colors.indigo[900]),
                    ),
                    childRight: Text("$reussite%",
                        style: TextStyle(color: Colors.red[900])),
                    percent: reussite,
                    theme: RoundedProgressBarTheme.blue),
              ),
            ],
          ),
        ),
      ),
    );

You should replace the middle Container (the one with the 0.8 * MediaQuery height) with Expanded so it will take the available space between the 2 other Containers.您应该用 Expanded 替换中间的 Container(高度为 0.8 * MediaQuery 的那个),这样它将占用其他 2 个 Container 之间的可用空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM