Dev/Flutter

Flutter DropdownButton 글자 중앙정렬

healthyryu 2023. 12. 16. 17:12

 

Flutter 에서 DropdowButton 의 텍스트를 중앙정렬 하기 위한 방법

 

1. DropdownButton 을 최대로 확장한다.

DropdownButton(
	 isExpanded: true,
     ...
 )

 

2. DropdownButton 의 DropdownMenuItem 에서 child 를 Center 로 감싸준다.

return DropdownMenuItem<String>(
      value: value,
      child: Center(
         child: Text(
                value,
                textAlign: TextAlign.center,
              ),
      ),
);

 

 

 

https://stackoverflow.com/a/63995395/3897810

 

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

 

반응형