Skip to content

Instantly share code, notes, and snippets.

View fredgrott's full-sized avatar
👾
focusing on flutter cross platform mobile dev

Fred Grott fredgrott

👾
focusing on flutter cross platform mobile dev
View GitHub Profile
@fredgrott
fredgrott / snippet.dart
Created December 28, 2025 20:27
window height api calls
final windowHeight = WindowHeight.of(context);
if (windowHeight == WindowHeight.compact) {
// Adapt UI for limited vertical space
}
Widget build(BuildContext context) {
final windowHeight = WindowHeight.of(context);
// This value can change during the app's lifetime
// Adapt your layout based on available vertical space...
@fredgrott
fredgrott / window_height.dart
Created December 28, 2025 20:24
window height
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from window_size_classes package by Yuna
// Copyright 2025 under GNU LGPL 3.0
import 'package:flutter/widgets.dart';
import 'package:material_expressive_collection/src/adaptive/breakpoints.dart';
import 'package:meta/meta.dart';
@fredgrott
fredgrott / snippet.dart
Created December 28, 2025 19:13
window width api calls
final windowWidth = WindowWidth.of(context);
return switch (wiindowWidth) {
WindowWidth.compact => CompactLayout(),
WindowWidth.medium => MediumLayout(),
WindowWidth.expanded => ExpandedLayout(),
_ => LargeLayout(), // large and extraLarge
};
Widget build(BuildContext context) {
@fredgrott
fredgrott / window_width.dart
Created December 28, 2025 18:36
window width
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from window_size_classes package by Yuna
// Copyright 2025 under GNU LGPL 3.0
import 'package:flutter/widgets.dart';
import 'package:material_expressive_collection/src/adaptive/breakpoints.dart';
import 'package:meta/meta.dart';
@fredgrott
fredgrott / breakpoints.dart
Created December 28, 2025 16:06
breakpoints for WindowSize classes
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from window_size_classes package by Yuna
// Copyright 2025 under GNU LGPL 3.0
/// The minimum width for [WindowWidthClass.medium] layouts.
///
/// Changed this from GSkinner's SizedContext package as with fold-ables
/// on both Android and iOS want an always valid size. That is accomplushed
/// by grabbing a FlutterView.display Display object.
///
/// @author Fredrick Allan Grott
extension MQExt on BuildContext {
/// Returns pixelsPerInch
double get pixelsPerInch => UniversalPlatform.isAndroid || UniversalPlatform.isIOS? 150 : 96;
@fredgrott
fredgrott / snippet.dart
Created December 16, 2025 18:33
WidgetStateExt
extension WidgetStateHelpers on Iterable<WidgetState> {
bool get isHovered => contains(WidgetState.hovered);
bool get isFocused => contains(WidgetState.focused);
bool get isPressed => contains(WidgetState.pressed);
bool get isDragged => contains(WidgetState.dragged);
bool get isSelected => contains(WidgetState.selected);
bool get isScrolledUnder => contains(WidgetState.scrolledUnder);
bool get isDisabled => contains(WidgetState.disabled);
bool get isError => contains(WidgetState.error);
}
@fredgrott
fredgrott / snippet.dart
Created December 16, 2025 18:31
BuildContextExt
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'dart:math';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';
@fredgrott
fredgrott / m3e_theme.dart
Created November 12, 2025 19:13
M3ETheme
// Copyright 2025 Fredrick Allan Grott. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Modified from the Material_3_Expressive package
// MIT License by Emily Moonstone 2025
// ignore_for_file: prefer_constructors_over_static_methods, dead_code
@fredgrott
fredgrott / snippet.dart
Created November 12, 2025 19:12
withM3ETheme
/// Inject (or replace) the M3ETheme extension on a ThemeData.
ThemeData withM3ETheme(ThemeData base, {M3ETheme? override}) {
// Use any existing M3ETheme, else the provided override, else defaults.
final current = base.extension<M3ETheme>();
final next = override ?? current ?? M3ETheme.defaults(base.colorScheme);
// Merge existing extensions (values) with our M3ETheme, replacing prior ones.
final Iterable<ThemeExtension<dynamic>> existing = base.extensions.values;
final List<ThemeExtension<dynamic>> merged = <ThemeExtension<dynamic>>[];
for (final e in existing) {