Skip to content

Instantly share code, notes, and snippets.

@geeksilva97
Created March 10, 2020 13:13
Show Gist options
  • Save geeksilva97/fd43a198b8cb78af07efbc9846b2a8fc to your computer and use it in GitHub Desktop.
Save geeksilva97/fd43a198b8cb78af07efbc9846b2a8fc to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class RatingDialog extends StatefulWidget {
@override
_RatingDialogState createState() => _RatingDialogState();
}
class _RatingDialogState extends State<RatingDialog> {
int _stars = 0;
Widget _buildStar(int starCount) {
return InkWell(
child: Icon(
Icons.star,
// size: 30.0,
color: _stars >= starCount ? Colors.orange : Colors.grey,
),
onTap: () {
setState(() {
_stars = starCount;
});
},
);
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Center(child: Text('Rate this post'),),
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_buildStar(1),
_buildStar(2),
_buildStar(3),
_buildStar(4),
_buildStar(5),
],
),
actions: <Widget>[
FlatButton(
child: Text('CANCEL'),
onPressed: Navigator.of(context).pop,
),
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop(_stars);
},
)
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment