forked from thangmam/smoothratingbar
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9c04daf
Showing
11 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
build/ | ||
ios/.generated/ | ||
ios/Flutter/Generated.xcconfig | ||
ios/Runner/GeneratedPluginRegistrant.* | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## [0.0.1] - 02/09/2018 | ||
|
||
### initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# smooth_star_rating 0.0.1 | ||
|
||
A Star rating with swipe enabled increment/decrement | ||
## Getting Started | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.flutter.plugins; | ||
|
||
import io.flutter.plugin.common.PluginRegistry; | ||
|
||
/** | ||
* Generated file. Do not edit. | ||
*/ | ||
public final class GeneratedPluginRegistrant { | ||
public static void registerWith(PluginRegistry registry) { | ||
if (alreadyRegisteredWith(registry)) { | ||
return; | ||
} | ||
} | ||
|
||
private static boolean alreadyRegisteredWith(PluginRegistry registry) { | ||
final String key = GeneratedPluginRegistrant.class.getCanonicalName(); | ||
if (registry.hasPlugin(key)) { | ||
return true; | ||
} | ||
registry.registrarFor(key); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sdk.dir=E:\\eclipse\\android-sdk-windows | ||
flutter.sdk=E:\\flutter | ||
flutter.versionName=0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
library smooth_star_rating; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
typedef void RatingChangeCallback(double rating); | ||
|
||
class StarRating extends StatelessWidget { | ||
final int starCount; | ||
final double rating; | ||
final RatingChangeCallback onRatingChanged; | ||
final Color color; | ||
final Color borderColor; | ||
final double size; | ||
final bool allowHalfRating; | ||
|
||
StarRating( | ||
{this.starCount = 5, | ||
this.rating = 0.0, | ||
this.onRatingChanged, | ||
this.color, | ||
this.borderColor, | ||
this.size, | ||
this.allowHalfRating = true}); | ||
|
||
Widget buildStar(BuildContext context, int index) { | ||
Icon icon; | ||
if (index >= rating) { | ||
icon = new Icon( | ||
Icons.star_border, | ||
color: borderColor ?? Theme.of(context).primaryColor, | ||
size: size ?? 25.0, | ||
); | ||
} else if (index > rating - (allowHalfRating ? 0.5 : 1.0) && | ||
index < rating) { | ||
icon = new Icon( | ||
Icons.star_half, | ||
color: color ?? Theme.of(context).primaryColor, | ||
size: size ?? 25.0, | ||
); | ||
} else { | ||
icon = new Icon( | ||
Icons.star, | ||
color: color ?? Theme.of(context).primaryColor, | ||
size: size ?? 25.0, | ||
); | ||
} | ||
|
||
return new GestureDetector( | ||
onHorizontalDragUpdate: (dragDetails) { | ||
RenderBox box = context.findRenderObject(); | ||
var _pos = box.globalToLocal(dragDetails.globalPosition); | ||
var i = _pos.dx / size; | ||
var newRating = allowHalfRating ? i : i.round().toDouble(); | ||
if (newRating > starCount) { | ||
newRating = starCount.toDouble(); | ||
} | ||
if (newRating < 0) { | ||
newRating = 0.0; | ||
} | ||
this.onRatingChanged ?? onRatingChanged(newRating); | ||
}, | ||
child: icon, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return new Material( | ||
color: Colors.transparent, | ||
child: new Wrap( | ||
alignment: WrapAlignment.start, | ||
children: new List.generate( | ||
starCount, (index) => buildStar(context, index))), | ||
); | ||
} | ||
} |
Oops, something went wrong.