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 January 23, 2026 15:39
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) {
@fredgrott
fredgrott / snippet.dart
Created January 23, 2026 15:29
full theme extension with design tokens
// Copyright 2026 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 m3e_design package
// Copyright (c) 2025 Emily Moonstone
// MIT Licnese
// ignore_for_file: prefer_constructors_over_static_methods
@fredgrott
fredgrott / snippet.dart
Created January 23, 2026 15:26
models as design tokens in a theme extension
// Copyright 2026 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 m3e_design package
// Copyright (c) 2025 Emily Moonstone
// MIT Licnese
// ignore_for_file: prefer_constructors_over_static_methods
@fredgrott
fredgrott / snippet.dart
Created January 23, 2026 13:39
theme extension example
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
extensions: const <ThemeExtension<dynamic>>[
MyColors(brandColor: Color(0xFF1E88E5), danger: Color(0xFFE53935)),
],
),
darkTheme: ThemeData.dark().copyWith(
extensions: <ThemeExtension<dynamic>>[
const MyColors(brandColor: Color(0xFF90CAF9), danger: Color(0xFFEF9A9A)),
@fredgrott
fredgrott / snippet.dart
Created January 23, 2026 13:37
theme extension example
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
/// Flutter code sample for [ThemeExtension].
@immutable
class MyColors extends ThemeExtension<MyColors> {
const MyColors({required this.brandColor, required this.danger});
final Color? brandColor;
@fredgrott
fredgrott / window_size.dart
Created December 28, 2025 20:36
window size
// 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
// ignore_for_file: avoid_classes_with_only_static_members
import 'package:flutter/widgets.dart';
@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';