Skip to content

Instantly share code, notes, and snippets.

View SashaKryzh's full-sized avatar

Alexander SashaKryzh

View GitHub Profile
@SashaKryzh
SashaKryzh / flutter_extension_methods.dart
Last active April 30, 2024 05:54
List of my favorite extension methods in Flutter.
import 'package:flutter/material.dart';
extension BuildContextExtensions on BuildContext {
ThemeData get theme => Theme.of(this);
TextTheme get textTheme => theme.textTheme;
ColorScheme get colorScheme => theme.colorScheme;
DefaultTextStyle get defaultTextStyle => DefaultTextStyle.of(this);
@SashaKryzh
SashaKryzh / app_text_theme_extension.dart
Created June 8, 2023 07:21
Flutter ThemeExtension for custom text styles.
/// `ThemeExtension` template for custom text styles.
///
/// If your goal is to only change the text color for light/dark mode, I don't see a big benefit from this extension.
/// For the default text style in the Text widget, you can set `textTheme.bodyMedium` in `ThemeData` (example: lib/app_theme.dart).
/// And to set text color for specific widgets, you can use `style: TextStyle(color: Theme.of(context).appColors.error)` or
/// `style: AppTypography.h1.copyWith(color: context.theme.appColors.error)`.
class AppTextThemeExtension extends ThemeExtension<AppTextThemeExtension> {
const AppTextThemeExtension({
required this.displayLarge,
required this.displayMedium,
@SashaKryzh
SashaKryzh / app_colors_extension.dart
Last active April 24, 2024 17:58
Flutter ThemeExtension for custom app colors.
import 'package:flutter/material.dart';
/// `ThemeExtension` template for custom colors.
///
/// For example purposes, it has all required fields from the default Material `ColorScheme`.
/// But you can add, rename and delete any fields your need.
///
/// ### Motivation
///
/// At the beginning, you may not know if your colors will fit into the Material `ColorScheme`,
@SashaKryzh
SashaKryzh / measure_size_widget.dart
Created July 7, 2022 21:30
Flutter Measure Size widget
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class MeasureSizeRenderObject extends RenderProxyBox {
MeasureSizeRenderObject(this.onChanged);
Size? oldSize;
final ValueChanged<Size> onChanged;
@override