본문 바로가기
Flutter

[Flutter] dropdown button text align to center

by hymndaniel 2022. 5. 4.

set property isExpanded to true
use Center widget with DropdownMenuItem class children.
IsExpanded will also take care of overflow.

 
DropdownButton(
     isExpanded: true,
     value: category_selected,
     items: categories.map<DropdownMenuItem<String>>((var value) {
        return DropdownMenuItem<String>(
          value: value["name"],
          child: Center(
                 child: Text(
                        value["name"],
                        textAlign: TextAlign.center,
                      ),
                    ),
                 );
           }).toList(),
      ),

 

Reference

https://stackoverflow.com/questions/56787244/how-to-center-text-in-dropdownbutton

 

How to center text in DropdownButton?

I'm trying to make the DropdownButton hint, text and menu items appear in the center instead of left but TextAlign.center does not seem to be doing anything. Image of Dropdown with the hint: Imag...

stackoverflow.com

 

728x90

'Flutter' 카테고리의 다른 글

[Flutter] list indexing  (0) 2022.05.04
[Flutter] string to int  (0) 2022.05.04
[Flutter] number format thousand separator  (0) 2022.05.02
[Flutter] image_picker 사용하기  (0) 2022.05.02
[Flutter] 이미지 데이터 서버에 업로드하기  (0) 2022.05.02