A package support for build responsive application on Flutter

Overview

fl_responsive_guide

Pub Package
Star on GitHub style: effective dart MIT License

Demo

Basic

Để hiểu được về việc build reponsive chúng ta cần nhìn lại 1 số khái niệm mà Material Design đề cập đến như: Layout anatomy : https://material.io/design/layout/understanding-layout.html#layout-anatomy Trong phần này chúng ta sẽ tìm hiểu được các định nghĩa của:

AppBar: https://material.io/design/layout/understanding-layout.html#layout-anatomy

Device breakpoints: https://material.io/design/layout/responsive-layout-grid.html#breakpoints

Navigation region: https://material.io/design/layout/understanding-layout.html#layout-anatomy

Columns, Gutters, Margin: https://material.io/design/layout/responsive-layout-grid.html#columns-gutters-and-margins

Sau khi tìm hiểu các thông tin trên ta sẽ thấy việc build 1 giao diện responsive sẽ cần dựa trên các thông số trên để làm việc. ở đây chúng ta sẽ có 1 class là ResponsiveGuide ResponsiveGuide là 1 InheritedWidget cho phép các widget bên dưới của nó có thể nhận đc thông tin thay đổi về config build FlDesignConfig

Mỗi 1 breakpoint sẽ có 1 config riêng để xác định loại render khi cần. Các thông số render UI như bên dưới.

  final FlSize margin; -> Dùng xác định cho margin của Body
  final FlSize body; -> Dùng xác định width của body
  final int layoutColumns; -> config cho số column trong body
  final double gutters; -> 
  final DeviceTarget deviceTarget; -> config xem giao diện của breakpoint này sẽ render cho device nào.
  final double? navigationRailWidth;
  final double appbarHeight;
  final double drawerWidth;
  final double tabBarHeight;

Trong đó chúng ta cần chú ý đến FlSize. Class này sẽ cho phéo chúng ta xác định khi nào cần khai báo size cụ thể, khi nào cần để nó auto scale theo màn hình.

abstract class FlSize {
  FlSize();

  factory FlSize.size(double size) {
    return FlSizeNumber(size);
  }

  factory FlSize.scale() {
    return FlSizeScale();
  }
}

class FlSizeNumber extends FlSize {
  final double number;

  FlSizeNumber(this.number);
}

class FlSizeScale extends FlSize {}

Implement

Breakpoints System of your application

Scaffold 1: App bars 2: Navigation/Drawer 3: Body

Breakpoints 1: Columns 2: Gutters 3: Margins

Về cơ bản thì việc build 1 ứng dụng responsive sẽ là việc xác định các dạng màn hình (xác định bởi breakpoint). Dựa trên breakpoint đang có để quyết định giao diện sẽ build. Do đó ta cần xác định Breakpoint cho ứng dụng của mình.

Dưới đây là 1 hướng dẫn chia breakpoint của Material Design:

Screen size Margin Body Layout columns
0-599dp 16dp Scaling 4
600-904 32dp Scaling 8
905-1239 Scaling 840dp 12
1240-1439 200dp Scaling 12
1440+ Scaling 1040 12

Ví dụ khi áp dụng:

      breakpointSystems: {
        600: FlDesignConfig(
            body: FlSize.scale(),
            margin: FlSize.size(0),
            appbarHeight: 56,
            deviceTarget: DeviceTarget.mobile),
        900: FlDesignConfig(
            body: FlSize.scale(),
            margin: FlSize.size(0),
            gutters: 12,
            appbarHeight: 56,
            deviceTarget: DeviceTarget.tablet),
        double.maxFinite: FlDesignConfig(
            body: FlSize.size(621),
            margin: FlSize.scale(),
            gutters: 24,
            appbarHeight: 80,
            deviceTarget: DeviceTarget.desktop)
      }

Với breakpointSystems này ta có thể thấy được, ứng dụng được chia làm 3 loại màn hình:

1: 0 < width < 600 => loại này đc xác định device là mobile, appbarHeight có chiều cao 56dp

2: 600 =< width < 900 => loại này đc xác định device là tablet, appbarHeight có chiều cao 56dp, gutter là 12dp

3: width >= 900 => loại này đc xác định device là desktop, appbarHeight có chiều cao 80dp, gutters là 24dp

Create wrapper widget which support build responsive

Sau khi xác định được breakpoints cho ứng dụng, các widget khi render sẽ xác định UI mình cần render dựa trên breakpoint nào.

Để thực hiện được việc này ta sẽ cần 2 class:

  1. ResponsiveGuideWrapper nó giống như 1 Provider của responsive layout. Cho phép các widget con của nó có thể xác định đc breakpoint hiện tại đang sử dụng để render là gì.

  2. ResponsiveGuideConsumerWidget 1 Widget consumer cho phép widget child biết thông số hiện tại khi render là gì.

Ví dụ:

  Widget build(BuildContext context) {
    return ResponsiveGuideWrapper(
      breakpointSystems: {
        600: FlDesignConfig(
            body: FlSize.scale(),
            margin: FlSize.size(0),
            appbarHeight: 56,
            deviceTarget: DeviceTarget.mobile),
        900: FlDesignConfig(
            body: FlSize.scale(),
            margin: FlSize.size(0),
            gutters: 12,
            appbarHeight: 56,
            deviceTarget: DeviceTarget.tablet),
        double.maxFinite: FlDesignConfig(
            body: FlSize.size(621),
            margin: FlSize.scale(),
            gutters: 12,
            appbarHeight: 56,
            deviceTarget: DeviceTarget.desktop)
      },
      child: Application(),
    );
  }
}

