Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

flutter: how to stop dropdown button text from moving with different length

So I have a dropdown button, but the item text has different length, so when I choose different item, the text moves to a different position like shown in the picture. How should I fix that?
enter image description here

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the code:

Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        DropdownButton<TaskAssort>(
            value: _selected,
            icon: const Icon(Icons.arrow_drop_down),
            style: const TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
              color: Colors.black,
              decoration: TextDecoration.none,
            ),
            isExpanded: true,
            onChanged: (TaskAssort? v) {
              _selected = v!;
              setState(() {});
            },
            items: [
              DropdownMenuItem(
                value: TaskAssort.Unfinished,
                child: Text(getAssortText(TaskAssort.Unfinished),
                    textAlign: TextAlign.end),
              ),
              DropdownMenuItem(
                value: TaskAssort.UnfinishedDaily,
                child: Text(getAssortText(TaskAssort.UnfinishedDaily),
                    textAlign: TextAlign.end),
              ),
              DropdownMenuItem(
                value: TaskAssort.Histroy,
                child: Text(getAssortText(TaskAssort.Histroy),
                    textAlign: TextAlign.end),
              ),
            ]),
      ],
    ),

>Solution :

Set alignment of DropdownButton

alignment: Alignment.centerRight
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading