개발자의 공부방/모바일 17

Flutter] ListView or GridView 만들 때 팁

최근 강좌를 보면서 얻은 팁을 얘기해보습니다. 보통 ListView 위젯을 이용해서 레이아웃을 구성하면 잘 안되는 경우가 많습니다. item의 갯수는 10개인데 그 내용(자식의 내용)과 일치하지 않거나 혹은 높이가 무한이라서 발생되거나 등의 에러가 대표적입니다. 이런 경우 두가지 해결 방법이 있습니다. 1. shrinkWrap를 사용한다. 2. Expanded를 사용한다. 간단한 예제 코드 Widget build(BuildContext context) { return Scaffold( appBar: AppBar( elevation: 0, backgroundColor: Colors.white, centerTitle: true, title: const Text( '이미지 검색 앱', style: TextSt..

Flutter] Null Check, Null check operator used on a null value

Null에 관련된 부분을 신경써야한다. 예를 들어 아래와 같은 코드가 있다고 했을 때 Align( alignment: Alignment.center, child: ChartSvg( url: _marketMapNotifier.chartImageMap[ widget.tickerNotifier.ticker.currencyPair]!, widthRatio: chartWidthRatio, height: chartHeight, color: getColor(), ) ), _marketMapNotifier.chartImageMap에서 chartImageMap은 Map으로 선언되어 있다. String?은 Null을 허용하고 있다. 그런데 위에 코드에서 아래와 같이 !느낌표를 사용해서 Null을 허용하지 않게 만들었다. ..

Flutter] DropDownButton 위젯 properties

items: 항목을 정의할 수 있다. 드롭 메뉴/목록의 아이템을 정의할 수 있으며, 사용자가 선택할 수 있는 목록이다. (리스트) value: 선택된 값에 대한 것을 의미한다. style: 스타일 속성을 사용해서 글꼴 크기, 글꼴 두께 등과 같은 드롭다운 메뉴, 목록의 텍스트 스타일을 지정할 수 있다. alignment: 힌트나 선택한 항목이 버튼 내에서 배치되는 방식을 정의한다. elevation: 드롭다운 메뉴, 목록의 높이를 조정할 수 있다. icon: 버튼 아이콘을 정의한다. iconSize: 버튼 아이콘의 크기를 정의한다. iconDisabledColor: 드롭다운버튼을 비활성화 했을 때 아이콘 색상을 정의할 수 있다. iconEnabledColor: 드롭다운 버튼을 활성화했을 때 아이콘 색상을..

Flutter] Dropbutton의 underline을 없애보자.

...생략 DropdownButton( underline: SizedBox.shrink(), ) ...생략 드롭버튼을 만들면 화면에 기본적으로 언더라인이 붙는다. 이 부분을 삭제하는데 많은 방법이 있는 것 같으나 간단하게 위 방법을 선택했다. 참조 : https://stackoverflow.com/questions/53588785/remove-underline-from-dropdownbuttonformfield Remove underline from DropdownButtonFormField How can I remove the underline from DropdownButtonFormField (check photo below), I have tried various combinations of op..

Flutter] Checkbox를 동그라미로 커스텀해보자.

체크박스를 사용하는 경우가 상당히 많은데, 커스텀해서 사용하는 방법을 알아보자. Checkbox( value: true, onChanged: (bool? value) { print('체크박스'); }, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10)), checkColor: Colors.white, // fillColor: MaterialStateProperty.resolveWith(getColor), activeColor: Color(0xff06bbfb), materialTapTargetSize: MaterialTapTargetSize.padded, ), Checkbox에 shape을 이용하면 사각형 형태가 아래와 같이 구 ..

Flutter] DropdownButton을 눌렀을 때 목록 크기를 맞추는 방법.

DropdownButton으로 드롭박스를 만들었을 때 이런 식으로 width 사이즈가 작게 나와 있다. 근데 비율이라는 드롭박스를 누르면 나오는 목록의 크기가 위의 사이즈와 다르게 나온다. 이 부분을 같도록 만들어보자. 방법은 간단하다. 1. DropdownButton 위젯을 ButtonTheme으로 감싸준다. 2. ButtonTheme 위젯의 옵션 중 alignedDropdown을 true로 주면 된다. 이런식으로 목록의 사이즈가 달라짐을 확인할 수 있다. flutter 개어렵다....

Flutter] DropdownButton으로 DropBox 구현하기

final _valueList = ['최대', '50%', '25%', '15%', '10%']; String? _selectedValue; ... 생략 Container( child: DropdownButton( hint: Text('비율'), items: _valueList .map( (String item) => DropdownMenuItem( child: Text(item), value: item, ), ) .toList(), onChanged: (String? value) => setState(() { print('==> ${this._selectedValue}'); print('==> selected $value'); this._selectedValue = value; }), value: _s..