48 lines
1020 B
Dart
48 lines
1020 B
Dart
void main() {
|
|
runApp(MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Color Changer'),
|
|
),
|
|
body: ColorChanger(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ColorChanger extends StatefulWidget {
|
|
@override
|
|
_ColorChangerState createState() => _ColorChangerState();
|
|
}
|
|
|
|
class _ColorChangerState extends State<ColorChanger> {
|
|
Color _backgroundColor = Colors.white;
|
|
|
|
void changeBackgroundColor() {
|
|
setState(() {
|
|
_backgroundColor = Color(Random().nextInt(0xFFFFFFFF));
|
|
});
|
|
}
|
|
|
|
@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),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |