Updated content screen

This commit is contained in:
Moe Poi ~ 2021-08-24 22:16:49 +07:00
parent aba312cd76
commit 097dc87f27

View file

@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:easy_learn/view/widgets/custom_button.dart'; import 'package:easy_learn/view/widgets/custom_button.dart';
import 'package:easy_learn/view/widgets/score_board.dart'; import 'package:easy_learn/view/widgets/score_board.dart';
import 'package:easy_learn/view/widgets/list_contents_box.dart'; import 'package:easy_learn/view/widgets/content_box.dart';
import 'package:easy_learn/config.dart' show model, label, inputType, numOfInferences, sampleRate, recordingLength, bufferSize, detectionThreshold; import 'package:easy_learn/config.dart' show model, label, inputType, numOfInferences, sampleRate, recordingLength, bufferSize, detectionThreshold;
@ -23,6 +23,53 @@ class _ContentState extends State<Content> {
final isRecording = ValueNotifier<bool>(false); final isRecording = ValueNotifier<bool>(false);
Stream<Map<dynamic, dynamic>>? result; Stream<Map<dynamic, dynamic>>? result;
int counter = 0;
final List<dynamic> contents = [
{
"title": "yes",
},
{
"title": "no",
},
{
"title": "up",
},
{
"title": "down",
},
{
"title": "left",
},
{
"title": "right",
},
{
"title": "on",
},
{
"title": "off",
},
{
"title": "stop",
},
{
"title": "go",
},
];
void next() {
setState(() {
counter++;
});
}
void previous() {
setState(() {
counter--;
});
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -49,7 +96,12 @@ class _ContentState extends State<Content> {
).onDone(() => isRecording.value = false); ).onDone(() => isRecording.value = false);
} }
String showResult(AsyncSnapshot snapshot, String key) => snapshot.hasData ? snapshot.data[key].toString() : 'null '; String showResult(AsyncSnapshot snapshot, String key) {
if (snapshot.hasData) {
return snapshot.data[key].toString();
}
return '-';
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -67,7 +119,7 @@ class _ContentState extends State<Content> {
scoreBoard = const ScoreBoard(score: "-",); scoreBoard = const ScoreBoard(score: "-",);
break; break;
default: default:
scoreBoard = ScoreBoard(score: showResult(snapshot, 'recognitionResult'),); scoreBoard = ScoreBoard(score: showResult(snapshot, 'recognitionResult') == contents[counter]["title"] ? showResult(snapshot, 'inferenceTime') : '-',);
} }
return Container( return Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
@ -100,19 +152,27 @@ class _ContentState extends State<Content> {
children: [ children: [
Container( Container(
margin: const EdgeInsets.only(left: 5.0), margin: const EdgeInsets.only(left: 5.0),
child: CustomButton(name: 'previous', size: 100.0, navigator: () {},) child: CustomButton(name: 'previous', size: 100.0, navigator: () {
if (counter != 0) {
previous();
}
},)
), ),
const SizedBox( SizedBox(
width: 180, width: 180,
height: 180, height: 180,
child: ListContentsBox( child: ContentBox(
imagePath: 'assets/images/list_contents_animals.png', imagePath: 'assets/images/content_${contents[counter]["title"]}.png',
title: 'Animals' title: contents[counter]["title"]
), ),
), ),
Container( Container(
margin: const EdgeInsets.only(right: 5.0), margin: const EdgeInsets.only(right: 5.0),
child: CustomButton(name: 'next', size: 100.0, navigator: () {}) child: CustomButton(name: 'next', size: 100.0, navigator: () {
if (counter != 9) {
next();
}
})
) )
], ],
), ),
@ -137,7 +197,7 @@ class _ContentState extends State<Content> {
} }
) )
], ],
), )
], ],
), ),
); );