Giter VIP home page Giter VIP logo

spaces's Introduction

logo

Spaces

Defining global spacing constants for building consistent and responsive apps.

Install

Add the dependency to your pubspec.yaml :

dependencies:
    spaces: <version>

Quick start

return MaterialApp(
    // Defining
    builder: (context, child) => Spacing(
        dataBuilder: (context) {
          final mediaQuery = MediaQuery.of(context);
          if (mediaQuery.size.width > 500) {
            return SpacingData.generate(30);
          }
          return SpacingData.generate(10);
        },
        child: child,
    ),
    home:Builder(builder: (context) {
        // Using
        final spacing = Spacing.of(context);
        return SpacedColumn.normal(
            padding: spacing.insets.all.semiBig,
            children: <Widget>[
                Text('hello'),
                Space.big(),
                Text('world'),
            ],
        );
      })
    ),
)

Usage

Configuring spacing

A Spacing widget should declare a global spacing configuration for your application.

return MaterialApp(
    builder: (context, child) => Spacing.fixed(
        data: SpacingData.generate(10.0), // This generates a set of spacing constants for your apps, from a base space of `10.0`.
        child: child,
    ),
    /// ...
)

Generate

By calling the Spacing.generate constructor, a set of constants are automatically generated from a single base value.

The generated values are :

  • extraSmall : value * 0.2
  • small : value * 0.4
  • semiSmall : value * 0.6
  • normal : value
  • semiBig : value * 1.5
  • big : value * 2.5
  • extraBig : value * 5.0
SpacingData.generate(10.0)

From spaces

If you want to define the various spacing values, you can use the

SpacingData.fromSpaces(
    extraSmall: 1.0,
    small: 2.0,
    semiSmall: 4.0,
    normal: 8.0,
    semiBig: 12.0,
    big: 20.0,
    extraBig: 100.0,
)

Responsive spacing

You can define the dataBuilder property of the Spacing constructor to generate a configuration from the given context.

Spacing(
    dataBuilder: (context) {
        final mediaQuery = MediaQuery.of(context);
        return SpacingData.generate(mediaQuery.size.width > 300.0 ? 20.0 : 10.0),
    },
    child: child,
)

Using constants

To access various spacing constants, simply use the Spacing.of(context) getter, or the context.spacing() extension method.

final spacing = Spacing.of(context);
// spacing.spaces.semiBig

Size variants

There are seven availables spacing constants : extraSmall, small, semiSmall, normal, semiBig, big, extraBig;

final spacing = Spacing.of(context);
return SizedBox(
    width: spacing.spaces.semiSmall,
);

Insets helpers

You have EdgeInsets presets available from <spacing>.insets.<selector>.<size>.

The available selectors are : all, horizontal, vertical, onlyLeft, onlyTop, onlyRight, onlyBottom, exceptLeft, exceptRight, exceptTop, exceptBottom.

final spacing = Spacing.of(context);
return Padding(
    padding: spacing.insets.exceptLeft.semiBig,
    child: Text('Hello'),
);

Widgets

Space

The Space widget uses gap under the hood to define a space in a Flex, Column, Row or Scrollable (such as ListView).

return Column(
    children: [
        Text('hello'),
        const Space.semiSmall(),
        Text('world'),
    ],
);

SpacedFlex / SpacedColumn / SpacedRow

Like Flex / Column / Row, but with additional padding and spaceBetween properties.

final spacing = Spacing.of(context);
return SpacedColumn.small(
    padding: spacing.insets.all.normal,
    children: [
        Text('hello'),
        Text('world'),
    ],
);

spaces's People

Contributors

aloisdeniel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spaces's Issues

Update freezed to latest version

Every time I try to use the latest version of freezed I got this error:

Because spaces <0.5.0 depends on gap ^1.2.0 and no versions of spaces match >0.5.0, spaces <0.5.0-โˆž or >0.5.0 requires gap ^1.2.0.
And because spaces 0.5.0 depends on freezed_annotation ^0.13.0-nullsafety.0 and my_flashcards depends on spaces any, either freezed_annotation ^0.13.0-nullsafety.0 or gap ^1.2.0.
So, because my_flashcards depends on both gap ^2.0.0 and freezed_annotation ^2.0.3, version solving failed.
pub get failed (1; So, because my_flashcards depends on both gap ^2.0.0 and freezed_annotation ^2.0.3, version solving failed.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.