Created
December 14, 2019 15:44
-
-
Save rrifafauzikomara/02aa4a9c3f6c451b38230ec44d6af75c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import 'package:flutter/material.dart'; | |
class RatingInformation extends StatelessWidget { | |
final double rating; | |
const RatingInformation({Key key, this.rating}) : super(key: key); | |
Widget _buildRatingBar(ThemeData theme) { | |
var stars = <Widget>[]; | |
for (var i = 1; i <= 5; i++) { | |
var color = i <= rating ? theme.accentColor : Colors.black12; | |
var star = Icon( | |
Icons.star, | |
color: color, | |
); | |
stars.add(star); | |
} | |
return Row(children: stars); | |
} | |
@override | |
Widget build(BuildContext context) { | |
var theme = Theme.of(context); | |
var textTheme = theme.textTheme; | |
var ratingCaptionStyle = textTheme.caption.copyWith(color: Colors.black45); | |
var numericRating = Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
Text( | |
rating.toString(), | |
style: textTheme.title.copyWith( | |
fontWeight: FontWeight.w400, | |
color: theme.accentColor, | |
), | |
), | |
SizedBox(height: 4.0), | |
Text( | |
'Ratings', | |
style: ratingCaptionStyle, | |
), | |
], | |
); | |
var starRating = Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
_buildRatingBar(theme), | |
Padding( | |
padding: const EdgeInsets.only(top: 4.0, left: 4.0), | |
child: Text( | |
'Grade now', | |
style: ratingCaptionStyle, | |
), | |
), | |
], | |
); | |
return Row( | |
crossAxisAlignment: CrossAxisAlignment.end, | |
children: [ | |
numericRating, | |
SizedBox(width: 16.0), | |
starRating, | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment