1

an app should be compatible for different screen formats. The portrait mode is set, therefore the landscape mode does not have to be observed.

The content is arranged in a Column () widget. All content - widgets except both ListView.builder have a fixed height.

Is it possible to arrange both ListView.builder in a widget like Expanded so that both expand evenly on the available space and you can still scroll extra in both?

Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              _showQuestionTheme(),
              _showQuestion(), //ListView.builder, which should expand 
              _showAnswers(), //ListView.builder, which should expand
              _buildAnswerButton(),
              _buildGameStatusTextfields(),
              _progressBarAnswerTimeLeft(),
            ],
          ),

3 Answers 3

1

Widgets like a listView always needs a predefined height and width. You can Wrap Listview inside a container and then, Give container a dynamic height: (elements in the list) * (Height of each element) I hope this trick will work for you.

for example:

Container(
height:litems.length*20,
child:ListView.builder
  (
    itemCount: litems.length,
    itemBuilder: (BuildContext ctxt, int index) {
     return Container(height:20,
             child:Text(litems[index]));
    }
  )
)
Sign up to request clarification or add additional context in comments.

Comments

1

Hope this will work for you :)

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("LIST VIEW:1",style: TextStyle(fontWeight: FontWeight.bold),),
              SizedBox(height: 20,),
             Expanded(
              //  flex: 1,
               child:Container(
                 decoration: BoxDecoration(
                   border: Border.all(color: Colors.black),
                   color: Colors.green,
                 ), 
                 height: 20,
                 child: ListView.builder(
                   itemCount: 20,
                   itemBuilder: (context, index){
                     return Card(
                       child: ListTile(
                         title: Text("Name"),
                          subtitle: Text("SubNME"),
                        ),
                      );
                    }
                  ),
                )
              ),
              SizedBox(height: 20,),
               Text("LIST VIEW:2",style: TextStyle(fontWeight: FontWeight.bold)),
              SizedBox(height: 20,),
              Expanded(
               child:Container(
                 decoration: BoxDecoration(
                   border: Border.all(color: Colors.black),
                   color: Colors.red,

                 ),

                 height: 20,
                 child: ListView.builder(
                   itemCount: 20,
                   itemBuilder: (context, index){
                     return Card(
                       child: ListTile(
                         title: Text("Title"),
                          subtitle: Text("Subtitle"),
                       ),
                     );
                    }
                  ),
                )
              )
            ],
          ),
        ),
      ),   
    );
  }
}

enter image description here

1 Comment

Great. Working.
0

use this for both ListView:

Container(
        height: MediaQuery.of(context).size.height*0.5,
    child:YOUR_LISTVIEW
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.