Responsive Layouts and Text for Flutter

Overview

About flutter_responsive plugin

example_6 example_7

This plugin provides a easy and productive way to work with responsive layouts for Flutter Applications in mobile, desktop and web, allowing your layout to adapt and wrap widgets ( Container, Rows, Columns and RichText ) referent to the size of his parent element.

Made by Rafael Setragni to all Flutter's Community.

Licensing

This project follows the GNU General Public License V3, wich means you can change the entire project the way as you want to, but you need to share your improvements back to the community.

To share your improvements, please first do a Fork of this project, change what you need to and finally do a pull request. And don´t let to share your ideas and needs on "Issues" page, even before to start your changes.

IMPORTANT NOTES:

  • This plugin was based on Bootstrap Web Project, but do not implement all its features (not yet).
  • The column's layer responsiveness is based on the size of the global screen, such as Bootstrap does.
  • All the widgets contains margin, padding, width, height (maximum and minimum edges), such as div Html element.
  • Fell free to improve and change this project.

How to Use

Add the dependency bellow into your pubspec.yaml file.

dependencies:
  flutter_responsive: ^0.0.6 #Please, ensure to use the most updated version

Add the reference into your .dart files

import 'package:flutter_responsive/flutter_responsive.dart';

Use the Widgets ResponsiveContainer, ResponsiveRow, ResponsiveCol and JSX as the way you want to.

Screen Sizes

This plugin was based on Bootstrap web project and split the screen in 12 columns, considering 7 screen sizes:

  • US - Ultra Small Screens - 0px to 309px
  • XS - Extra Small Screens - 310px to 575px
  • SM - Small Screens - 576px to 767px
  • MD - Medium Screens - 768px to 991px
  • LG - Large Small Screens - 992px to 1199px
  • XL - Extra Large Screens - 1200px to 1999px
  • UL - Ultra Large Screens - 2000px and beyond

example_1 example_2 example_3 example_4

Personalizing limits (Optional)

All the limits could be personalized as you need, changing the limit Hashmap into ResponsiveScreen class.

/* Map<String, double> */
ResponsiveScreen.limits = {
    ScreenSize.us: 0.00,
    // Smart watches
    ScreenSize.xs: 310.00,
    // Small phones (5c)
    ScreenSize.sm: 576.00,
    // Medium phones
    ScreenSize.md: 768.00,
    // Large phones (iPhone X)
    ScreenSize.lg: 992.00,
    // Tablets
    ScreenSize.xl: 1200.00,
    // Laptops
    ScreenSize.ul: 2000.00,
    // Desktops and TVs 4K
  };

Grid Usage

This plugin have 3 major grid elements:

  • ResponsiveContainer: Container to all page elements, such as Rows and Columns, centralizing the content and beeing limited to a maximum width size
ResponsiveContainer(

  // Determines the container's limit size
  widthLimit: ResponsiveScreen.limits[ScreenSize.lg],
  margin: EdgeInsets.symmetric(horizontal: 10),
  
  children: <Widget>[
  
    ResponsiveRow(),
    ResponsiveRow(),
    ResponsiveRow(),
    
  ]
)
  • ResponsiveRow: Container wich contains many columns or even other widget. OBS: Its not necessary to wrap inner widgets into a ResponsiveCol object.
ResponsiveRow(

  margin: EdgeInsets.only(top: 20, bottom: 5),
  
  children: <Widget>[
  
    ResponsiveCol(),
    ResponsiveCol(),
    ResponsiveCol(),
    
    Text('It´s fine to use another widget directly inside a ResponsiveRow')
  ]
),
  • ResponsiveCol:
ResponsiveCol(
  margin: EdgeInsets.all(10),
  padding: EdgeInsets.all(10),
  backgroundColor: Colors.blue,
  gridSizes: {
      ScreenSize.xs : 4,
      ScreenSize.sm : 3,
      ScreenSize.lg : 2,
      ScreenSize.xl : 1,
  },
  children: [
      Text('Lorem ipsum dolor sit amet, consectetur adipiscing elit')
  ]
)

Full Example

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

class HomePage extends StatefulWidget {
  @override
  _HomePage createState() => _HomePage();
}

