diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a8529f..8bf2ea0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ +# 0.6.1 +* [Fix] `ripple` and `opacity` now works with `add` method. +* Other minor improvements and fixes + ## 0.6.0 * Added `ripple` method to `StyleClass`. * Added `opacity` method to `StyleClass`. * Major rewrite of widget builder. Improved performance. - ## 0.5.0 * Added `backgroundBlur` method to the `StyleClass`. * Added `backgroundImage` method to `StyleClass`. diff --git a/README.md b/README.md index 899e60d..663ae12 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,10 @@ Division( To add a style to the `StyleClass`, use the ..[style] syntax. The two dots is used to not return [style], but the `StyleClass`. -On construction, choose to use radians or not when giving circular values. `Styleclass({bool useRadians = false})`. +On construction, choose to use radians or not when giving circular values. + ```dart + Styleclass({bool useRadians = false}) + ``` #### Align ```dart @@ -187,7 +190,7 @@ Value must not be negative. dynamic color = const Color(0xFF000000), BorderStyle style = BorderStyle.solid}) ``` -Choose between `all` or `left`, `right`, `top` and `bottom`. +Choose between `all`, `left`, `right`, `top` and `bottom`. `all` works together with the other properties. `color` parameter supports HEX '#xxxxxx', rgb(int, int, int), rgba(int, int, int, double) and [Color]. #### Border radius @@ -251,7 +254,7 @@ By default one turn equals the value 1.0. To change to radians: `StyleClass(useR ``` Material ripple effect. -The ripple effect does not work if `onTap` is defined. You may change `onTap` to `onTapDown`, `onTapUp` and `onTapCancel`. +**`onTap` does not work if `ripple` is defined.** You may use `onTapDown`, `onTapUp` or `onTapCancel` instead. #### Animate ```dart diff --git a/example/pubspec.lock b/example/pubspec.lock new file mode 100644 index 0000000..a1e8431 --- /dev/null +++ b/example/pubspec.lock @@ -0,0 +1,139 @@ +# Generated by pub +# See https://www.dartlang.org/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.11" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.5" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.2" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.0" + quiver: + dependency: transitive + description: + name: quiver + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.5" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.9.3" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.4" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.6" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" +sdks: + dart: ">=2.2.0 <3.0.0" diff --git a/lib/src/build.dart b/lib/src/build.dart index 40ce24d..3938724 100644 --- a/lib/src/build.dart +++ b/lib/src/build.dart @@ -72,8 +72,6 @@ class DivisionBuild extends StatelessWidget { Widget build(BuildContext context) { Widget current = child; - // container - if (child == null && (constraints == null || !constraints.isTight)) { current = LimitedBox( maxWidth: 0.0, @@ -82,7 +80,6 @@ class DivisionBuild extends StatelessWidget { ); } - // child alignment if (alignmentChild != null) current = Align(alignment: alignmentChild, child: current); @@ -90,7 +87,6 @@ class DivisionBuild extends StatelessWidget { if (effectivePadding != null) current = Padding(padding: effectivePadding, child: current); - // Material ripple effect if (ripple != null && ripple?.enable == true) { current = Material( color: Colors.transparent, @@ -112,7 +108,6 @@ class DivisionBuild extends StatelessWidget { if (margin != null) current = Padding(padding: margin, child: current); - // background blur if (backgroundBlur != null) { current = ClipRRect( borderRadius: decoration?.borderRadius, @@ -126,11 +121,9 @@ class DivisionBuild extends StatelessWidget { ); } - // widget alignment if (alignment != null) current = Align(alignment: alignment, child: current); - // transform if (transform != null) { current = Transform( alignment: FractionalOffset.center, @@ -139,7 +132,6 @@ class DivisionBuild extends StatelessWidget { ); } - // opacity if (opacity != null) current = Opacity(opacity: opacity, child: current); return current; diff --git a/lib/src/format/format_color.dart b/lib/src/format/format_color.dart index 57a5440..0fd6fc1 100644 --- a/lib/src/format/format_color.dart +++ b/lib/src/format/format_color.dart @@ -12,6 +12,8 @@ Color formatColor(dynamic color, {bool acceptNull = false}) { color[1] is int && color[2] is int && color[3] is double) { + print( + 'The color format [int, int, int, double] is deprectaed. Use rgba(int, int, int, double) instead'); formattedColor = Color.fromRGBO(color[0], color[1], color[2], color[3]); } else { throw ('Unsupported rgba color format. Expected [int, int, int, double] but recieved $color'); @@ -19,6 +21,8 @@ Color formatColor(dynamic color, {bool acceptNull = false}) { } if (color.length == 3) { if (color is List) { + print( + 'The color format [int, int, int] is deprectaed. Use rgba(int, int, int) instead'); formattedColor = Color.fromRGBO(color[0], color[1], color[2], 1); } else { throw ('Unsupported rgb color format. Expected [int, int, int] but recieved $color'); diff --git a/lib/src/function/color.dart b/lib/src/function/color.dart index 770bd2d..110ea0e 100644 --- a/lib/src/function/color.dart +++ b/lib/src/function/color.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; /// Returns [Color]. /// -/// [r], [g] and [b] must not exceed 255 +/// [r], [g] and [b] must not exceed 255. /// /// ```dart /// ..backgroundColor(rgb(34, 29, 189)); @@ -13,7 +13,7 @@ Color rgb(int r, int g, int b) { /// Returns [Color]. /// -/// [r], [g] and [b] must not exceed 255 +/// [r], [g] and [b] must not exceed 255. /// /// ```dart /// ..backgroundColor(rgba(34, 29, 189, 0.7)); diff --git a/lib/src/gesture_class.dart b/lib/src/gesture_class.dart index 27adbbe..204686c 100644 --- a/lib/src/gesture_class.dart +++ b/lib/src/gesture_class.dart @@ -1,6 +1,6 @@ import 'package:flutter/widgets.dart'; -/// Holds all the gestures for the `Division` widget +/// Responsible for all the gestures for the `Division` widget /// /// ```dart /// Division( @@ -8,10 +8,10 @@ import 'package:flutter/widgets.dart'; /// ..width(100) /// ..height(150) /// ..borderRadius(all: 30.0) -/// ..backgroundColor(hex; 'eeeeee'), +/// ..backgroundColor('#eeeeee'), /// gesture: GestureClass() /// ..onTap(() => print('Widget pressed!')) -/// ..onLongPress(() => print('Widget pressed long!)), +/// ..onLongPress(() => print('Widget longpress)), /// child: Text('Some text), /// ) /// ``` diff --git a/lib/src/style_class.dart b/lib/src/style_class.dart index 5d33602..23b1405 100644 --- a/lib/src/style_class.dart +++ b/lib/src/style_class.dart @@ -5,10 +5,12 @@ import 'format/format_alignment.dart'; import 'format/format_color.dart'; import 'model/ripple.dart'; -/// Holds all the styling for the `Division` widget +//TODO: overflow method + +/// Responsibe for all the styling for the `Division` widget /// -/// If `useRadians` parameter is false, one full circle equals 1. If true one full circle equals 2 * pi. -/// Applies to the style properties which by default in flutter uses radians, like ..rotate() nad ..sweepGradient() +/// Choose to calculate angles with radians or not through [useRadians] parameter. 0.0 - 1.0 or 0.0 - 2 * pi +/// Applies to the style properties which by default in flutter uses radians, like ..rotate() and ..sweepGradient() /// /// ```dart /// Division( @@ -16,7 +18,7 @@ import 'model/ripple.dart'; /// ..width(100) /// ..height(150) /// ..borderRadius(all: 30.0) -/// ..backgroundColor(hex; 'eeeeee'), +/// ..backgroundColor('#eeeeee'), /// gesture: GestureClass() /// ..onTap(() => print('Widget pressed!')) /// ..onLongPress(() => print('Widget pressed long!)), @@ -24,14 +26,9 @@ import 'model/ripple.dart'; /// ) /// ``` class StyleClass { - //Choose to calculate using radians or from 0 to 1 + /// Choose to calculate angles with radians or not. 0.0 - 1.0 or 0.0 - 2 * pi final bool useRadians; - BuildContext context; - - //May include context as a required parameter if needed. - // BuildContext context; - StyleClass({this.useRadians = false}); AlignmentGeometry _alignment; @@ -62,82 +59,32 @@ class StyleClass { double _opacity; RippleModel _ripple; - //Animation duration in milliseconds Duration _duration; - - //animation curve Curve _curve; - /// used to get the final style property AlignmentGeometry get getAlignment => _alignment; - - /// used to get the final style property AlignmentGeometry get getAlignmentChild => _alignmentChild; - - /// used to get the final style property EdgeInsetsGeometry get getPadding => _padding; - - /// used to get the final style property EdgeInsetsGeometry get getMargin => _margin; - - /// used to get the final style property Color get getBackgroundColor => _backgroundColor; - - /// used to get the final style property DecorationImage get getBackgroundImage => _backgroundImage; - - /// used to get the final style property double get getBackgroundBlur => _backgroundBlur; - - /// used t get the final style property Gradient get getGradient => _gradient; - - /// used to get the final style property BoxBorder get getBorder => _border; - - /// used to get the final style property BorderRadiusGeometry get getBorderRadius => _borderRadius; - - /// used to get the final style property List get getBoxShadow => _boxShadow; - - /// used to get the final style property double get getWidth => _width; - - /// used to get the final style property double get getMinWidth => _minWidth; - - /// used to get the final style property double get getMaxWidth => _maxWidth; - - /// used to get the final style property double get getHeight => _height; - - /// used to get the final style property double get getMinHeight => _minHeight; - - /// used to get the final style property double get getMaxHeight => _maxHeight; - - /// used to get the final style property double get getScale => _scale; - - /// used to get the final style property double get getRotate => _rotate; - - /// used to get the final style property Offset get getOffset => _offset; - - /// used to get the final style property Duration get getDuration => _duration; - - /// used to get the final style property Curve get getCurve => _curve; - - /// used to get the final style property double get getOpacity => _opacity; - - /// used to get the final style property RippleModel get getRipple => _ripple; BoxDecoration get getBoxDecoration { @@ -184,68 +131,56 @@ class StyleClass { return null; } - /// used to get the final style property - // StyleClass get getOnly => _only; - - /// Alignment of the widget. + /// Alignment of the widget /// /// ### Supported alignment formats /// #### Alignment - /// Built in Alignment method. For example + /// Built in Alignment class. /// ```dart - /// Alignment.center + /// Alignment.center, Alignment(0.2, -0.8), etc /// ``` - /// /// #### String /// ```dart - /// 'center', 'top', 'bottom', 'left', 'right', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' + /// 'center', 'top', 'bottom', 'left', 'right', + /// 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' /// ``` /// #### List - /// /// 0.0 equals centered. -1.0 and 1.0 equals to the side ///```dart /// [double dx, double dy] /// ``` /// #### double - /// /// Same value for dx and dy /// ```dart /// double align /// ``` - /// - void align(dynamic alignment) { - _alignment = formatAlignment(alignment); - } + void align(dynamic alignment) => _alignment = formatAlignment(alignment); - /// Alignment of the child widget. + /// Alignment of the widget. /// /// ### Supported alignment formats /// #### Alignment - /// Built in Alignment method. For example + /// Built in Alignment class. /// ```dart - /// Alignment.center + /// Alignment.center, Alignment(0.2, -0.8), etc /// ``` - /// /// #### String /// ```dart - /// 'center', 'top', 'bottom', 'left', 'right', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' + /// 'center', 'top', 'bottom', 'left', 'right', + /// 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' /// ``` /// #### List - /// /// 0.0 equals centered. -1.0 and 1.0 equals to the side ///```dart /// [double dx, double dy] /// ``` /// #### double - /// /// Same value for dx and dy /// ```dart /// double align /// ``` - /// - void alignChild(dynamic alignment) { - _alignmentChild = formatAlignment(alignment); - } + void alignChild(dynamic alignment) => + _alignmentChild = formatAlignment(alignment); /// Empty space to inscribe inside the [decoration]. The [child], if any, is placed inside this padding. /// @@ -308,9 +243,7 @@ class StyleClass { /// ..backgroundColor(rgba(255,255,255,0.15)) /// ``` /// Does not work together with `..rotate()`. - void backgroundBlur(double blur) { - _backgroundBlur = blur; - } + void backgroundBlur(double blur) => _backgroundBlur = blur; /// ### Supported color formats /// #### Color @@ -319,22 +252,19 @@ class StyleClass { /// Color(0xFFEEEEEE) or Colors.blue /// ``` /// #### HEX String - /// 6 digit hex color. Optional to use # or not + /// 6 digit hex color. Optional to use # /// ```dart /// '#eeeeee' or 'eeeeee' /// ``` - /// #### RGBA List - /// Formatted as [int, int, int, double] + /// #### RGBA /// ```dart - /// [43, 120, 32, 0.6] + /// rgba(43, 120, 32, 0.6) /// ``` - /// #### RGB List + /// #### RGB /// ```dart - /// [43, 120, 32] + /// rgb(43, 120, 32]) /// ``` - void backgroundColor(dynamic color) { - _backgroundColor = formatColor(color); - } + void backgroundColor(dynamic color) => _backgroundColor = formatColor(color); /// Eighter the [url] or the [path] has to be specified. /// [url] is for network images and [path] is for local images. @@ -353,14 +283,11 @@ class StyleClass { BoxFit fit, dynamic alignment = Alignment.center, ImageRepeat repeat = ImageRepeat.noRepeat}) { - if ((url ?? path) == null) { - throw ('A [url] or a [path] has to be provided'); - } + if ((url ?? path) == null) throw ('A [url] or a [path] has to be provided'); - alignment = formatAlignment(alignment); + AlignmentGeometry formattedAlignment = formatAlignment(alignment); ImageProvider image; - if (path != null) { image = AssetImage(path); } else { @@ -371,35 +298,32 @@ class StyleClass { image: image, colorFilter: colorFilter, fit: fit, - alignment: alignment, + alignment: formattedAlignment, repeat: repeat, ); } /// ### Supported alignment formats /// #### Alignment - /// Built in Alignment method. For example + /// Built in Alignment class. /// ```dart - /// Alignment.center + /// Alignment.center, Alignment(0.2, -0.8), etc /// ``` - /// /// #### String /// ```dart - /// 'center', 'top', 'bottom', 'left', 'right', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' + /// 'center', 'top', 'bottom', 'left', 'right', + /// 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' /// ``` /// #### List - /// /// 0.0 equals centered. -1.0 and 1.0 equals to the side ///```dart /// [double dx, double dy] /// ``` /// #### double - /// /// Same value for dx and dy /// ```dart /// double align /// ``` - /// void linearGradient( {dynamic beginAlign = 'left', dynamic endAlign = 'right', @@ -409,11 +333,9 @@ class StyleClass { AlignmentGeometry begin = formatAlignment(beginAlign); AlignmentGeometry end = formatAlignment(endAlign); - // Converts the dynamic list of colors to a List + // List -> List List finalColors = []; - for (dynamic color in colors) { - finalColors.add(formatColor(color)); - } + for (dynamic color in colors) finalColors.add(formatColor(color)); _gradient = LinearGradient( begin: begin, @@ -425,28 +347,25 @@ class StyleClass { /// ### Supported alignment formats /// #### Alignment - /// Built in Alignment method. For example + /// Built in Alignment class. /// ```dart - /// Alignment.center + /// Alignment.center, Alignment(0.2, -0.8), etc /// ``` - /// /// #### String /// ```dart - /// 'center', 'top', 'bottom', 'left', 'right', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' + /// 'center', 'top', 'bottom', 'left', 'right', + /// 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' /// ``` /// #### List - /// /// 0.0 equals centered. -1.0 and 1.0 equals to the side ///```dart /// [double dx, double dy] /// ``` /// #### double - /// /// Same value for dx and dy /// ```dart /// double align /// ``` - /// void radialGradient( {dynamic centerAlign = 'center', double radius = 0.5, @@ -455,11 +374,9 @@ class StyleClass { List stops}) { AlignmentGeometry center = formatAlignment(centerAlign); - // Converts the dynamic list of colors to a List + // List -> List List finalColors = []; - for (dynamic color in colors) { - finalColors.add(formatColor(color)); - } + for (dynamic color in colors) finalColors.add(formatColor(color)); _gradient = RadialGradient( center: center, @@ -470,30 +387,30 @@ class StyleClass { ); } + /// Choose to calculate angles with radians or not through [useRadians] parameter. + /// [endAngle] default to 1.0 if [useRadians] is false and 2 * pi if [useRadians] is true, + /// /// ### Supported alignment formats /// #### Alignment - /// Built in Alignment method. For example + /// Built in Alignment class. /// ```dart - /// Alignment.center + /// Alignment.center, Alignment(0.2, -0.8), etc /// ``` - /// /// #### String /// ```dart - /// 'center', 'top', 'bottom', 'left', 'right', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' + /// 'center', 'top', 'bottom', 'left', 'right', + /// 'topLeft', 'topRight', 'bottomLeft', 'bottomRight' /// ``` /// #### List - /// /// 0.0 equals centered. -1.0 and 1.0 equals to the side ///```dart /// [double dx, double dy] /// ``` /// #### double - /// /// Same value for dx and dy /// ```dart /// double align /// ``` - /// void sweepGradient( {dynamic centerAlign = 'center', double startAngle = 0.0, @@ -503,9 +420,7 @@ class StyleClass { List stops}) { AlignmentGeometry center = formatAlignment(centerAlign); - if (useRadians == false) { - startAngle = startAngle * pi * 2; - } + if (useRadians == false) startAngle = startAngle * pi * 2; if (endAngle == null) { //default value @@ -515,11 +430,9 @@ class StyleClass { endAngle = endAngle * pi * 2; } - // Converts the dynamic list of colors to a List + // List -> List List finalColors = []; - for (dynamic color in colors) { - finalColors.add(color); - } + for (dynamic color in colors) finalColors.add(color); _gradient = SweepGradient( center: center, @@ -568,8 +481,7 @@ class StyleClass { ); } - /// Eigther use the `all` property to apply to all corners, or user `topLeft`, `topRight`, `bottomLeft` and `bottomRight`. - /// If the `all` property is defined, the other properties will have no effect. + /// It is valid to use `all` together with single sided properties. Single sided properties will trump over the `all` property. void borderRadius( {double all, double topLeft, @@ -589,7 +501,7 @@ class StyleClass { ); } - /// If defined while the elevation property is defined, the last one defined will be the style applied. + /// If defined while the elevation method is defined, the last one defined will be the one applied. /// ### Supported color formats /// #### Color /// Built in Color method. For example @@ -597,18 +509,17 @@ class StyleClass { /// Color(0xFFEEEEEE) or Colors.blue /// ``` /// #### HEX String - /// 6 digit hex color. Optional to use # or not + /// 6 digit hex color. Optional to use # /// ```dart /// '#eeeeee' or 'eeeeee' /// ``` - /// #### RGBA List - /// Formatted as [int, int, int, double] + /// #### RGBA /// ```dart - /// [43, 120, 32, 0.6] + /// rgba(43, 120, 32, 0.6) /// ``` - /// #### RGB List + /// #### RGB /// ```dart - /// [43, 120, 32] + /// rgb(43, 120, 32]) /// ``` void boxShadow( {dynamic color = const Color(0x33000000), @@ -626,102 +537,55 @@ class StyleClass { _boxShadow = [ BoxShadow( - color: shadowColor, - blurRadius: blur ?? 0.0, - spreadRadius: spread ?? 0.0, - offset: finalOffset ?? Offset(0.0, 0.0)) + color: shadowColor, + blurRadius: blur ?? 0.0, + spreadRadius: spread ?? 0.0, + offset: finalOffset ?? Offset(0.0, 0.0), + ), ]; } /// Elevates the widget with a boxShadow. /// /// If the elevation property is used at the same time as the boxShadow property, the last one - /// defined will be the applied style. + /// defined will be the one applied. /// If the `angled` property is true, the shadow will be att 45 degrees. /// ```dart /// StyleClass..elevation(30.0, '#f5f5f5') /// ``` void elevation(double elevation, {bool angled = false, dynamic color = const Color(0x33000000)}) { - // prevent negative values - if (elevation < 0) { + //TODO: angle in value + if (elevation < 0) throw ('Elevation cant be negative. Recieved a value of $elevation'); - } - - //No shadow if elevation == 0 - if (elevation == 0) { - _boxShadow = null; - return; - } final double offsetX = angled ? elevation : 0.0; final double offsetY = elevation; final double spread = 0.0; final double blur = elevation; - Color shadowColor; //custom curve defining the opacity - // double opacity = 0.2 - (sqrt(elevation) / 90); double opacity = 0.5 - (sqrt(elevation) / 19); - - //prevent negative values for the opacity - if (opacity < 0.0) { - opacity = 0.0; - } + if (opacity < 0.0) opacity = 0.0; //find which color format used: hex, rgba or color - shadowColor = formatColor(color).withOpacity(opacity); + Color formattedColor = formatColor(color).withOpacity(opacity); _boxShadow = [ BoxShadow( - color: shadowColor, + color: formattedColor, blurRadius: blur, spreadRadius: spread, offset: Offset(offsetX, offsetY)) ]; } - /// ```dart - /// StyleClass()..width(100.0); - /// ``` - void width(double width) { - _width = width; - } - - /// ```dart - /// StyleClass()..minWidth(10.0); - /// ``` - void minWidth(double minWidth) { - _minWidth = minWidth; - } - - /// ```dart - /// StyleClass()..maxWidth(500.0); - /// ``` - void maxWidth(double maxWidth) { - _maxWidth = maxWidth; - } - - /// ```dart - /// StyleClass()..height(100.0); - /// ``` - void height(double height) { - _height = height; - } - - /// ```dart - /// StyleClass()..minHeight(10.0); - /// ``` - void minHeight(double minHeight) { - _minHeight = minHeight; - } - - /// ```dart - /// StyleClass()..maxHeight(500.0); - /// ``` - void maxHeight(double maxHeight) { - _maxHeight = maxHeight; - } + void width(double width) => _width = width; + void minWidth(double minWidth) => _minWidth = minWidth; + void maxWidth(double maxWidth) => _maxWidth = maxWidth; + void height(double height) => _height = height; + void minHeight(double minHeight) => _minHeight = minHeight; + void maxHeight(double maxHeight) => _maxHeight = maxHeight; /// Must not be negative. /// 1 corresponds to normal size. 2 corresponds to double the size. @@ -737,10 +601,7 @@ class StyleClass { /// ```dart /// StyleClass()..offset(10.0, 5.0); /// ``` - void offset(double dx, double dy) { - // Offsets the object. The offset direction changes with the rotation - _offset = Offset(dx, dy); - } + void offset(double dx, double dy) => _offset = Offset(dx, dy); /// Widget rotation /// ```dart @@ -748,8 +609,7 @@ class StyleClass { /// /// StyleClass(useRadians = true)..rotate(0.75 * pi * 2) /// ``` - /// - /// Choose between using radians or not. + /// Choose to calculate angles with radians or not through [useRadians] `StyleClass` parameter. 0.0 - 1.0 or 0.0 - 2 * pi void rotate(double angle) { if (useRadians == true) { _rotate = angle; @@ -773,13 +633,11 @@ class StyleClass { } /// Material ripple effect - /// /// ```dart /// StyleClass()..ripple(true); /// ``` - /// - /// The ripple effect does not work if `onTap` is defined. - /// `onTap` can be replaced with `onTapDown`, `onTapUp` and `onTapCancel`. + /// **`onTap` does not work if `ripple` is defined.** + /// You may use `onTapDown`, `onTapUp` or `onTapCancel` instead. void ripple(bool enable, {dynamic splashColor, dynamic highlightColor}) { _ripple = RippleModel( enable: enable, @@ -806,12 +664,10 @@ class StyleClass { /// }) /// ``` void animate([int duration = 500, Curve curve = Curves.linear]) { - if (duration < 0) { - throw ('Duration cannot be negative'); - } + if (duration < 0) throw ('Duration cannot be negative'); + _duration = Duration(milliseconds: duration); _curve = curve; - // _only = only; } /// Adds a `StyleClass` to a `StyleClass`. @@ -845,6 +701,8 @@ class StyleClass { _offset = styleClass?.getOffset ?? _offset; _duration = styleClass?.getDuration ?? _duration; _curve = styleClass?.getCurve ?? _curve; + _ripple = styleClass?.getRipple ?? _ripple; + _opacity = styleClass?.getOpacity ?? _opacity; } else { _alignment = _alignment ?? styleClass?.getAlignment; _alignmentChild = _alignmentChild ?? styleClass?.getAlignmentChild; @@ -868,6 +726,8 @@ class StyleClass { _offset = _offset ?? styleClass?.getOffset; _duration = _duration ?? styleClass?.getDuration; _curve = _curve ?? styleClass?.getCurve; + _ripple = _ripple ?? styleClass?.getRipple; + _opacity = _opacity ?? styleClass?.getOpacity; } } } diff --git a/pubspec.lock b/pubspec.lock index a1e8431..ea410c7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -66,14 +66,14 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.7.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" sky_engine: dependency: transitive description: flutter @@ -120,7 +120,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.4" + version: "0.2.6" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bea894f..1846f78 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: division description: A simple to use yet powerfull styling widget with syntax inspired by CSS. -version: 0.6.0 +version: 0.6.1 author: Rein Gundersen Bentdal homepage: https://github.com/ReinBentdal/division repository: https://github.com/ReinBentdal/division