From f1740e94574879e1b0ae508e156de216c24d592e Mon Sep 17 00:00:00 2001 From: Benevides Chissanga Date: Sun, 1 Mar 2020 14:37:11 -0300 Subject: [PATCH] [Feat] - Ability to add spaces on stars. [fix] - fixed typo on property `_aligns` --- example/pubspec.lock | 65 ++++++++++++++++++++++++++++++++++++++------ lib/rating_bar.dart | 20 +++++++++++--- pubspec.lock | 65 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 130 insertions(+), 20 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 9eedd89..bfd36ec 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,13 +1,27 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" cupertino_icons: dependency: "direct main" description: @@ -46,27 +74,34 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.1.8" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" pedantic: dependency: transitive description: @@ -74,13 +109,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.5" rating_bar: dependency: "direct main" description: @@ -120,7 +162,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -134,7 +176,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -149,5 +191,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0" diff --git a/lib/rating_bar.dart b/lib/rating_bar.dart index a9092b5..61db9b9 100644 --- a/lib/rating_bar.dart +++ b/lib/rating_bar.dart @@ -19,6 +19,7 @@ class RatingBar extends StatefulWidget { this.emptyColor = Colors.grey, this.halfFilledColor, this.size = 40, + this.margin, }) : _readOnly = false, assert(maxRating != null), assert(initialRating != null), @@ -42,6 +43,7 @@ class RatingBar extends StatefulWidget { this.emptyColor = Colors.grey, this.halfFilledColor, this.size = 40, + this.margin, }) : _readOnly = true, onRatingChanged = null, assert(maxRating != null), @@ -66,6 +68,7 @@ class RatingBar extends StatefulWidget { final bool isHalfAllowed; final Alignment aligns; final bool _readOnly; + final EdgeInsetsGeometry margin; @override _RatingBarState createState() { @@ -75,11 +78,12 @@ class RatingBar extends StatefulWidget { class _RatingBarState extends State { double _currentRating; - Alignment _algins; + Alignment _aligns; + @override void initState() { super.initState(); - _algins = widget.aligns; + _aligns = widget.aligns; if (widget.isHalfAllowed) { _currentRating = widget.initialRating; } else { @@ -90,7 +94,7 @@ class _RatingBarState extends State { @override Widget build(BuildContext context) { return Align( - alignment: _algins, + alignment: _aligns, child: Row( mainAxisSize: MainAxisSize.min, children: List.generate(widget.maxRating, (index) { @@ -129,7 +133,15 @@ class _RatingBarState extends State { iconData = widget.filledIcon; color = widget.filledColor ?? Theme.of(context).primaryColor; } - return Icon(iconData, color: color, size: widget.size); + + var icon = Icon(iconData, color: color, size: widget.size); + + return widget.margin != null + ? Container( + margin: widget.margin, + child: icon, + ) + : icon; } Widget buildStar(BuildContext context, int position) { diff --git a/pubspec.lock b/pubspec.lock index bcb5643..67a7df1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,27 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" flutter: dependency: "direct main" description: flutter @@ -39,27 +67,34 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.1.8" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" pedantic: dependency: transitive description: @@ -67,13 +102,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.3" + version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -106,7 +148,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -120,7 +162,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -135,5 +177,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0"