Main/Test

48 lines
1020 B
Plaintext
Raw Normal View History

2023-07-26 17:14:59 +00:00
void main() {
2023-07-26 17:22:22 +00:00
runApp(MyApp());
2023-07-26 17:14:59 +00:00
}
2023-07-26 17:22:22 +00:00
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Color Changer'),
),
body: ColorChanger(),
),
);
2023-07-26 17:14:59 +00:00
}
}
2023-07-26 17:22:22 +00:00
class ColorChanger extends StatefulWidget {
@override
_ColorChangerState createState() => _ColorChangerState();
2023-07-26 17:14:59 +00:00
}
2023-07-26 17:22:22 +00:00
class _ColorChangerState extends State<ColorChanger> {
Color _backgroundColor = Colors.white;
void changeBackgroundColor() {
setState(() {
_backgroundColor = Color(Random().nextInt(0xFFFFFFFF));
});
2023-07-26 17:14:59 +00:00
}
2023-07-26 17:22:22 +00:00
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => changeBackgroundColor(),
child: Container(
color: _backgroundColor,
child: Center(
child: Text(
'Tap to Change Color',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
),
),
);
}
2023-07-26 17:14:59 +00:00
}