Skip to content

Instantly share code, notes, and snippets.

@SteveOye
Last active March 10, 2023 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveOye/7c234b48cb348dae8066cd1f684cb979 to your computer and use it in GitHub Desktop.
Save SteveOye/7c234b48cb348dae8066cd1f684cb979 to your computer and use it in GitHub Desktop.
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:widget_sample/model/blog.dart';
class ListItem extends StatefulWidget {
const ListItem({
super.key,
required this.blogs,
required this.index,
});
final List<Blog> blogs;
final int index;
@override
State<ListItem> createState() => _ListItemState();
}
class _ListItemState extends State<ListItem> {
bool isClicked = false;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(6),
padding: const EdgeInsets.all(12),
color: !isClicked ? Colors.greenAccent : Colors.deepOrangeAccent,
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.blogs[widget.index].title,
style: const TextStyle(fontSize: 24),
),
Text(widget.blogs[widget.index].body),
],
),
const Spacer(),
GestureDetector(
onTap: () {
log('Paint bused clicked at index ${widget.index}');
setState(() {
isClicked = !isClicked;
});
},
child: Icon(Icons.brush_rounded),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment