[Mobile]/[Flutter]
[Flutter] 위젯 별로 공통 함수로 분류하기
CALLMESMITHMYNAME
2023. 7. 16. 01:02
반응형
플러터는 소스가 너무 길어진다.
그래서 관리하기도 어렵고 소스를 이해하기도, 유지보수하기도, 그리고...가독성도 떨어진다.
그래서 유틸성으로 개발해서 관리해보자
class WidgetUtil{
Widget getListView(List<Person> persons){
return ListView.builder(
shrinkWrap: true,
itemCount: persons.length,
itemBuilder: (BuildContext context,int index){
return Container(
height: 50,
child: Text(persons[index].id),
);
});
}
}
Container(
child: new WidgetUtil().getListView(persons),
)
,Container(
// group1ooX (5:11)
margin: EdgeInsets.fromLTRB(78*fem, 0*fem, 76*fem, 0*fem
위와 같이 사용하면 된다.
소스가 확연히 준것을 볼 수 있다. 그리고 파일로도 분리가 된다.
여러가지 재사용하기에도 용이해서 좋다.
반응형