window_size_classes 1.1.1 copy "window_size_classes: ^1.1.1" to clipboard
window_size_classes: ^1.1.1 copied to clipboard

A Flutter package which provides window size classes as defined by Material Design 3.

codecov

A Flutter package that provides window size classes as defined by Material Design 3. Inspired by Jetpack Compose.

Features #

  • Width classes from Material Design 3: compact, medium, expanded, large, extra-large
  • Height classes from Android: compact, medium, expanded
  • Comparison operators & Comparable<T>
  • of(context) method for widgets
  • Raw breakpoint values

Usage #

Matching window classes to layouts #

import 'package:window_size_classes/window_size_classes.dart';

Widget build(BuildContext context) {
  final widthClass = WindowWidthClass.of(context);

  return switch (widthClass) {
    WindowWidthClass.compact => CompactLayout(),
    WindowWidthClass.medium => MediumLayout(),
    WindowWidthClass.expanded => ExpandedLayout(),
    _ => LargeLayout(), // large and extraLarge
  };
}

Responsive Navigation #

Widget build(BuildContext context) {
  final widthClass = WindowWidthClass.of(context);
  
  if (widthClass >= WindowWidthClass.expanded) {
    // Wide layout: permanent navigation rail
    return Row(children: [
      NavigationRail(/* ... */),
      Expanded(child: content),
    ]);
  } else {
    // Narrow layout: bottom navigation or drawer
    return Scaffold(
      body: content,
      bottomNavigationBar: NavigationBar(/* ... */),
    );
  }
}

Using Height Classes #

Widget build(BuildContext context) {
  final heightClass = WindowHeightClass.of(context);
  
  return Scaffold(
    appBar: heightClass != WindowHeightClass.compact 
        ? AppBar(title: Text('My App'))  // Hide app bar when height is limited
        : null,
    body: content,
  );
}

Comparison Operators #

Widget build(BuildContext context) {
  final showSidebar = WindowWidthClass.of(context) > WindowWidthClass.compact;
  
  return showSidebar 
    ? TwoColumnLayout() 
    : SingleColumnLayout();
}

Resources #

1
likes
150
points
96
downloads
screenshot

Publisher

verified publisherplushies.me

Weekly Downloads

A Flutter package which provides window size classes as defined by Material Design 3.

Repository (GitHub)
View/report issues

Topics

#material #material3

Documentation

API reference

License

LGPL-3.0 (license)

Dependencies

flutter, meta

More

Packages that depend on window_size_classes