Test aktualisiert

This commit is contained in:
dominik 2023-07-26 17:22:22 +00:00
parent 40a6ab6263
commit c7ec6c46d1

60
Test
View File

@ -1,34 +1,48 @@
void main() { void main() {
print('Hello, World!'); runApp(MyApp());
} }
class MyApp extends StatelessWidget {
int factorial(int n) { @override
if (n == 0 || n == 1) { Widget build(BuildContext context) {
return 1; return MaterialApp(
} else { home: Scaffold(
return n * factorial(n - 1); appBar: AppBar(
title: Text('Color Changer'),
),
body: ColorChanger(),
),
);
} }
} }
void main() { class ColorChanger extends StatefulWidget {
int number = 5; @override
int result = factorial(number); _ColorChangerState createState() => _ColorChangerState();
print('The factorial of $number is $result.');
} }
int findMax(List<int> numbers) { class _ColorChangerState extends State<ColorChanger> {
int max = numbers[0]; Color _backgroundColor = Colors.white;
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] > max) { void changeBackgroundColor() {
max = numbers[i]; setState(() {
} _backgroundColor = Color(Random().nextInt(0xFFFFFFFF));
});
} }
return max;
}
void main() { @override
List<int> numbers = [12, 56, 3, 78, 42, 9]; Widget build(BuildContext context) {
int maxNumber = findMax(numbers); return GestureDetector(
print('The maximum number in the list is $maxNumber.'); onTap: () => changeBackgroundColor(),
child: Container(
color: _backgroundColor,
child: Center(
child: Text(
'Tap to Change Color',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
),
),
);
}
} }