Cree la Rating para generar las estrellas y reutilizarla en la descripción y en los reviews.
rating.dart
import 'package:flutter/material.dart';
class Rating extends StatelessWidget {
double stars;
double marginLeft;
double fontSize;
Rating(this.stars, this.marginLeft, this.fontSize);
Widget getStar(double star) {
var icon = Icons.star;
if (star == 0.5) {
icon = Icons.star_half;
} else if (star < 0.5) {
icon = Icons.star_border;
}
return Container(
margin: EdgeInsets.only(right: 3.0),
child: Icon(
icon,
color: Color(0xFFf2C611),
size: fontSize,
),
);
}
Widget getRating(double stars) {
var list = new List<Widget>();
for (var n = 0; n < 5; n++) {
list.add(getStar(stars));
stars--;
}
return Container(
margin: EdgeInsets.only(left: marginLeft),
child: Row(
children: list,
),
);
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return getRating(stars);
}
}
Utilicé la clase Rating en la clase de Review para generar las estrellas.
review.dart
import 'package:flutter/material.dart';
import 'rating.dart';
class Review extends StatelessWidget {
String pathImage = 'assets/img/frank.jpeg';
String name = 'Francisco Peñalo';
String details = '1 review 5 photos';
double stars = 5;
String comment = 'There is an amazing place in ';
Review(this.pathImage, this.name, this.details, this.stars, this.comment);
@override
Widget build(BuildContext context) {
// TODO: implement build
final userComment = Container(
margin: EdgeInsets.only(left: 20.0),
child: Text(comment,
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Lato',
fontSize: 13.0,
fontWeight: FontWeight.w900,
)),
);
final userInfo = Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20.0),
child: Text(details,
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Lato',
fontSize: 13.0,
color: Color(0xFFa3a5a7),
)),
),
Rating(stars, 5.0, 14.0)
],
);
final userName = Container(
margin: EdgeInsets.only(
left: 20.0,
),
child: Text(name,
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Lato',
fontSize: 17.0,
)),
);
final userDetails = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
userName,
userInfo,
userComment,
],
);
final photo = Container(
margin: EdgeInsets.only(top: 20.0, left: 20.0),
width: 80.0,
height: 80.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(pathImage),
)),
);
return Row(
children: <Widget>[
photo,
userDetails,
],
);
}
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?