Build flexible layouts with constraints, Similar to Android ConstraintLayout

Overview

Flutter ConstraintLayout

Build flexible layouts with constraints, Similar to Android ConstraintLayout.

No matter how complex the layout is and how deep the dependencies are, each child element of ConstraintLayout will only be measured once, This results in extremely high layout performance.

Feature

  1. build flexible layouts with constraints
  2. margin and goneMargin
  3. clickPadding (quickly expand the click area of child elements without changing their actual size)
  4. visibility control
  5. constraint integrity hint
  6. bias
  7. z-index
  8. translate

Coming soon:

  1. guideline
  2. barrier
  3. constraints visualization
  4. chain
  5. percentage layout
  6. more...

Support platform:

  1. Android
  2. iOS
  3. Mac
  4. Windows
  5. Linux
  6. Web

Import

Null-safety

dependencies:
  flutter_constraintlayout:
    git:
      url: 'https://github.com/hackware1993/Flutter-ConstraintLayout.git'
      ref: 'v0.1-stable'

Example

import 'package:flutter/material.dart';
import 'package:flutter_constraintlayout/constrait_layout/constraint_layout.dart';

class Example extends StatefulWidget {
  const Example({Key? key}) : super(key: key);

  @override
  State createState() => ExampleState();
}

class ExampleState extends State<Example> {
  double x = 0;
  double y = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.black,
        body: ConstraintLayout(
          children: [
            Constrained(
              id: 'box1',
              width: 200,
              height: 200,
              topToTop: CL.parent,
              rightToRight: CL.parent,
              child: Container(
                color: Colors.redAccent,
                alignment: Alignment.center,
                child: const Text('box1'),
              ),
            ),
            Constrained(
              id: 'box2',
              width: CL.matchConstraint,
              height: CL.matchConstraint,
              leftToLeft: 'box3',
              rightToRight: 'box3',
              topToBottom: 'box3',
              bottomToBottom: CL.parent,
              child: Container(
                color: Colors.blue,
                alignment: Alignment.center,
                child: const Text('box2'),
              ),
            ),
            Constrained(
              id: 'box3',
              width: CL.wrapContent,
              height: CL.wrapContent,
              rightToLeft: 'box1',
              topToBottom: 'box1',
              child: Container(
                color: Colors.orange,
                width: 200,
                height: 300,
                alignment: Alignment.center,
                child: const Text('box3'),
              ),
            ),
            Constrained(
              id: 'box4',
              width: 50,
              height: 50,
              rightToRight: CL.parent,
              bottomToBottom: CL.parent,
              child: Container(
                color: Colors.redAccent,
                alignment: Alignment.center,
                child: const Text('box4'),
              ),
            ),
            Constrained(
              id: 'box5',
              width: 120,
              height: 100,
              center: true,
              zIndex: 100,
              translate: Offset(x, y),
              clickPadding: const EdgeInsets.all(30),
              translateDependency: true,
              child: GestureDetector(
                child: Container(
                  color: Colors.pink,
                  alignment: Alignment.center,
                  child: const Text('box5 draggable'),
                ),
                onPanUpdate: (details) {
                  setState(() {
                    x += details.delta.dx;
                    y += details.delta.dy;
                  });
                },
              ),
            ),
            Constrained(
              id: 'box6',
              width: 120,
              height: 120,
              centerVertical: true,
              verticalBias: 0.8,
              leftToRight: 'box3',
              rightToRight: CL.parent,
              child: Container(
                color: Colors.lightGreen,
                alignment: Alignment.center,
                child: const Text('box6'),
              ),
            ),
            Constrained(
              id: 'box7',
              width: CL.matchConstraint,
              height: CL.matchConstraint,
              topToTop: 'box1',
              leftToLeft: CL.parent,
              rightToLeft: 'box3',
              bottomToBottom: CL.parent,
              margin: const EdgeInsets.all(50),
              child: Container(
                color: Colors.lightGreen,
                alignment: Alignment.center,
                child: const Text('box7'),
              ),
            ),
            Constrained(
              width: 200,
              height: 100,
              leftToRight: 'box5',
              bottomToTop: 'box5',
              child: Container(
                color: Colors.cyan,
                alignment: Alignment.center,
                child: const Text('child[7] pinned to the top right'),
              ),
            )
          ],
        ),
      ),
    );
  }
}

example.webp

Support me

If it helps you a lot, consider sponsoring me a cup of milk tea.
Paypal
support.webp

License

MIT License

Copyright (c) 2022 hackware1993

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...

Foody - Flutter project to display foods to clients and display charts and has a lot of features , two flutter apps : Android and Web

Foody - Flutter project to display foods to clients and display charts and has a lot of features , two flutter apps : Android and Web

Foody Flutter project to display foods to the clients and use charts and use a lot of features to complete the process (HUGE APP) There two apps: Andr

Feb 7, 2022

Flutter YouTube UI - Web & Mobile: Android | IOS

Flutter YouTube UI - Web & Mobile: Android | IOS

YouTube Clone UI - Flutter Mobile: IOS | Android Mobile Version: Android | IOS @luanbatistadev Open Source Copyright © 2021-present, Luan Batista. Fac

Sep 22, 2022

A Flutter plugin for iOS and Android for generating sign-in buttons for different social media account.

A Flutter plugin for iOS and Android for generating sign-in buttons for different social media account.

A Flutter plugin for iOS and Android for generating sign-in buttons for different social media account.

Nov 6, 2022

E-commerce UI concept in Flutter for Android and iOS, this application just for learning purposes.

E-commerce UI concept in Flutter for Android and iOS,  this application just for learning purposes.

