-
Notifications
You must be signed in to change notification settings - Fork 0
/
star_rating_component.dart
50 lines (43 loc) · 1.11 KB
/
star_rating_component.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'dart:async';
import 'package:angular/angular.dart';
import 'package:angular_components/material_button/material_button.dart';
import 'package:angular_components/material_icon/material_icon.dart';
@Component(
selector: 'mat-star-rating',
templateUrl: './star_rating_component.html',
styleUrls: [
"https://fonts.googleapis.com/icon?family=Material+Icons"
],
encapsulation: ViewEncapsulation.Emulated,
directives: [
MaterialButtonComponent,
MaterialIconComponent,
NgFor
]
)
class StarRatingComponent implements OnInit {
@Input() int rating;
@Input() int starCount;
@Input() String starColor;
final ratingUpdated = new StreamController.broadcast();
@Output() Stream get onRatingClick => ratingUpdated.stream;
var ratingArr = [];
@override
void ngOnInit() {
for (var index = 0; index < starCount; index++) {
ratingArr.add(index);
}
}
onClick(int rating) {
this.rating = rating;
ratingUpdated.add(rating);
return false;
}
showIcon(int index) {
if (rating >= index + 1) {
return 'star';
} else {
return 'star_border';
}
}
}