This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_test/flutter_test.dart'; | |
int mcd(int a, int b) => b == 0 ? a.abs() : mcd(b, a % b); | |
void main() { | |
group('MCD Tests', () { | |
test('positive numbers', () { | |
expect(mcd(48, 18), equals(6)); | |
expect(mcd(56, 98), equals(14)); | |
expect(mcd(101, 103), equals(1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final myList = [1, 2, 3, 4]; | |
myList.length = 2; | |
print(myList); | |
myList.length = 0; | |
print(myList); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EasyTheme extends InheritedWidget { | |
final ValueNotifier<ThemeMode> theme = ValueNotifier(ThemeMode.system); | |
EasyTheme({required super.child, super.key}); | |
static EasyTheme? maybeOf(BuildContext context) => | |
context.dependOnInheritedWidgetOfExactType<EasyTheme>(); | |
static EasyTheme of(BuildContext context) { | |
final EasyTheme? result = maybeOf(context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FPSCounter extends StatefulWidget { | |
const FPSCounter({super.key}); | |
@override | |
State<FPSCounter> createState() => _FPSCounterState(); | |
} | |
class _FPSCounterState extends State<FPSCounter> { | |
int fps = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array<Any> { | |
static func generate<T>(_ length: Int, _ generator: (_ index: Int) -> T) -> [T] { | |
return (0...length).map { (index) in generator(index) } | |
} | |
} | |
//Usage | |
Array.generate(5, { index in return Int.random(in: 0...5) }) //[3, 2, 4, 1, 5] | |
Array.generate(5, { index in return "Element \(index)" }) //["Element 0", "Element 1", ...] |