spacing 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

spacing #

Flutter | Avoid writing repetitious paddings and make your code more redeable

Getting Started #

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:spacing/spacing.dart';

import 'web_frame.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(platform: TargetPlatform.iOS),
      title: 'Spacing',
      builder: (context, child) => WebFrame(
        child: child,
      ),
      home: SpacingPage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Spacing'),
      ),
      body: CustomScrollView(
        slivers: <Widget>[
          SliverSafeArea(
            bottom: false,
            left: false,
            right: false,
            sliver: SliverPadding(
              padding: EdgeInsets.fromLTRB(20, 40, 20, 8),
              sliver: SliverToBoxAdapter(
                child:
                    Text('Section 1', style: Theme.of(context).textTheme.title),
              ),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.symmetric(vertical: 4, horizontal: 20),
            sliver: SliverSection(),
          ),
          SliverPadding(
            padding: EdgeInsets.fromLTRB(20, 40, 20, 8),
            sliver: SliverToBoxAdapter(
              child:
                  Text('Section 2', style: Theme.of(context).textTheme.title),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.symmetric(vertical: 4),
            sliver: SliverSectionFullScreen(),
          ),
          SliverPadding(
            padding: EdgeInsets.fromLTRB(20, 40, 20, 8),
            sliver: SliverToBoxAdapter(
              child:
                  Text('Section 3', style: Theme.of(context).textTheme.title),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.symmetric(vertical: 4, horizontal: 20),
            sliver: SliverSection(),
          ),
          SliverPadding(
            padding: EdgeInsets.fromLTRB(20, 40, 20, 8),
            sliver: SliverToBoxAdapter(
              child:
                  Text('Section 4', style: Theme.of(context).textTheme.title),
            ),
          ),
          SliverSafeArea(
            top: false,
            left: false,
            right: false,
            sliver: SliverPadding(
              padding: EdgeInsets.symmetric(vertical: 4, horizontal: 20),
              sliver: SliverSection(),
            ),
          )
        ],
      ),
    );
  }
}

class SpacingPage extends StatefulWidget {
  SpacingPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _SpacingPage createState() => _SpacingPage();
}

class _SpacingPage extends State<SpacingPage> {
  @override
  Widget build(BuildContext context) {
    return DefaultSpacing(
      verticalSpacing: 4,
      horizontalSpacing: 4,
      padding: EdgeInsets.symmetric(horizontal: 20),
      child: Scaffold(
        appBar: AppBar(
          title: Text('Spacing'),
        ),
        body: CustomScrollView(
          slivers: <Widget>[
            SliverSpacing.topSafeArea(),
            SliverSpacing.vertical(20),
            SliverSpacing.padding(
              sliver: SliverToBoxAdapter(
                child: Text(
                  'Section 1',
                  style: Theme.of(context).textTheme.title,
                ),
              ),
            ),
            SliverSpacing(),
            SliverSpacing.padding(
              sliver: SliverSection(),
            ),
            SliverSpacing.vertical(20),
            SliverSpacing.padding(
              sliver: SliverToBoxAdapter(
                child: Text(
                  'Section 2',
                  style: Theme.of(context).textTheme.title,
                ),
              ),
            ),
            SliverSpacing(),
            SliverSectionFullScreen(),
            SliverSpacing.vertical(20),
            SliverSpacing.padding(
              sliver: SliverToBoxAdapter(
                child: Text(
                  'Section 3',
                  style: Theme.of(context).textTheme.title,
                ),
              ),
            ),
            SliverSpacing(),
            SliverSpacing.padding(
              sliver: SliverSection(),
            ),
            SliverSpacing.vertical(20),
            SliverSpacing.padding(
              sliver: SliverToBoxAdapter(
                child: Text(
                  'Section 4',
                  style: Theme.of(context).textTheme.title,
                ),
              ),
            ),
            SliverSpacing.padding(
              sliver: SliverSection(),
            ),
            SliverSpacing.bottomSafeArea()
          ],
        ),
      ),
    );
  }
}

class SliverSection extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: Card(
        child: Container(
          height: 200,
          width: double.infinity,
        ),
      ),
    );
  }
}

class SliverSectionFullScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: Container(
        color: Colors.grey[200],
        height: 200,
        width: double.infinity,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          padding: EdgeInsets.all(20),
          itemBuilder: (context, item) {
            return Card(
              child: Container(
                height: 100,
                width: 100,
              ),
            );
          },
          itemCount: 10,
        ),
      ),
    );
  }
}

class Item extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Card(
      child: Container(
        height: 200,
        width: 200,
      ),
    );
  }
}

class ExampleColumn extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final horizontalPadding = 20.0;
    final verticalSpace = 12.0;
    final padding = EdgeInsets.only(
        top: verticalSpace, left: horizontalPadding, right: verticalSpace);
    return Column(
      children: <Widget>[
        SafeArea(
          bottom: false,
          child: Padding(
            padding: padding,
            child: Item(),
          ),
        ),
        // No horizontal padding
        Padding(
          padding: EdgeInsets.only(top: verticalSpace),
          child: Item(),
        ),
        Padding(
          padding: padding,
          child: Item(),
        ),
        SafeArea(
          top: false,
          child: Padding(
            padding: padding,
            child: Item(),
          ),
        ),
      ],
    );
  }
}

class ExampleSpacingColumn extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final spacing = SizedBox(height: 20);
    final padding = EdgeInsets.symmetric(horizontal: 20);
    return DefaultSpacing(
        verticalSpacing: 8,
        padding: EdgeInsets.symmetric(horizontal: 20),
        child: Column(
          children: <Widget>[
            SafeArea(bottom: false, child: spacing),
            Padding(
              padding: padding,
              child: Item(),
            ),
            spacing,
            Item(),
            spacing,
            Padding(
              padding: padding,
              child: Item(),
            ),
            spacing,
            SafeArea(
              bottom: false,
              child: Padding(
                padding: padding,
                child: Item(),
              ),
            ),
          ],
        ));
  }
}

class ExampleSizeBox extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultSpacing(
        verticalSpacing: 8,
        padding: EdgeInsets.symmetric(horizontal: 20),
        child: Column(
          children: <Widget>[
            Spacing.topSafeArea(),
            Spacing.padding(
              child: Item(),
            ),
            Spacing(),
            // No horizontal padding
            Item(),
            Spacing(),
            Spacing.padding(
              child: Item(),
            ),
            Spacing(),
            Spacing.padding(
              child: Item(),
            ),
            Spacing.bottomSafeArea(),
          ],
        ));
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  spacing: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:spacing/spacing.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on May 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/jamesblasco/spacing was unreachable.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test