Skip to content

Instantly share code, notes, and snippets.

View hawkkiller's full-sized avatar
🎯
Focusing

Michael Lazebny hawkkiller

🎯
Focusing
View GitHub Profile
import 'package:analytics_example/analytics_property.dart';
/// A builder for analytics properties.
///
/// This class is used to build a map of properties
/// that can be sent to an analytics service.
final class AnalyticsBuilder {
AnalyticsBuilder() : properties = [];
/// The properties that have been added to this builder.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
import 'dart:collection';
abstract interface class AnalyticsReporter {
Future<void> reportEvent(AnalyticsEvent event);
}
final class FirebaseReporter implements AnalyticsReporter {
final FirebaseAnalytics _firebaseAnalytics;
@override
@hawkkiller
hawkkiller / prefs.dart
Created September 5, 2023 11:49
shared prefs
import 'package:shared_preferences/shared_preferences.dart';
/// {@template preferences_dao}
/// Class that provides seamless access to the shared preferences.
///
/// Inspired by https://pub.dev/packages/typed_preferences
/// {@endtemplate}
abstract base class PreferencesDao {
final SharedPreferences _sharedPreferences;
@hawkkiller
hawkkiller / eventloop.dart
Created August 3, 2023 14:50
Event Loop unloading
import 'dart:async';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
void main() {
// create final variables that reference canonical object
final a = const A('A');
final b = const A('A');
// check if both a and b reference the same object
print(identical(a, b)); // True
// strings are const by default
// note, that str reference canonical object of type String
@hawkkiller
hawkkiller / main.dart
Last active July 9, 2023 17:24
LSP signature requirement violation
class Bird {
void fly() {
print('The bird is flying.');
}
}
class Ostrich extends Bird {
@override
void fly() {
throw UnsupportedError('Ostriches cannot fly.');
@hawkkiller
hawkkiller / main.dart
Created July 9, 2023 17:16
OCP violation example
abstract interface class Account {
double get balance;
}
class SavingsAccount implements AccountType {
double balance;
SavingsAccount(this.balance);
}
@hawkkiller
hawkkiller / main.dart
Created July 8, 2023 13:58
Open-closed principle example
sealed class Shape {
double calcSquare();
}
class Circle extends Shape {
Circle(this.radius);
final double radius;
@override
@hawkkiller
hawkkiller / main.dart
Last active July 8, 2023 12:33
Open-closed principle violation example
sealed class Shape {}
class Circle extends Shape {
Circle(this.radius);
final double radius;
}
class Rectangle extends Shape {
Rectangle(this.width, this.height);