Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Alex Isaienko s0nerik

🎯
Focusing
View GitHub Profile
@s0nerik
s0nerik / main.dart
Created Oct 21, 2021
UseCase specification comparison (class vs function, explicit vs implicit deps)
View main.dart
void main() {
final di = DIContainer();
final quarterExpenses1 = di.getComputeQuarterExpensesUseCase().perform(100000);
print(quarterExpenses1);
final quarterExpenses2 = di.getComputeQuarterExpensesUseCaseFunction()(100000);
print(quarterExpenses2);
final quarterExpenses3 = di.getExplicitComputeQuarterExpensesUseCaseFunction()(100000);
print(quarterExpenses3);
}
@s0nerik
s0nerik / main.dart
Created Oct 18, 2021
Dart async error catch example (CORRECT, actually captures the expection)
View main.dart
Future<void> main() async {
await test();
}
Future<void> test() async {
try {
return await errorGenerator();
} catch (e) {
print('!!!CAPTURED ERROR!!!');
} finally {
@s0nerik
s0nerik / main.dart
Created Oct 18, 2021
Dart async error catch example (WRONG, doesn't capture expection)
View main.dart
Future<void> main() async {
await test();
}
Future<void> test() async {
try {
return errorGenerator();
} catch (e) {
print('!!!CAPTURED ERROR!!!');
} finally {
@s0nerik
s0nerik / main.dart
Last active Oct 4, 2021
Figma line height vs Flutter's TextStyle height illustration
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
const lineHeight = 27.0;
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@s0nerik
s0nerik / enum_mapper.dart
Last active Jul 17, 2021
Two way enum mapper
View enum_mapper.dart
typedef EnumMapperCallback<T, E> = T Function(E value);
class EnumMapper<E, T> {
EnumMapper(List<E> enumValues, EnumMapperCallback<T, E> mapper) {
for (final enumValue in enumValues) {
final key = enumValue;
final value = mapper(enumValue);
_forwardMap[key] = value;
_inverseMap[value] = key;
}
@s0nerik
s0nerik / cluster.dart
Last active Nov 12, 2020
Flutter cluster bitmap rendering example
View cluster.dart
BitmapDescriptor _stationPin;
ui.Image _clusterBgImage;
Future<BitmapDescriptor> _getClusterBitmap(
BuildContext context,
MapCluster cluster,
) async {
if (!cluster.isCluster && _stationPin != null) {
return _stationPin;
}
@s0nerik
s0nerik / adjust_pan.dart
Last active Aug 26, 2020
A widget that mimics Android's `adjustPan` windowSoftInputMode
View adjust_pan.dart
import 'dart:async';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
typedef AdjustPanChildBuilder = Widget Function(EdgeInsetsGeometry padding);
/// A widget that forces the same behavior as
/// Android's `adjustPan` windowSoftInputMode.
///
@s0nerik
s0nerik / preprocess.py
Created Jun 4, 2020
Preprocess SVG files for svg_flutter
View preprocess.py
#!/usr/bin/env python3
# coding=utf8
import re
import io
import os
import sys
regex = r"(<[^>]+href=\"#([^>]+)\"[^<]*>)[^\3]*(<[^>]+id=\"\2\"[^<]*>)"
pattern = re.compile(regex)
View main.dart
void main() {
final iterable = [1].map((x) => x * 2);
x(iterable);
}
void x(List<int> ints) {
print('Hello');
}
@s0nerik
s0nerik / main.dart
Created May 13, 2020
Dart const List
View main.dart
main() {
final list1 = const <int>[];
final list2 = const <int>[];
print(identical(list1, list2));
list1.add(666);
print(list1[0]);
print(list2[0]);
}