Skip to content

Instantly share code, notes, and snippets.

@suragch
Created May 2, 2022 02:14
Show Gist options
  • Save suragch/e22d5f4a538340d6d13b00f49f9dd6c0 to your computer and use it in GitHub Desktop.
Save suragch/e22d5f4a538340d6d13b00f49f9dd6c0 to your computer and use it in GitHub Desktop.
Three buttons, change icon
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