Как я могу добавить кнопку над списком?

Я попытался добавить RaisedButton над ListView. Я использовал Colum, но получил ошибку. Кто-нибудь может сказать мне, в чем моя ошибка? Заранее спасибо!

 body: Column(
        children: <Widget>[
          RaisedButton(
            child: Text("Test"),
            onPressed: null,
          ),
          ListView.builder(
            itemCount: exercises.length,
            itemBuilder: (context, i) {
              return Container(
                child: Text(
                  exercises[i]["text"],
                ),
              );
            },
          ),
        ],
      ),

person simi    schedule 15.05.2020    source источник


Ответы (2)


Добавляя к ответу @Viren, вы должны использовать Гибкий вместо Расширенного

body: Column(
        children: <Widget>[
          RaisedButton(
            child: Text("Test"),
            onPressed: null,
          ),
          Flexible(
            child: Container(
              child: ListView.builder(
                itemCount: 5,
                itemBuilder: (context, i) {
                  return Container(
                    child: Text(
                      'jitesh',
                    ),
                  );
                },
              ),
            ),
          )
        ],
      ),

Найдите diff Flutter: Expanded vs Flexible

person Jitesh Mohite    schedule 15.05.2020

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

     body: Column(
    children: <Widget>[
      RaisedButton(
        child: Text("Test"),
        onPressed: null,
      ),
      Expanded( // added widget
     child: ListView.builder(
        itemCount: exercises.length,
        itemBuilder: (context, i) {
          return Container(
            child: Text(
              exercises[i]["text"],
            ),
          );
        },
      ),
    ],
  ),
  )
person Viren V Varasadiya    schedule 15.05.2020