diff --git a/.gitignore b/.gitignore index 0d5045c..5362550 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,100 @@ +# Miscellaneous +*.class +*.lock +*.log +*.pyc +*.swp .DS_Store -.dart_tool/ +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# Visual Studio Code related +.vscode/ + +# Flutter repo-specific +/bin/cache/ +/bin/mingit/ +/dev/benchmarks/mega_gallery/ +/dev/bots/.recipe_deps +/dev/bots/android_tools/ +/dev/docs/doc/ +/dev/docs/flutter.docs.zip +/dev/docs/lib/ +/dev/docs/pubspec.yaml +/dev/integration_tests/**/xcuserdata +/dev/integration_tests/**/Pods +/packages/flutter/coverage/ +version + +# packages file containing multi-root paths +.packages.generated +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins .packages +.pub-cache/ .pub/ +build/ +flutter_*.png +linked_*.ds +unlinked.ds +unlinked_spec.ds + +# Android related +**/example/android/**/gradle-wrapper.jar +**/example/android/.gradle +**/example/android/captures/ +**/example/android/gradlew +**/example/android/gradlew.bat +**/example/android/local.properties +**/example/android/**/GeneratedPluginRegistrant.java +**/example/android/key.properties +*.jks + +# iOS/XCode related +**/example/ios/**/*.mode1v3 +**/example/ios/**/*.mode2v3 +**/example/ios/**/*.moved-aside +**/example/ios/**/*.pbxuser +**/example/ios/**/*.perspectivev3 +**/example/ios/**/*sync/ +**/example/ios/**/.sconsign.dblite +**/example/ios/**/.tags* +**/example/ios/**/.vagrant/ +**/example/ios/**/DerivedData/ +**/example/ios/**/Icon? +**/example/ios/**/Pods/ +**/example/ios/**/.symlinks/ +**/example/ios/**/profile +**/example/ios/**/xcuserdata +**/example/ios/.generated/ +**/example/ios/Flutter/App.framework +**/example/ios/Flutter/Flutter.framework +**/example/ios/Flutter/Flutter.podspec +**/example/ios/Flutter/Generated.xcconfig +**/example/ios/Flutter/app.flx +**/example/ios/Flutter/app.zip +**/example/ios/Flutter/flutter_assets/ +**/example/ios/Flutter/flutter_export_environment.sh +**/example/ios/ServiceDefinitions.json +**/example/ios/Runner/GeneratedPluginRegistrant.* + +# Coverage +coverage/ -build/ \ No newline at end of file +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages \ No newline at end of file diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml deleted file mode 100644 index 2aa056d..0000000 --- a/.idea/google-java-format.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index 6068110..0000000 --- a/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml deleted file mode 100644 index b0f6971..0000000 --- a/.idea/libraries/Flutter_Plugins.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml deleted file mode 100644 index f2aa065..0000000 --- a/.idea/markdown-navigator.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml deleted file mode 100644 index db06266..0000000 --- a/.idea/markdown-navigator/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 0cb5058..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index cc0f3f4..76b1a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.0.0+1 +* **FIXED** Issue with scrollable views [Issue #18](https://github.com/sarbagyastha/flutter_rating_bar/issues/18). +* **FIXED** `unratedColor` not working for colors with alpha [Issue #15](https://github.com/sarbagyastha/flutter_rating_bar/issues/15). + ## 3.0.0 **Breaking Changes** This version requires `flutter >= 1.9`. diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 53ae0ae..b6e61b6 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,3 +1,4 @@ android.enableJetifier=true android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh deleted file mode 100644 index b79cb5a..0000000 --- a/example/ios/Flutter/flutter_export_environment.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=C:\Development\flutter" -export "FLUTTER_APPLICATION_PATH=C:\Development\plugins\flutter_rating_bar\example" -export "FLUTTER_TARGET=lib\main.dart" -export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build\ios" -export "FLUTTER_FRAMEWORK_DIR=C:\Development\flutter\bin\cache\artifacts\engine\ios" diff --git a/example/lib/main.dart b/example/lib/main.dart index 50b9498..42f5244 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -89,6 +89,7 @@ class _MyAppState extends State { ), itemCount: 5, itemSize: 50.0, + unratedColor: Colors.amber.withAlpha(50), direction: _isVertical ? Axis.vertical : Axis.horizontal, ), SizedBox( @@ -106,7 +107,8 @@ class _MyAppState extends State { suffixIcon: MaterialButton( onPressed: () { setState(() { - _userRating = double.parse(_ratingController.text ?? "0.0"); + _userRating = + double.parse(_ratingController.text ?? "0.0"); }); }, child: Text("Rate"), @@ -222,8 +224,9 @@ class _MyAppState extends State { initialRating: 3, direction: _isVertical ? Axis.vertical : Axis.horizontal, allowHalfRating: true, - unratedColor: Colors.grey[200], + unratedColor: Colors.amber.withAlpha(50), itemCount: 5, + itemSize: 50.0, itemPadding: EdgeInsets.symmetric(horizontal: 4.0), itemBuilder: (context, _) => Icon( _selectedIcon ?? Icons.star, diff --git a/example/pubspec.lock b/example/pubspec.lock deleted file mode 100644 index 5408922..0000000 --- a/example/pubspec.lock +++ /dev/null @@ -1,146 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - 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_rating_bar: - dependency: "direct dev" - description: - path: ".." - relative: true - source: path - version: "3.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.7" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" - 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.5" - 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.5" - 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.5.0 <3.0.0" diff --git a/flutter_rating_bar.iml b/flutter_rating_bar.iml deleted file mode 100644 index 501965f..0000000 --- a/flutter_rating_bar.iml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lib/flutter_rating_bar.dart b/lib/flutter_rating_bar.dart index a1e760a..474d5be 100644 --- a/lib/flutter_rating_bar.dart +++ b/lib/flutter_rating_bar.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; /// Defines widgets which are to used as rating bar items. class RatingWidget { - /// Defines widget to be used as rating bar item when the item is completely rated. final Widget full; @@ -118,11 +117,8 @@ class _NoRatingWidget extends StatelessWidget { child: FittedBox( fit: BoxFit.contain, child: enableMask - ? ColorFiltered( - colorFilter: ColorFilter.mode( - unratedColor, - BlendMode.srcATop, - ), + ? _ColorFilter( + color: unratedColor, child: child, ) : child, @@ -131,6 +127,33 @@ class _NoRatingWidget extends StatelessWidget { } } +class _ColorFilter extends StatelessWidget { + final Widget child; + final Color color; + + _ColorFilter({ + @required this.child, + @required this.color, + }); + + @override + Widget build(BuildContext context) { + return ColorFiltered( + colorFilter: ColorFilter.mode( + color, + BlendMode.srcATop, + ), + child: ColorFiltered( + colorFilter: ColorFilter.mode( + Colors.white, + BlendMode.srcATop, + ), + child: child, + ), + ); + } +} + class _IndicatorClipper extends CustomClipper { final double ratingFraction; final bool rtlMode; @@ -160,11 +183,10 @@ class _IndicatorClipper extends CustomClipper { } /// A widget to display rating as assigned using [rating] property. -/// +/// /// It's a read only version of [RatingBar]. /// Use [RatingBar], if interative version is required. i.e. if user input is required. class RatingBarIndicator extends StatefulWidget { - /// Defines the rating value for indicator. /// /// Default = 0.0 @@ -226,7 +248,8 @@ class _RatingBarIndicatorState extends State { @override Widget build(BuildContext context) { - _isRTL = (widget.textDirection ?? Directionality.of(context)) == TextDirection.rtl; + _isRTL = (widget.textDirection ?? Directionality.of(context)) == + TextDirection.rtl; _ratingNumber = widget.rating.truncate() + 1; _ratingFraction = widget.rating - _ratingNumber + 1; return SingleChildScrollView( @@ -278,11 +301,8 @@ class _RatingBarIndicatorState extends State { fit: BoxFit.contain, child: index + 1 < _ratingNumber ? widget.itemBuilder(context, index) - : ColorFiltered( - colorFilter: ColorFilter.mode( - widget.unratedColor ?? Colors.grey[200], - BlendMode.srcATop, - ), + : _ColorFilter( + color: widget.unratedColor ?? Colors.grey[200], child: widget.itemBuilder(context, index), ), ), @@ -314,16 +334,15 @@ class _RatingBarIndicatorState extends State { } /// A widget to receive rating input from users. -/// -/// [RatingBar] can also be used to display rating -/// +/// +/// [RatingBar] can also be used to display rating +/// /// Prefer using [RatingBarIndicator] instead, if read only version is required. /// As RatingBarIndicator supports any fractional rating value. class RatingBar extends StatefulWidget { - /// {@template flutterRatingBar.itemCount} /// Defines total number of rating bar items. - /// + /// /// Default = 5 /// {@endtemplate} final int itemCount; @@ -336,7 +355,7 @@ class RatingBar extends StatefulWidget { /// {@template flutterRatingBar.itemSize} /// Defines width and height of each rating item in the bar. - /// + /// /// Default = 40.0 /// {@endtemplate} final double itemSize; @@ -451,7 +470,8 @@ class _RatingBarState extends State { @override Widget build(BuildContext context) { - _isRTL = (widget.textDirection ?? Directionality.of(context)) == TextDirection.rtl; + _isRTL = (widget.textDirection ?? Directionality.of(context)) == + TextDirection.rtl; if (_ratingHistory != widget.initialRating) { _rating = widget.initialRating; _ratingHistory = widget.initialRating; @@ -515,7 +535,8 @@ class _RatingBarState extends State { height: widget.itemSize, child: FittedBox( fit: BoxFit.contain, - child: widget.ratingWidget?.full ?? widget.itemBuilder(context, index), + child: + widget.ratingWidget?.full ?? widget.itemBuilder(context, index), ), ); iconRating += 1.0; @@ -532,39 +553,36 @@ class _RatingBarState extends State { }); } }, - onHorizontalDragStart: (_) { - if (widget.direction == Axis.horizontal) _glow.value = true; - }, - onHorizontalDragEnd: (_) { - if (widget.direction == Axis.horizontal) { - _glow.value = false; - widget.onRatingUpdate(iconRating); - iconRating = 0.0; - } - }, - onHorizontalDragUpdate: (dragUpdates) { - if (widget.direction == Axis.horizontal) _dragOperation(dragUpdates, widget.direction); - }, - onVerticalDragStart: (_) { - if (widget.direction == Axis.vertical) _glow.value = true; - }, - onVerticalDragEnd: (_) { - if (widget.direction == Axis.vertical) { - _glow.value = false; - widget.onRatingUpdate(iconRating); - iconRating = 0.0; - } - }, - onVerticalDragUpdate: (dragUpdates) { - if (widget.direction == Axis.vertical) _dragOperation(dragUpdates, widget.direction); - }, + onHorizontalDragStart: _isHorizontal ? (_) => _glow.value = true : null, + onHorizontalDragEnd: _isHorizontal + ? (_) { + _glow.value = false; + widget.onRatingUpdate(iconRating); + iconRating = 0.0; + } + : null, + onHorizontalDragUpdate: _isHorizontal + ? (dragUpdates) => _dragOperation(dragUpdates, widget.direction) + : null, + onVerticalDragStart: _isHorizontal ? null : (_) => _glow.value = true, + onVerticalDragEnd: _isHorizontal + ? null + : (_) { + _glow.value = false; + widget.onRatingUpdate(iconRating); + iconRating = 0.0; + }, + onVerticalDragUpdate: _isHorizontal + ? null + : (dragUpdates) => _dragOperation(dragUpdates, widget.direction), child: Padding( padding: widget.itemPadding, child: ValueListenableBuilder( valueListenable: _glow, builder: (context, glow, _) { if (glow && widget.glow) { - Color glowColor = widget.glowColor ?? Theme.of(context).accentColor; + Color glowColor = + widget.glowColor ?? Theme.of(context).accentColor; return DecoratedBox( decoration: BoxDecoration( shape: BoxShape.circle, @@ -593,6 +611,8 @@ class _RatingBarState extends State { ); } + bool get _isHorizontal => widget.direction == Axis.horizontal; + void _dragOperation(DragUpdateDetails dragDetails, Axis direction) { if (!widget.tapOnlyMode) { RenderBox box = context.findRenderObject(); diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 6b94abc..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,139 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - 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.7" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" - 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.5" - 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.5" - 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.5.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 28261f8..180b92e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_rating_bar description: A simple yet fully customizable ratingbar for flutter which also include a rating bar indicator, supporting any fraction of rating. -version: 3.0.0 +version: 3.0.0+1 author: Sarbagya Dhaubanjar repository: https://github.com/sarbagyastha/flutter_rating_bar homepage: https://sarbagyastha.com.np