void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
leading: const Icon(Icons.add_task),
backgroundColor: Colors.blue,
title: const Text(
'Flutter: Projeto Cores',
style: TextStyle(color: Colors.white),
),
),
body: const ColorsBox(),
),
);
}
}
class ColorsBox extends StatefulWidget {
const ColorsBox({super.key});
@override
State<ColorsBox> createState() => _ColorsBoxState();
}
class _ColorsBoxState extends State<ColorsBox> {
int colornum = 0;
List<Widget> colorSet = [
createColor(Colors.blue, Colors.blue, Colors.blue),
createColor(Colors.green, Colors.blue, Colors.purple),
createColor(Colors.orange, Colors.red, Colors.grey),
createColor(Colors.black, Colors.yellow, Colors.brown),
createColor(Colors.green.shade50, Colors.deepOrange, Colors.blue.shade700),
];
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
colorSet[colornum % colorSet.length],
colorSet[colornum % colorSet.length],
colorSet[colornum % colorSet.length],
ElevatedButton(
style: ButtonStyle(
fixedSize: const MaterialStatePropertyAll(Size(100, 30)),
backgroundColor: MaterialStatePropertyAll(Colors.green.shade500),
),
onPressed: () {
setState(
() {
colornum++;
},
);
},
child: const Icon(Icons.check),
),
],
),
);
}
}
Widget createColor(Color color1, Color color2, Color color3) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: color1,
border: Border.all(color: Colors.black, width: 2),
),
width: 80,
height: 110,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: color2,
border: Border.all(color: Colors.black, width: 2),
),
width: 80,
height: 110,
child: const Icon(Icons.person),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: color3,
border: Border.all(color: Colors.black, width: 2),
),
width: 80,
height: 110,
),
],
),
);
}