Skip to content

Instantly share code, notes, and snippets.

View hawkkiller's full-sized avatar
🎯
Focusing

Michael Lazebny hawkkiller

🎯
Focusing
View GitHub Profile
@hawkkiller
hawkkiller / button.dart
Created January 24, 2025 10:51
Different buttons for design system
import 'package:ui/ui.dart';
sealed class UiButton extends StatelessWidget {
const UiButton({super.key});
const factory UiButton.primary({
required String label,
required VoidCallback? onPressed,
Widget? icon,
bool isEnabled,
@hawkkiller
hawkkiller / sticky_headers.dart
Created November 23, 2024 12:00
Simple and efficient sticky headers
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
@hawkkiller
hawkkiller / bloc.dart
Last active September 30, 2024 19:13
A good looking BLoC that conforms to design principles and manages the state correctly.
import 'package:bloc/bloc.dart';
class UserProfile {
UserProfile({
required this.name,
this.age,
});
final String name;
final int? age;
@hawkkiller
hawkkiller / scope.dart
Created September 21, 2024 12:51
Scope used for lazy initialization
import 'package:flutter/material.dart';
class SettingsBloc {
void close() {}
}
/// {@template settings_scope}
/// SettingsScope widget.
/// {@endtemplate}
class SettingsScope extends StatefulWidget {
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
class AnimatedEdgeSlide extends SingleChildRenderObjectWidget {
const AnimatedEdgeSlide({
required Widget super.child,
required this.positionAnimation,
super.key,
});
@hawkkiller
hawkkiller / badge.dart
Created May 20, 2024 14:11
Dead simple badge using custom single child layout
class RecommendedBadge extends StatelessWidget {
const RecommendedBadge({super.key});
@override
Widget build(BuildContext context) => DecoratedBox(
decoration: BoxDecoration(
color: Colors.of(context).tertiary,
borderRadius: BorderRadius.circular(4),
),
child: Padding(
@hawkkiller
hawkkiller / good_forms.dart
Last active February 9, 2024 13:56
Forms that support async validation
import 'dart:async';
import 'package:flutter/material.dart';
typedef ValueBuilder<T> = Widget Function(BuildContext context, T value);
class GoodForm extends StatefulWidget {
const GoodForm({
required this.builder,
super.key,
@hawkkiller
hawkkiller / main.dart
Created January 25, 2024 16:57
Async validation
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class UsernameValidator {
final UserRepository _userRepository;
import 'dart:convert';
void main() {
final johnJson = '{"name": "John Doe"}';
final john = getUser(johnJson);
final wrongJson = '{"name": "John Doe}';
// this raises FormatException
void main() {
try {
loadPage();
} catch (e, stackTrace) {
print('Stack Trace: $stackTrace');
}
}
void loadPage() {
loadHeader();