Skip to content

Instantly share code, notes, and snippets.

@f1dz
Last active August 5, 2022 08:57
Show Gist options
  • Save f1dz/f713e6062f6e6e10d14a7bc7e30c352e to your computer and use it in GitHub Desktop.
Save f1dz/f713e6062f6e6e10d14a7bc7e30c352e to your computer and use it in GitHub Desktop.
Favorite Button
import 'package:flutter/material.dart';
class FavoriteButton extends StatefulWidget {
const FavoriteButton({Key? key, required this.favorite}) : super(key: key);
final bool favorite;
@override
State<FavoriteButton> createState() => _FavoriteButtonState();
}
class _FavoriteButtonState extends State<FavoriteButton> {
bool favorite = false;
@override
void initState() {
favorite = widget.favorite;
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.2), borderRadius: BorderRadius.circular(12)),
child: IconButton(
padding: EdgeInsets.zero,
tooltip: "Favorit",
onPressed: () {
setState(() {
favorite = !favorite;
});
},
icon: Icon(
Icons.favorite_rounded,
color: favorite ? const Color.fromARGB(255, 255, 0, 0) : Colors.white,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment