Skip to content

Instantly share code, notes, and snippets.

View MelbourneDeveloper's full-sized avatar
🏠
Working from home

Christian Findlay MelbourneDeveloper

🏠
Working from home
View GitHub Profile
@MelbourneDeveloper
MelbourneDeveloper / mani.dart
Created May 13, 2023 08:31
Bloc Style Functions
//Programming is too easy. What if we wrote functions like this?
//Instead of just calling the function, we create types to bundle
//up the arguments and then pass the type to the function that accepts
//a generic type.
//
//This is the essence of the Bloc pattern.
class AdditionArguments {
final num a;
final num b;
@MelbourneDeveloper
MelbourneDeveloper / main.dart
Created May 13, 2023 08:30
Bloc Style With Sealed Event Types
//Programming is too easy. What if we wrote functions like this?
//Instead of just calling the function, we create types to bundle
//up the arguments and then pass the type to the function that accepts
//a generic type.
//
//This is the essence of the Bloc pattern.
sealed class Event {}
class AdditionArguments extends Event {
@MelbourneDeveloper
MelbourneDeveloper / main.dart
Created May 11, 2023 22:58
Flutter Example
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: FutureBuilder(
future: Future<String>.delayed(
const Duration(seconds: 3), () => 'Hello World!'),
@MelbourneDeveloper
MelbourneDeveloper / main.dart
Created May 11, 2023 22:30
Multiple Values and when
(int a, int b) returnMulti() => (1, 2);
void main() {
var numbers = returnMulti();
var dayNumber = switch (numbers) {
(int a, int b) when a == 1 && b == 2 => 'One and Two',
(_, _) => 'Default'
};
print(dayNumber);
}
import 'dart:math';
sealed class Shape {}
class Square extends Shape {
Square(this.length, this.width);
final double length;
final double width;
}
@MelbourneDeveloper
MelbourneDeveloper / main.dart
Created May 11, 2023 21:44
Pattern Matching Example
abstract class Animal {
String get name;
}
class Dog extends Animal {
@override
String get name => 'Spot';
}
class Cat extends Animal {
@MelbourneDeveloper
MelbourneDeveloper / main.dart
Last active May 11, 2023 21:27
Day Of Week
void main() {
var dayOfWeek = 'Monday';
var dayNumber = switch (dayOfWeek) {
'Monday' => 1,
'Tuesday' => 2,
'Wednesday' => 3,
'Thursday' => 4,
'Friday' => 5,
'Saturday' => 6,
'Sunday' => 7,
@MelbourneDeveloper
MelbourneDeveloper / main.dart
Created May 11, 2023 09:53
Switch Expression Example
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: FutureBuilder(
future: Future<String>.delayed(
const Duration(seconds: 3), () => 'Hello World!'),
import 'package:flutter/material.dart';
final colors = [
const Color.fromARGB(255, 255, 0, 0),
const Color.fromARGB(255, 0, 255, 0),
const Color.fromARGB(255, 0, 0, 255),
];
void main() {
runApp(
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red)
.copyWith(surface: Colors.pink),
cardTheme: CardTheme(
shape: RoundedRectangleBorder(