class _HomePage extends State<HomePage> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    /*create 12 columns*/
    List<Widget> responsiveGridExample =

      /*repeat 12 times*/
      List<int>.generate(12, (index) => index).map((colIndex) =>
          ResponsiveCol(
              padding: EdgeInsets.all(10),
              backgroundColor: Colors.blue,
              gridSizes: {
                ScreenSize.xs : 4,
                ScreenSize.sm : 3,
                ScreenSize.lg : 2,
                ScreenSize.xl : 1,
              },
              children: [
                Text('Lorem ipsum dolor sit amet, consectetur adipiscing elit')
              ]
          )
      ).toList();

    MediaQueryData mediaQuery = MediaQuery.of(context);

    return Scaffold(
        appBar: AppBar(
          title: const Text('Home', overflow: TextOverflow.ellipsis),
        ),
        body: Container(
          color: Color(0xFFCCCCCC),
          child: ListView(
            children: <Widget>[
              ResponsiveContainer(
                margin: EdgeInsets.symmetric(vertical: 10),
                padding: EdgeInsets.symmetric(horizontal: 10),
                backgroundColor: Colors.white,
                widthLimit: mediaQuery.size.width * 0.95,
                children: <Widget>[
                  ResponsiveRow(
                    margin: EdgeInsets.symmetric(vertical: 10),
                    children: <Widget>[

                      ResponsiveCol(
                          padding: EdgeInsets.all(10),
                          margin: EdgeInsets.only(bottom: 20),
                          backgroundColor: Colors.blueGrey,
                          children: [
                            Text('Flutter Responsive Layout', style: JSXTypography.h4.merge(TextStyle(color: Colors.white)))
                          ]
                      ),
                    ]
                  ),
                  ResponsiveRow(
                    margin: EdgeInsets.symmetric(vertical: 10),
                    children: <Widget>[

                      // By default, the column occupies the entire row, always
                      ResponsiveCol(
                        children: [
                          JSX(
                            shrinkToFit: true,
                            padding: EdgeInsets.only(bottom: 20),
                            stylesheet: {
                              'h3': JSXStylesheet(
                                  textStyle: TextStyle(color: Theme.of(context).primaryColor),
                                  displayLine: DisplayLine.block
                              ),
                              'h6': JSXStylesheet(
                                  textStyle: TextStyle(color: Theme.of(context).primaryColor),
                                  displayLine: DisplayLine.block
                              )
                            },
                            margin: EdgeInsets.symmetric(horizontal: 10, vertical: 20),
                            text:
                            '<div>'
                                '<h3>Responsive Layouts</h3><h6>for <i>Flutter</i></h6>'
                                '<br><br>'
                                '<p>This <b>RichText</b> was easily produced and personalized using pure HTML</p>'
                                '<p>Bellow there is an example of 12 columns, wich changes the amount of each line depending of his father´s widget size.</p>'
                            '</div>',
                          )
                        ]
                      )

                    ]..addAll(
                        responsiveGridExample
                    )
                  )
                ],
              )
            ],
          ),
        )
    );
  }
}

Final result:

example_9

How to run the plugin example

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

To run the full example App, wich contains performance and case tests, do the steps bellow:

  • Clone this project into your local machine using Github Desktop or any other git program of your preference.
  • Download Android Studio and the last Flutter SDK into your local machine. Configure they to works properly such as this article here
  • Run flutter pub get to update all the dependencies
  • Debug the file example/lib/main.dart or any of the unity case tests located on test folder on emulator or real device.
  • To run properly the performance tests, please run the app using flutter run --release
You might also like...

Another breakpoint framework. Aims to simplify as much as possible building adaptive layouts.

Another breakpoint framework. Aims to simplify as much as possible building adaptive layouts. Features Really simple implementation Works with and wit

Sep 26, 2022

An Instagram like text editor Flutter widget that helps you to change your text style.

An Instagram like text editor Flutter widget that helps you to change your text style.

TextEditor An instagram like text editor widget for flutter Show some ❤️ and star the repo to support the project Features Edit TextStyle object font

Dec 16, 2022

Grad text package - A Flutter Widget to draw gradients into text

Grad text package - A Flutter Widget to draw gradients into text

grad_text A Flutter Widget to draw gradients into text.(Null safe) Demo Install

Jan 31, 2022

Detectable text field - Flutter Text widgets with detection features

Detectable text field - Flutter Text widgets with detection features

detectable_text_field Text widgets with detection features. You can detect hasht

Feb 2, 2022

