Skip to content

Commit

Permalink
project init
Browse files Browse the repository at this point in the history
  • Loading branch information
thangmam committed Sep 2, 2018
0 parents commit 9c04daf
Show file tree
Hide file tree
Showing 11 changed files with 586 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
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/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## [0.0.1] - 02/09/2018

### initial release.
11 changes: 11 additions & 0 deletions LICENSE
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.
6 changes: 6 additions & 0 deletions README.md
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


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;
}
}
3 changes: 3 additions & 0 deletions android/local.properties
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
77 changes: 77 additions & 0 deletions lib/smooth_star_rating.dart
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))),
);
}
}
Loading

0 comments on commit 9c04daf

Please sign in to comment.