Created
December 28, 2025 20:36
-
-
Save fredgrott/674976ae8bfbd1899a453d30d96e6318 to your computer and use it in GitHub Desktop.
window size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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'; | |
| import 'package:material_expressive_collection/src/adaptive/window_height.dart'; | |
| import 'package:material_expressive_collection/src/adaptive/window_width.dart'; | |
| import 'package:meta/meta.dart'; | |
| /// Helper class for retrieving the [WindowWidth] and [WindowHeight] | |
| /// for the current screen size. | |
| /// | |
| /// See also: | |
| /// | |
| /// - [of] | |
| abstract final class WindowSize { | |
| /// Returns the [WindowWidth] and [WindowHeight] for the current | |
| /// screen size. | |
| /// | |
| /// The [context] must have a [MediaQuery] ancestor. | |
| /// | |
| /// ```dart | |
| /// Widget build(BuildContext context) { | |
| /// final (windowWidth, windowHeight) = WindowSize.of(context); | |
| /// // Use windowWidth and windowHeight to adapt your layout... | |
| /// } | |
| /// ``` | |
| @useResult | |
| @pragma('dart2js:tryInline') | |
| @pragma('vm:prefer-inline') | |
| @pragma('wasm:prefer-inline') | |
| static (WindowWidth windowWidth, WindowHeight windowHeight) of( | |
| BuildContext context, | |
| ) { | |
| return fromSize(View.of(context).display.size); | |
| } | |
| /// Returns the [WindowWidth] and [WindowHeight] for the given | |
| /// [size]. | |
| /// | |
| /// ```dart | |
| /// final (windowWidth, windowHeight) = WindowSize.fromSize(size); | |
| /// ``` | |
| @useResult | |
| @pragma('dart2js:tryInline') | |
| @pragma('vm:prefer-inline') | |
| @pragma('wasm:prefer-inline') | |
| static (WindowWidth windowWidth, WindowHeight windowHeight) fromSize( | |
| Size size, | |
| ) { | |
| final Size(:width, :height) = size; | |
| return ( | |
| WindowWidth.fromWidth(width), | |
| WindowHeight.fromHeight(height), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment