Coder Social home page Coder Social logo

alrajdev / spacious-widgets Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 106 KB

A flutter library to add SizedBox between children in list of widgets

Home Page: https://pub.dev/packages/spacious_widgets

License: MIT License

Kotlin 1.41% Swift 3.87% Objective-C 0.36% Dart 94.36%
flutter widget

spacious-widgets's Introduction

A flutter library to insert SizedBox between every children widget in Column, Row, and any List of widgets.

Getting started

Visit this library in pub.dev

#Add dependency

dependencies:  
 spacious_widgets: ^1.1.0+3

Features

  • Single extension function to add SizedBox between every widgets in a List
  • Adjust any single inserted SizedBox
  • Ignore SizedBox anywhere
  • Doesn't insert SizedBox around Spacer widget

Usage

List<Widget> setSpace({double? start, double? height, double? width, double? end});  

Normally to add space between widgets we use SizedBox between every widget.

Column(  
   children: [
      Text("A"),
      SizedBox(height: 10),
      Text("B"),
      SizedBox(height: 10),
      Text("C"),
      SizedBox(height: 10),
      Text("D"),
      SizedBox(height: 10),
      Text("E"),
   ],
)  

This is tedious when the List gets bigger. For any n widgets, we have to put n-1 SizedBox, and if we need space at the start and end we need n+1 SizedBox

So with this library the SizedBox is added automatically, so the actual List is not cluttered with SizedBox.

Column(  
   children: [
      Text("A"),
      Text("B"),
      Text("C"),
      Text("D"),
      Text("E"),
   ].setSpace(height: 10),
)  

The above inserts SizedBox(height: 10, width: null) between every widget.

For Row use setSpace(width: 10) which inserts SizedBox(width: 10, height: null).

start inserts SizedBox before the first widget, end inserts SizedBox after the last widget

[  
   ...widgets
].setSpace(start: 15, height: 10, end: 15),  

The start and end parameter requires height or width parameter to be set.
start and end overrides the height or width value. To only insert SizedBox at the start and end, set height or width to 0

Adjustments

To adjust the height or width in the inserted SizedBox, use the widgets AdjustSpace and NoSpace

Column(  
    children: [
        Text("A"),
        AdjustSpace(adjust: 10),   // increase 10 in the height
        Text("B"),
        AdjustSpace(adjust: -5),   // decrease 5 in the height
        Text("C"),  
        AdjustSpace(override: 20), // override the height
        Text("D"),
        NoSpace(),                 // don't insert SizedBox here
        Text("E"),
        Text("F"),
    ].setSpace(start: 15, height: 10, end: 15),
)  

Example

License

MIT

Development

Please raise an issue if you found any problems, have any features or optimization ideas in the Github Repository. I'm happy to learn and co-operate.

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.