화면
각각의 플러스를 누르면 각각의 숫자에 따라 +1씩 늘어남
class MyApp extends StatefulWidget {
MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var a = 1;
var name = ['구정모', '김기현', '예식이'];
var like = [0, 0, 0];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('앱이름')),
body: ListView.builder(
itemCount: 3,
itemBuilder: (c, i) {
return ListTile(
leading: Text(like[i].toString()),
title: Text(name[i]),
trailing: IconButton(onPressed: (){
setState(() {
like[i]++;
});
}, icon: Icon(Icons.add)),
);
},
),
),
);
}
}
훗날 좀 더 활용해서,
좋아요기능을 만들 수 있겠다.
좋아요 상태이면 해제하고
좋아요 해제상태이면 좋아요로 변경 될 수 있도록.
'백엔드개발자 > FLUTTER, DART' 카테고리의 다른 글
[Flutter] TextEditingController, 사용자 입력한 값, 자식위젯에서 부모위젯 상태변경 (0) | 2023.01.24 |
---|---|
[Flutter] FloatingActionButton , showDialog, Dialog (0) | 2023.01.24 |
[Flutter] type 'MyApp' is not a subtype of type 'StatelessWidget' in type cast (0) | 2023.01.17 |
[Flutter] 재랜더링, state, setState() 사용해보기 (0) | 2023.01.17 |
[Flutter] 커스텀 위젯 만들기(코드가 길어지는 경우에 유용) (0) | 2023.01.16 |