Giter Site home page Giter Site logo

hjjunior / resposiveness Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 2.0 1.45 MB

A Kind of CSS way to define breakpoints in your Flutter layout

License: MIT License

Dart 89.06% Kotlin 0.80% Swift 2.62% Objective-C 0.25% HTML 7.27%
responsive-layout responsive-design flutter-package flutter-widget

resposiveness's Introduction

Responsive Builder

Build Status

Demo

A CSS way-like to define breakpoints in your Flutter layout.

Propose

This project has been built thinking to an easy and less verbose possible way to get the breakpoints defined in CSS on Flutter. With this project you can define sizes, which will be rebuilded in your app, on the view, to get the most responsible layout for current size.

basic example

Portrait -> Landscape

Why

Design responsive layouts shouldn't be hard! Specially for those who came from web development, there's an easy way: defining CSS breakpoints. Flutter provide a Widget which is rebuilded when we have changes on layout size, btw, It was a little bit painful, to create internal if's on render view, it looks dirty, I think this is to much responsability to one file and is not reusable. Because of it, I created this package, where you can:

  • Get different looks according with current size of screen
  • Reuse your breakpoints
  • Don't get dirty views with conditional size logic

Getting Started

Since this project wasn't published on Pub (yet!), you should use in your project by adding the dependency on pubspec.yml referring the Github package.

dependencies:
  # ...
  responsive_builder:
    git: https://github.com/hjJunior/responsive-builder.dart

How to use

  1. Import the package where you need to rebuild your widget according with breakpoint
  2. (Optional) Use children prop to reuse the common Widget that exists between the layouts
  3. Define the list of breakpoints
  4. Define in same order the responsible builder for each breakpoint defined before
import 'package:responsive_builder/responsive_builder.dart';

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ResponsiveBuilder(
      children: <Widget>[
        Text('Text 1'),
        Text('Text 2'),
        Text('Text 3'),
      ],
      breakpoints: [
        ResponsiveBreakpoint.byPortraitMode(), // index: 0
        ResponsiveBreakpoint.byLandscapeMode(), // index: 1
      ],
      builders: [
        (context, children) => Column(children: children,), // index 0: portrait
        (context, children) => Row(children: children,), // // index 1: landscape
      ],
    );
  }
}

Breakpoints

Currently, these are the constructors available to make your layout responsible.

Method Description
ResponsiveBreakpoint.byPortraitMode(); Rebuild when device is on portrait mode
ResponsiveBreakpoint.byLandscapeMode(); Rebuild when device is on landscape mode
ResponsiveBreakpoint.byMinHeight(); Rebuild when screen have the minimum height specified
ResponsiveBreakpoint.byMinWidth(); Rebuild when screen have the minimum width specified
ResponsiveBreakpoint.byMaxHeight(); Rebuild when screen have the maximum height specified
ResponsiveBreakpoint.byMaxWidth(); Rebuild when screen have the maximum width specified

Or use ResponsiveBreakpoint() to combine if you need a specific combination.

resposiveness's People

Contributors

cdm-philipe-costa avatar hjjunior avatar

Stargazers

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

Watchers

 avatar

resposiveness's Issues

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.