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.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:window_size_classes/window_size_classes.dart';

import 'helper.dart';
import 'surface_container.dart';

void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) => const MaterialApp(home: Example());
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    // Window*Class.of(context) is also available
    final (widthClass, heightClass) = WindowSizeClass.of(context);

    final WindowWidthClass(:spacing, :fixedPaneWidth) = widthClass;

    return Scaffold(
      backgroundColor: theme.colorScheme.surface,
      // Use Dart 3.10's dot shorthands for even terser code.
      appBar: heightClass != .compact
          ? AppBar(title: Text('Window Size Classes'))
          : null,
      // Add padding to the body that matches the class' spacing and the
      // system's view padding.
      body: Padding(
        padding: maxEdgeInsets(
          EdgeInsets.all(spacing),
          MediaQuery.viewPaddingOf(context),
        ),
        child: Row(
          spacing: spacing,
          children: [
            // Show a fixed-width pane if the screen is wide enough.
            if (fixedPaneWidth != null)
              SizedBox(
                width: fixedPaneWidth,
                child: SurfaceContainer(
                  child: Center(child: Text(fixedPaneWidth.toString())),
                ),
              ),
            Expanded(
              child: SurfaceContainer(
                child: Center(
                  // Show the window size class name.
                  child: Text(
                    'Width class: ${widthClass.name}\n'
                    'Height class: ${heightClass.name}',
                    style: theme.textTheme.titleLarge,
                    textAlign: TextAlign.center,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
150
points
97
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