Sử dụng:

      body: ResponsiveGuideConsumerWidget(
        builder: (context, designInfo) {
          switch (designInfo.deviceTarget) {
            case DeviceTarget.mobile:
              return Center(
                child: Text('Mobile App'),
              );
            case DeviceTarget.tablet:
              return Center(
                child: Text('Tablet App'),
              );
            case DeviceTarget.desktop:
              return Center(
                child: Text('Desktop App'),
              );
          }
        },
      )
You might also like...

🌍 Responsive web app powered by Flutter and Dart

🌍 Responsive web app powered by Flutter and Dart

Flutter Web App Demo Responsive web app powered by Flutter and Dart. Contents Features Requirements Develop Building with the production JavaScript co

Nov 24, 2022

Create responsive dashboard Daily Task design using Flutter

Create responsive dashboard Daily Task design using Flutter

Daily Task Watch it on YouTube Dashboard Screen This dashboard page is designed for the daily task. This design contains profile, task overview, calen

Jan 5, 2023

A responsive scaffold widget that adjusts to your device size, for your flutter mobile and web apps.

A responsive scaffold widget that adjusts to your device size, for your flutter mobile and web apps.

scaffold_responsive A responsive scaffold widget that adjusts to your device size, for your flutter mobile and web apps. Check out the Live demo here

Sep 27, 2022

Outlook Email App Redesign - Flutter Fully Responsive Design UI

Outlook Email App Redesign - Flutter Fully Responsive Design UI

Outlook Email App Redesign - Flutter Fully Responsive Design UI Watch it on YouTube Flutter web work on beta make sure you change your channel, Config

Dec 30, 2022

Responsive Layouts and Text for Flutter

Responsive Layouts and Text for Flutter

About flutter_responsive plugin This plugin provides a easy and productive way to work with responsive layouts for Flutter Applications in mobile, des

Aug 15, 2021

Webresponsivo - A Responsive Web App Built With Flutter

Webresponsivo - A Responsive Web App Built With Flutter

Try the web app here 🚀 License Copyright (c) 2020 Souvik Biswas Permission is h

Jul 17, 2022

Responsive UI building in Flutter

Responsive UI building in Flutter

Responsive UI building in Flutter - Flutter project based on explaining and learning the responsive design concept in flutter as flutter makes hybrid applications so responsive deign is necessary for that purpose.

May 29, 2022

Flutter Facebook Responsive UI - Web & Mobile: Android | IOS

Flutter Facebook Responsive UI - Web & Mobile: Android | IOS

Facebook Clone Responsive UI - Flutter Web & Mobile: IOS | Android Web Version with Flutter! This web version uses flutter. Mobile Version: Android |

Jan 3, 2023

Flutter Responsive Tabs Demo

Flutter Responsive Tabs Demo

flutter_responsive_tabs A responsive tabs demo at two different screen size namely tablet and phone. Live Demo: https://apgapg.github.io/flutter_respo

Sep 29, 2022
Owner
Đặng Ngọc Đức
Flutter Developer
Đặng Ngọc Đức
Flutter plugin, support android/ios.Support crop, flip, rotate, color martix, mix image, add text. merge multi images.

image_editor The version of readme pub and github may be inconsistent, please refer to github. Use native(objc,kotlin) code to handle image data, it i

FlutterCandies 317 Jan 3, 2023
My Flutter Responsive Package.

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

null 0 Dec 25, 2021
Esizer - A Flutter package provide responsive, dynamic, configurable size for each device screen size

ESizer A Flutter package provide responsive, dynamic, configurable size for each

Extreme Vietnam Public 1 Feb 15, 2022
Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui.

tenon_mortise Easily build your Widgets, Avoid parenthesis nesting, easy to build UI, A little like swift-ui. Getting Started Usage To use this plugin

JieLiu 4 Dec 15, 2022
Pokedex-Flutter - Pokedex demonstrates modern Flutter development with GetX, Hive, Flow, Adaptive/Responsive Design

Pokedex-Flutter Pokedex demonstrates modern Flutter development with GetX, Hive,

Khoujani 3 Aug 17, 2022
Aq flutter tools - AQ flutter tools - Responsive Images, Translations and more

Made by AQuadic Getting started Important Links AQuadic Script Requirement This

Aquadic 0 Feb 7, 2022
Flutter Responsive Dashboard

Store Responsive Dashboard A Flutter Web Project. Responsive on Mobile and Desktop Demo Site Contact Cam Phan - Facebook - [email protected] - Websit

Cam Phan 44 Sep 29, 2022
Responsive Blog Theme using Flutter | Web, macOS, Android, iOS

Responsive Blog Theme using Flutter | Web, macOS, Android, iOS Watch it on YouTube Packages we are using: flutter_svg: link get: link Flutter recently

Abu Anwar 196 Dec 9, 2022
Create responsive dashboard Project Management design using Flutter

Project Management Watch it on YouTube Dashboard Screen This dashboard page is designed for the project management web. This design contains task mana

Firgia 284 Dec 23, 2022
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

Bernardo Ferrari 2.8k Jan 4, 2023