Skip to content

Instantly share code, notes, and snippets.

View swavkulinski's full-sized avatar

Swav Kulinski (Robotoaster) swavkulinski

View GitHub Profile
@swavkulinski
swavkulinski / records_fibonacci.dart
Last active May 23, 2023 08:31
Records: unboxing & Fibonacci example
void main() {
var result = <int>[];
for (var (int x,int y) = (0,1); y < 100; (x+=y,y+=x)){
result.add(x);
result.add(y);
}
print (result);
}
@swavkulinski
swavkulinski / main.dart
Last active May 23, 2023 07:14
Dart sealed class
void main() {
f(A1('1'));
f(A2(2));
// f(A3()); // Abstract classes cannot be instantiated
f(A31('A3',31));
f(A32('A3',32));
f(A33('A3','33'));
}
void f(A x) {
@swavkulinski
swavkulinski / main.dart
Last active February 21, 2023 20:01
Ref.read() vs Ref.watch() in Riverpod
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
/// This sample demonstrates the difference between Ref.read() and Ref.watch()
/// This sample is broken to show that despite repoProvider is updated there is no update in the UI
// This is where our state is stored
@swavkulinski
swavkulinski / main.dart
Last active February 16, 2023 00:28
Abstract methods, nullable, non nullable and default parameters
main (){}
abstract class A {
void listen({
bool isOk,
required String isBad,
});
}
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAuthorised() {
return request.auth != null;
}
function isAuthorisedWithId(id) {
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
final data = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20]
.map((x) => {'name':' Dart $x'}).toList();
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
void main() {
}
enum Moves {
FORWARD,
BACK,
LEFT,
RIGHT,
JUMP,
void main() {
// an array is a collection of objects
var dance = [Moves.LEFT,Moves.RIGHT,Moves.JUMP,];
print('${dance[0]}');
for (var move in dance) {
print('$move');
}
void main() {
var breakfast = Breakfast(
tea: Tea(
milk: Milk(),
),
);
print('$breakfast was ${breakfast.getCalories()} calories');
}
void main(){
var breakfast = Breakfast();
print('$breakfast');
}
class Breakfast {
}