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
// 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.
// ignore_for_file: avoid_classes_with_only_static_members, avoid_bool_literals_in_conditional_expressions
import 'package:flutter/material.dart';
import 'package:userinterface/core/utils/window_size_enum.dart';
/// Helper class for defining breakpoints in a responsive UI design.
// 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.
/// WindowSizeEnum per WindowSize class docs, see
/// https://m3.material.io/foundations/layout/applying-layout/window-size-classes
///
/// Vertical Paddinhg is at
/// https://m3.material.io/foundations/layout/understanding-layout/spacing
/// @author Fredrick Allan Grott
// 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 'package:flutter/material.dart';
import 'package:lifecycle/lifecycle.dart';
import 'package:userinterface/core/lifecycle/app_lifecycle_globals.dart';
/// Subscribes lifecycle events for normal widgets.
/// This is used to wrap the scaffold of the app so that
@fredgrott
fredgrott / app_lifecycle_globals.dart
Created May 4, 2025 18:14
app lifecycle globals
// 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:ui';
/// Used with the AppLifecycleMixin scaffold wrapper
/// and in MediaQuery extensions I use this to get the devicePixelRatio
/// and size as the size will represent the physical size in foldables and
/// big screens where multiple windows may exist.
@fredgrott
fredgrott / current_route.dart
Created April 27, 2025 18:13
current route
// Data class to hold current FlexScaffold destination route for top level and
// top level destination pushed on top in small device navigation.
import 'package:app_scaffold/flex/flex_target.dart';
import 'package:flutter/foundation.dart';
@immutable
class CurrentRoute {
const CurrentRoute({
this.usePush = false,
required this.destination,
@fredgrott
fredgrott / current_route_state_notifier.dart
Created April 27, 2025 18:10
current route state notifier (the vm)
import 'package:app_scaffold/flex/flex_target.dart';
import 'package:state_notifier/state_notifier.dart';
import 'package:userinterface/core/navigation/models/current_route.dart';
/// StateNotifier for the immutable AppNavigation data.
/// For Service Locator injection, this class is registered
/// With GetIt. In Provider type ionjectors, we make
/// A separate NotifierProvider class.
///
/// Many people mistakenly label this as a controller, its
@fredgrott
fredgrott / navigation_shell.dart
Created April 27, 2025 18:08
navigation shell using HookWidget
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:userinterface/core/custom_hooks/use_create_state_notifier.dart';
import 'package:userinterface/core/custom_hooks/use_state_notifier.dart';
import 'package:userinterface/core/navigation/model_views/app_navigation_state.dart';
import 'package:userinterface/core/navigation/models/current_route.dart';
@fredgrott
fredgrott / use_state_notifier.dart
Created April 27, 2025 18:00
use state notifier
import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:state_notifier/state_notifier.dart';
/// Subscribes to a [StateNotifier] and mark the widget as needing build
/// whenever the state is changed.
T useStateNotifier<T>(StateNotifier<T> stateNotifier) {
return use(_StateNotifierHook<T>(stateNotifier));
}
@fredgrott
fredgrott / use_create_state_notifier.dart
Created April 27, 2025 17:56
use create state notifier
import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:state_notifier/state_notifier.dart';
typedef CreateStateNotifier<T extends StateNotifier> = T Function();
/// Creates a memoized [StateNotifier] instance via [create], dispose it when
/// the widget disposes.
T useCreateStateNotifier<T extends StateNotifier>(
CreateStateNotifier<T> create) {
@fredgrott
fredgrott / media_query_extension.dart
Created April 17, 2025 19:24
media query extension
// 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 'package:dual_screen/dual_screen.dart';
import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';
import 'package:userinterface/core/lifecycle/app_lifecycle_globals.dart';