Skip to content

Instantly share code, notes, and snippets.

@manthri-mohan-sai
Created August 19, 2021 04:29
Show Gist options
  • Save manthri-mohan-sai/a8f98ca5c281e5cef90ab1d5283dcc15 to your computer and use it in GitHub Desktop.
Save manthri-mohan-sai/a8f98ca5c281e5cef90ab1d5283dcc15 to your computer and use it in GitHub Desktop.
Simple Icon Button with Favorite icon.
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatefulWidget {
@override
createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
bool isFavorite = false;
@override
Widget build(BuildContext context) {
return IconButton(
icon: Icon(
isFavorite ? Icons.favorite : Icons.favorite_outline,
color: isFavorite ? Colors.red : Colors.grey,
),
onPressed: () => setState(() => isFavorite = !isFavorite),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment