switchable_padding 1.0.0 copy "switchable_padding: ^1.0.0" to clipboard
switchable_padding: ^1.0.0 copied to clipboard

A widget that adds calculated padding to the child according to the given width.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({
    Key? key,
    required this.title,
  }) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    _padding(double width) {
      if (width < 600) {
        return const EdgeInsets.all(0);
      } else if (width < 905) {
        return const EdgeInsets.all(16);
      } else if (width < 1440) {
        return const EdgeInsets.all(32);
      } else {
        return const EdgeInsets.all(48);
      }
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Container(
        color: Theme.of(context).colorScheme.background,
        child: SwitchablePadding(
          padding: _padding,
          child: Container(
            color: Theme.of(context).colorScheme.surface,
            child: SwitchablePadding(
              padding: _padding,
              child: Container(
                color: Theme.of(context).colorScheme.surfaceVariant,
                child: SwitchablePadding(
                  padding: _padding,
                  child: Container(
                    color: Theme.of(context).colorScheme.tertiary,
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
160
pub points
0%
popularity

Publisher

unverified uploader

A widget that adds calculated padding to the child according to the given width.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on switchable_padding