E-commerce UI concept in Flutter for Android and iOS, this application just for learning purposes. There are over 20 screen variations.

Nov 12, 2022

An app to pick, upload and display images from camera and gallery with size and extension constraints.

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

Mar 7, 2022

Experimenting with rive's constraints :)

Experimenting with rive's constraints :)

state_machine_rive A new Flutter project for Rive StateMachine. Login From State-Machine Navigate to design on rive.app Sample Ik constraints On Rive

Nov 2, 2022

A widget that imposes different constraints on its child than it gets from its parent

A widget that imposes different constraints on its child than it gets from its parent, possibly allowing the child to overflow the parent. Similar to `OverflowBox` except that the unconstrained width or height is sized to the intrinsic size of the child, instead of being assumed to be infinite, which allows IntrinsicSizeOverflowBox to be used in a `Scrollable` widget.

Dec 7, 2022

Build basic Flutter layouts and widgets with the help of Row, Column, Stack, Expanded, Container, ListView, and GridView in Flutter.

Build basic Flutter layouts and widgets with the help of Row, Column, Stack, Expanded, Container, ListView, and GridView in Flutter.

Build basic Flutter layouts and widgets with the help of Row, Column, Stack, Expanded, Container, ListView, and GridView in Flutter.

Mar 30, 2022

Page indicator for flutter, with multiple build-in layouts.

Page indicator for flutter, with multiple build-in layouts.

flutter_page_indicators Page indicator for flutter, with multiple build-in layouts. NOTE:This project is forked from flutter_page_indicator, because t

Jun 29, 2022

MetaFlutter - A tool to build Flutter layouts on-device

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

Nov 22, 2022

LogiFresh helps you build a login easily with a friendly design, and very flexible for its construction

LogiFresh helps you build a login easily with a friendly design, and very flexible for its construction

Login Fresh LogiFresh helps you build a login easily with a friendly design, and very flexible for its construction. Installation Follow the install i

Nov 24, 2022

The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.

The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.

The best swiper for flutter , with multiple layouts, infinite loop. Compatible with Android & iOS.

Jan 3, 2023

ScrollGalleryView is a flexible library which helps you to create awesome media galleries in your Android application.

ScrollGalleryView is a flexible library which helps you to create awesome media galleries in your Android application.

ScrollGalleryView ScrollGalleryView is a flexible library which helps you to create awesome media galleries in your Android application. It's easily i

Nov 30, 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

Jan 6, 2023

Super Useful Flutter Layouts - Right in Your Pocket. 😉

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

Jan 8, 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

Apr 18, 2021

Collection of cool Layouts built with Flutter to Inspire Other UI developers and explore the possibilities of Flutter.

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

Nov 22, 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

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

Sep 29, 2022
Comments
  • margin left not work, when centerHorizontalTo parent

    margin left not work, when centerHorizontalTo parent

    Widget addressView() { return Text( '当前位置:地址1111111111111111111100000002222222222222222222222222220000000', textAlign: TextAlign.center, style: TextStyle(fontSize: 12), ).applyConstraint( id: address, centerHorizontalTo: parent, top: center.bottom, margin: const EdgeInsets.only(top: 24, left: 50,right: 50), ); }

    opened by DonaldDu 1
Releases(v1.7.0-alpha)
Owner
fangbing chen
An intermittent perfectionist.
fangbing chen
Fluid layouts allows you to create responsive layout for mobile, web and desktop from a single codebase.

Fluid layout aims to help building a responsive experience through all the different screen sizes. Based in the boostrap approach, FluidLayout calculates a padding content (fluid_padding) that changes depending on the parent size. The Fluid widget uses that padding to set its size

Jaime Blasco 3 Jan 10, 2022
A package to help build customisable timelines in Flutter.

TimelineTile A package to help build customisable timelines in Flutter. Example You can access the example project for a Timeline Showcase. The Beauti

null 549 Jan 6, 2023
It is too hard to build coherent and accessible themes with the right colors. This should help.

Color Studio It is hard to choose colors. Most color pickers give you 16 million colors and ask you to pick one. So many options, in fact, that your c

Bernardo Ferrari 372 Dec 22, 2022
Build Beautiful UIs with Flutter Widgets

I learnt this following thing from this project How to create Stateless Widgets What is the difference between hot reload and hot refresh and running

Chitraarasu.k 2 Dec 31, 2021
A simple Flutter component capable of using JSON Schema to declaratively build and customize web forms.

A simple Flutter component capable of using JSON Schema to declaratively build and customize web forms.

null 3 Oct 2, 2022
This is a simple movies app build it with flutter

Movies App ?? This is a simple app build it with flutter. Features: ?? Get movies from themoviedb.org Search movies See details movies and casting Too

Tony Gonzalez 2 Feb 1, 2021
The most complete flutter plugin packages for open various settings screen in Android and Ios

open_settings The most complete flutter plugin packages for open various settings screen in Android and Ios For Android: this plugin currently support

Ali Hoseinpoor 15 Dec 11, 2022
A small attempt to make an e-commerce user interface in Flutter for Android and iOS.

Flutter ecommerce App A small attempt to make an e-commerce user interface in Flutter for Android and iOS. I developed this application just for learn

Md Tarikul Islam 615 Jan 3, 2023
Instagram UI designed with Flutter; it is compatible and responsive with any type of Android and iOS devices.

instagram Instagram clone UI designed with Flutter; it is compatible and responsive with any type of Android and iOS devices . Getting Started This pr

Mustafa Nabavi 4 Oct 28, 2021
An android/ios E-commerce application developed for local retailers and businesses.

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

null 0 Dec 28, 2021