Skip to content
Snippets Groups Projects
Commit a9cc43cf authored by 현민 정's avatar 현민 정
Browse files

onTab 구현

parent 7775faf9
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/material.dart';
class ChecklistItem extends StatefulWidget {
final String title;
ChecklistItem({required this.title});
@override
State<StatefulWidget> createState() => _ChecklistItem();
}
class _ChecklistItem extends State<ChecklistItem> {
bool _isChecked = false;
void _check() {
setState(() {
_isChecked = !_isChecked;
});
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _check,
child: Container(
child: Text(
widget.title,
style: TextStyle(
color: _isChecked ? Colors.grey : Colors.black,
decoration: _isChecked ? TextDecoration.lineThrough : null,
),
),
),
);
}
}
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:second_flutter/checklist_item.dart';
class ChecklistView extends StatefulWidget { class ChecklistView extends StatefulWidget {
@override @override
...@@ -8,11 +9,19 @@ class ChecklistView extends StatefulWidget { ...@@ -8,11 +9,19 @@ class ChecklistView extends StatefulWidget {
} }
class _ChecklistView extends State<ChecklistView> { class _ChecklistView extends State<ChecklistView> {
List<String> checklist = ["집가고싶다", "과제해야돼", "으아아아악"];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('checklist')), appBar: AppBar(title: const Text('checklist')),
body: Container(), body: Container(
child: Column(
children: List<Widget>.generate(checklist.length, (index) {
return ChecklistItem(title: checklist[index]);
}),
),
),
); );
} }
} }
// main.dart // main.dart
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:second_flutter/checklist_item.dart';
import 'package:second_flutter/checklist_view.dart'; import 'package:second_flutter/checklist_view.dart';
void main() { void main() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment