class Matematyka {
static int dodaj(int a, int b) {
return a + b;
}
}
void main() {
// Wywołanie metody statycznej bez tworzenia obiektu
int wynik = Matematyka.dodaj(5, 3);
print('Wynik: $wynik'); // Wynik: 8
}
class FormatowanieTekstu {
static String doTytulu(String tekst) {
if (tekst.isEmpty) return tekst;
return tekst[0].toUpperCase() + tekst.substring(1).toLowerCase();
}
}
void main() {
String tekst = FormatowanieTekstu.doTytulu('flutter jest super');
print(tekst); // Wynik: Flutter jest super
}
import 'package:flutter/material.dart';
class StyleApp {
static TextStyle naglowekStyl() {
return TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.blue,
);
}
}
class MojWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text(
'Witaj w Flutterze!',
style: StyleApp.naglowekStyl(),
);
}
}
import 'package:test/test.dart';
import 'main.dart';
void main() {
test('Test formatowania tekstu', () {
expect(FormatowanieTekstu.doTytulu('test'), equals('Test'));
expect(FormatowanieTekstu.doTytulu(''), equals(''));
});
}