Skip to content

Instantly share code, notes, and snippets.

@ravindu9701
Created August 4, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravindu9701/e54b84c26bddb9dca13685fdc2b64994 to your computer and use it in GitHub Desktop.
Save ravindu9701/e54b84c26bddb9dca13685fdc2b64994 to your computer and use it in GitHub Desktop.
class PredictionWidget extends StatelessWidget {
final List<Prediction> predictions;
const PredictionWidget({Key key, this.predictions}) : super(key: key);
Widget _numberWidget(int num, Prediction prediction) {
return Column(
children: <Widget>[
Text(
'$num',
style: TextStyle(
fontSize: 60,
fontWeight: FontWeight.bold,
color: prediction == null
? Colors.black
: Colors.blue.withOpacity(
(prediction.confidence * 2).clamp(0, 1).toDouble(),
),
),
),
Text(
'${prediction == null ? '' : prediction.confidence.toStringAsFixed(3)}',
style: TextStyle(
fontSize: 12,
),
)
],
);
}
List<dynamic> getPredictionStyles(List<Prediction> predictions) {
List<dynamic> data = [
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
];
predictions?.forEach((prediction) {
data[prediction.index] = prediction;
});
return data;
}
@override
Widget build(BuildContext context) {
var styles = getPredictionStyles(this.predictions);
return Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
for (var i = 0; i < 5; i++) _numberWidget(i, styles[i])
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
for (var i = 5; i < 10; i++) _numberWidget(i, styles[i])
],
)
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment