Flutter
[Flutter] 커스텀 위젯 변수 넘기기
유호야
2022. 12. 4. 02:51
반응형
class InfoButton extends StatelessWidget {
// const InfoButton({Key? key}) : super(key: key);
final String info;
InfoButton(this.info);
@override
Widget build(BuildContext context) {
return TextButton(onPressed: (){},
child: Text('$info',
style: TextStyle(color: Colors.grey)),
style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.grey[200]),),
);
}
}
디자인이 같은 Icon 버튼을 재사용하고 싶어서 커스텀 위젯을 위와 같이 만들었고
버튼에 들어갈 내용만 받아서 같은 모양의 버튼이 출력되게 했다.
Row(
children: [
InfoButton('자기개발'),
SizedBox(width: 3),
InfoButton('실무 능력 향상'),
],
),
반응형