A text field that displays text on different languages based on your selection.

translatable_text_field A text field that displays text on different languages based on your selection. Its basic idea is that you place this fields i

Mar 13, 2022

Responsive Scaffold - On mobile it shows a list and pushes to details and on tablet it shows the List and the selected item. Maintainer: @rodydavis

Responsive Scaffold - On mobile it shows a list and pushes to details and on tablet it shows the List and the selected item. Maintainer: @rodydavis

responsive_scaffold View the online demo here! On mobile it shows a list and pushes to details and on tablet it shows the List and the selected item.

Dec 2, 2022

Generate responsive pages and apps on HTML, Tailwind, Flutter and SwiftUI.

Generate responsive pages and apps on HTML, Tailwind, Flutter and SwiftUI.

Figma to Code Most design to code plugins are bad, some are even paid. This project aims to raise the bar by generating responsive layouts in Tailwind

Jan 4, 2023

Utils and widgets to make your flutter apps and websites fully responsive.

Utils and widgets to make your flutter apps and websites fully responsive.

Super Responsive A responsive library for Flutter that is easy to use and easy to read makes your app look great on all devices makes your app more re

Sep 12, 2022

Getx and Responsive design and nodejs for backend

getx_final A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Nov 12, 2021
Comments
  • no works widthLimit: ResponsiveScreen.limits['lg'],

    no works widthLimit: ResponsiveScreen.limits['lg'],

    The example does not work with: widthLimit: ResponsiveScreen.limits['lg'],

    https://pub.dev/packages/flutter_responsive#grid-usage

    widthLimit, was it changed for another property?

    ResponsiveContainer(
    
      // Determines the container's limit size
      widthLimit: ResponsiveScreen.limits['lg'],
      margin: EdgeInsets.symmetric(horizontal: 10),
      
      children: <Widget>[
      
        ResponsiveRow(),
        ResponsiveRow(),
        ResponsiveRow(),
        
      ]
    )
    
    opened by zkmark 1
Owner
Rafael Setragni
Full Stack Developer, passionate with hard problems to solve.
Rafael Setragni
null 0 Feb 16, 2022
Masked text field - A flutter package for masked text field for formet your text and good UI

Masked Text Field Masked Text Field Features A package for masked text field for

Alok Dubey 7 Sep 4, 2022
Text analyzer that extracts tokens from text for use in full-text search queries and indexes.

Tokenize text, compute document readbility and compare terms in Natural Language Processing. THIS PACKAGE IS PRE-RELEASE, and SUBJECT TO DAILY BREAKIN

GM Consult Pty Ltd 5 Dec 12, 2022
Collection of cool Layouts built with Flutter to Inspire Other UI developers and explore the possibilities of Flutter.

Awesome_Flutter_Layouts Would you like to Contribute your Designs? Please refer the Contribution guidelines before you dive In Need help? or Looks Som

Mahesh Jamdade 103 Nov 22, 2022
Flutter file based routing - File based routing and nested layouts for Flutter

Flutter File Based Routing I was inspired by the routing in remix.run with neste

Rody Davis 10 Sep 29, 2022
Super Useful Flutter Layouts - Right in Your Pocket. 😉

Super Useful Flutter Layouts - Right in Your Pocket. ?? Update: Flutter web app preview here: https://flutter-layouts-demo.web.app/ YouTube video walk

Andrea Bizzotto 1.2k Jan 8, 2023
MetaFlutter - A tool to build Flutter layouts on-device

MetaFlutter MetaFlutter is a project to create Flutter layouts on device. Learn, explore and experiment with Flutter widgets directly on your phone. M

Deven Joshi 162 Nov 22, 2022
Additional alignments to help make your layouts more readable (TopLeft, TopRight, etc)

extra alignments Why should Center get all the love? This package adds additional alignments to help make your layouts more readable. The full set inc

gskinner team 13 Jan 6, 2023
Package to select layout per orientation or device size like mobile vs tablet layouts or portrait vs landscape

proxy_layout Package to select layout per orientation or device size like mobile vs tablet layouts or portrait vs landscape Usage You have two widgets

Jimmy Aumard 8 Apr 18, 2021
Helper for building advanced multi child layouts.

About Boxy is designed to overcome the limitations of Flutter's built-in layout widgets, it provides utilities for flex, custom multi-child layouts, d

Andre 329 Dec 12, 2022