From f695ae5e99768dfd14d36439b719209534bbca23 Mon Sep 17 00:00:00 2001 From: Serge Shkurko Date: Thu, 28 Apr 2022 13:02:37 +0300 Subject: [PATCH] Added availability for breakpoints customization --- CHANGELOG.md | 28 +++++++++++++----------- lib/src/flutter_bootstrap.dart | 39 +++++++++++++++++++++++++++------- pubspec.lock | 15 +++++++++---- pubspec.yaml | 2 +- 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2196e73..2018426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,24 +1,28 @@ -## [1.0.0] - Initial stable release +## [2.1.0] -* Initial release - -## [1.0.0+1] +* Added breakpoints customization -* Code formatting +## [2.0.0] -## [1.0.0+2] +* Migrated to null-safety [thanks to anisalibegic] -* Warning suppression +## [1.0.2] + +* Calculation off by 1px (md size) [thanks to gibahjoe] +* Visibility bug on small size ## [1.0.1] * BootstrapRow.height now gives a real "min height" -## [1.0.2] +## [1.0.0+2] -* Calculation off by 1px (md size) [thanks to gibahjoe] -* Visibility bug on small size +* Warning suppression -## [2.0.0] +## [1.0.0+1] -* Migrated to null-safety [thanks to anisalibegic] \ No newline at end of file +* Code formatting + +## [1.0.0] - Initial stable release + +* Initial release diff --git a/lib/src/flutter_bootstrap.dart b/lib/src/flutter_bootstrap.dart index f3a2b17..16c8569 100644 --- a/lib/src/flutter_bootstrap.dart +++ b/lib/src/flutter_bootstrap.dart @@ -8,6 +8,27 @@ List _prefixesReversed = ['', 'sm', 'md', 'lg', 'xl']; double _oneColumnRatio = 0.083333; double _gutterSize = 48.0; int _numberOfColumns = 12; +BootstrapGridBreakpoints _breakpoints = const BootstrapGridBreakpoints(); + +/// +/// Grid breakpoints values +/// +class BootstrapGridBreakpoints { + final double xs; + final double sm; + final double md; + final double lg; + final double xl; + + const BootstrapGridBreakpoints({ + this.xs = 0, + this.sm = 575, + this.md = 767, + this.lg = 992, + this.xl = 1200, + }); +} + /// /// Customization of the grid @@ -15,6 +36,7 @@ int _numberOfColumns = 12; void bootstrapGridParameters({ int numberOfColumns = 12, double gutterSize = 24, + BootstrapGridBreakpoints breakpoints = const BootstrapGridBreakpoints(), }) { assert(() { if (numberOfColumns < 10 || numberOfColumns > 24) { @@ -40,6 +62,7 @@ void bootstrapGridParameters({ _numberOfColumns = numberOfColumns; _oneColumnRatio = 1.0 / numberOfColumns; _gutterSize = gutterSize; + _breakpoints = breakpoints; } /// @@ -48,19 +71,19 @@ void bootstrapGridParameters({ String bootstrapPrefixBasedOnWidth(double width) { String pfx = ""; - if (width > 1200) { + if (width > _breakpoints.xl) { return "xl"; } - if (width > 992) { + if (width > _breakpoints.lg) { return "lg"; } - if (width > 767) { + if (width > _breakpoints.md) { return "md"; } - if (width > 575) { + if (width > _breakpoints.sm) { return "sm"; } @@ -75,16 +98,16 @@ double bootstrapMaxWidthNonFluid(double width) { /// /// Otherwise, it depends on the available width /// - if (width >= 1200) { + if (width >= _breakpoints.xl) { return 1140; } - if (width >= 992) { + if (width >= _breakpoints.lg) { return 960; } - if (width >= 768) { + if (width >= _breakpoints.lg + 1) { return 720; } - if (width >= 576) { + if (width >= _breakpoints.lg + 1) { return 540; } return width; diff --git a/pubspec.lock b/pubspec.lock index a22483c..0ec6d8c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" collection: dependency: transitive description: @@ -20,13 +20,20 @@ packages: description: flutter source: sdk version: "0.0.0" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" sky_engine: dependency: transitive description: flutter @@ -45,6 +52,6 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 631aa24..eac4e77 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_bootstrap description: A partial implementation of Bootstrap Grid system in Flutter for Responsive Layout. -version: 2.0.0 +version: 2.1.0 homepage: https://github.com/boeledi/flutter_bootstrap environment: