Выпадающее меню Flutter выравнивает выделенный элемент и текст подсказки - PullRequest
0 голосов
/ 23 апреля 2020

У меня следующий код. У меня есть ListTile с текстом title и выпадающим списком trailing.

Card(
      elevation: 1,
      margin: EdgeInsets.only(bottom: 3),
      child: ListTile(
        title:Text("Item Type"),
        contentPadding:
            EdgeInsets.fromLTRB(10, 0, 10, 0),
        trailing: DropdownButtonHideUnderline(
            child: DropdownButton(
              isExpanded: false,
              value: selectedLeaveType,
              items: itemTypeList.map((item) {
                return new DropdownMenuItem(
                  child: new Text(item['item_name']),
                  value: item['item_id'],
                );
              }).toList(),
              onChanged: (value) {
                setState(() {
                  selectedLeaveType = value;
                });
              },
              hint: Align(
                alignment: Alignment.centerRight,
                child: Text(
                  "Select Item Type",
                  style: TextStyle(color: Colors.grey),
                ),
              ),
              style:
                  TextStyle(color: Colors.black, decorationColor: Colors.red),
            ),
          ),
        ),
      ),
    );

. Раскрывающийся список содержит элементы различной длины. Я хочу, чтобы Text был выровнен по левому краю и dropdown выровнен по правому краю.

Задача

Я хочу выровнять только текст подсказки и выделенный текст раскрывающегося списка для выравнивания вправо, но без везения.

Кто-нибудь поможет мне в этом ??

enter image description here

1 Ответ

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

Попробуйте увеличить ширину:

Card(
  elevation: 1,
  margin: EdgeInsets.only(bottom: 3),
  child: ListTile(
    title: Text("Item Type"),
    contentPadding: EdgeInsets.fromLTRB(10, 0, 10, 0),
    trailing: DropdownButtonHideUnderline(
      child: DropdownButton(
        isExpanded: false,
        value: true,
        items: itemTypeList.map((item) {
          return new DropdownMenuItem(

            child: Container(
              width: 150,                    //expand here
              child: new Text(
                item['item_name'],
                textAlign: TextAlign.end,
              ),
            ),
            value: item['item_id'],
          );
        }).toList(),
        onChanged: (value) {
          setState(() {
            selectedLeaveType = value;
          });
        },
        hint: Container(
          width: 150,                      //and here
          child: Text(
            "Select Item Type",
            style: TextStyle(color: Colors.grey),
            textAlign: TextAlign.end,
          ),
        ),
        style:
            TextStyle(color: Colors.black, decorationColor: Colors.red),
      ),
    ),
  ),
),

Результаты:

enter image description here

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...