Created
May 2, 2022 02:14
-
-
Save suragch/e22d5f4a538340d6d13b00f49f9dd6c0 to your computer and use it in GitHub Desktop.
Three buttons, change icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class HomeScreen extends StatefulWidget { | |
const HomeScreen({Key? key}) : super(key: key); | |
@override | |
State<HomeScreen> createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> { | |
var icon = Icons.house; | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Icon(icon, size: 50), | |
SizedBox(height: 20), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
ElevatedButton( | |
onPressed: () { | |
icon = Icons.house; | |
setState(() {}); | |
}, | |
child: Text('House'), | |
), | |
SizedBox(width: 20), | |
ElevatedButton( | |
onPressed: () { | |
icon = Icons.sunny; | |
setState(() {}); | |
}, | |
child: Text('Sun'), | |
), | |
SizedBox(width: 20), | |
ElevatedButton( | |
onPressed: () { | |
icon = Icons.cloud; | |
setState(() {}); | |
}, | |
child: Text('Cloud'), | |
), | |
], | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment