Skip to content

Commit

Permalink
made states for camera page more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
RhevanKruger committed Oct 22, 2024
1 parent bf65c2c commit dbe5929
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
11 changes: 9 additions & 2 deletions frontend/lib/components/confirm_pop_up.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class _ConfirmationPopUpState extends State<ConfirmationPopUp> {
}
return Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi), // Flip the image horizontally
transform: Matrix4.rotationY(math.pi * 2), // Flip the image horizontally
child: ClipRRect(
borderRadius: BorderRadius.circular(0.0), // No rounding for full-screen image
child: Container(
Expand Down Expand Up @@ -244,6 +244,13 @@ class _ConfirmationPopUpState extends State<ConfirmationPopUp> {
? Theme.of(context).colorScheme.secondary // Use secondary color if transcribed text is not null
: Colors.white, // Use white if transcribed text is null
decoration: TextDecoration.none, // Remove underline
shadows: [
Shadow(
blurRadius: 10.0, // Adjust for more or less blur
color: Colors.black.withOpacity(1), // Subtle black shadow
offset: Offset(0, 2), // Vertical offset to position the shadow
),
],
),
textAlign: TextAlign.center,
),
Expand Down Expand Up @@ -274,7 +281,7 @@ class _ConfirmationPopUpState extends State<ConfirmationPopUp> {
heroTag: 'retake', // Unique tag for retake button
backgroundColor: Theme.of(context).colorScheme.primary, // Keep the FAB's background transparent
onPressed: () {
Navigator.of(context).pop(); // Closes the pop-up
Navigator.of(context).pop(true); // Closes the pop-up
},
child: Icon(
Icons.refresh,
Expand Down
32 changes: 21 additions & 11 deletions frontend/lib/pages/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class _CameraPageState extends State<CameraPage> {
String audioMoodWeight = '';
bool audioReady = false;
bool disabledButton = false;
GlobalKey _buttonKey = GlobalKey(); // Create a GlobalKey for the button



final List<String> modes = ["Photo", "Video", "Audio"];
Expand Down Expand Up @@ -176,8 +178,8 @@ class _CameraPageState extends State<CameraPage> {
await _takeForcedPicture(); // Take a picture if none exists
} else {
int count = 0;
while (!audioReady && count < 10000000000) {
await Future.delayed(Duration(milliseconds: 100)); // Check every 100ms
while (!audioReady && count < 10000) {
await Future.delayed(Duration(milliseconds: 10)); // Check every 100ms
count += 1;
}
disabledButton = false;
Expand Down Expand Up @@ -240,6 +242,7 @@ class _CameraPageState extends State<CameraPage> {
).then((_) {
setState(() {
pictureFile = null; // Reset picture file after dialog closes
disabledButton = false;
});
});
}
Expand Down Expand Up @@ -297,15 +300,15 @@ class _CameraPageState extends State<CameraPage> {
print("RETURNED MOODS");
print(returnedMoods.toString());

if(returnedMoods.length == imagePaths.length) {
if (returnedMoods.length == imagePaths.length) {
returnedMoods.add(audioMoodWeight);
}

// Delay to give visual feedback
await Future.delayed(Duration(milliseconds: 100));

// Send all the captured images during real-time video as a list
Navigator.push(
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ConfirmationPopUp(
Expand All @@ -317,24 +320,30 @@ class _CameraPageState extends State<CameraPage> {
isRealTimeVideo: true,
),
),
).then((_) {
);

if (result == true) {
// Set disabledButton to true when navigating back
setState(() {
pictureFile = null;
returnedMoods.clear();
imagePaths.clear(); // Clear image paths after confirmation
disabledButton = false;
});
}

setState(() {
pictureFile = null;
returnedMoods.clear();
imagePaths.clear(); // Clear image paths after confirmation
});
}


Future<void> _takeForcedPicture() async {
// Capture a picture and fetch mood
if (controller != null && controller!.value.isInitialized) {
pictureFile = await controller!.takePicture();
if (pictureFile != null) {
imagePaths.add(pictureFile!.path); // Add the image path here
await _fetchMood(); // Fetch mood after picture is taken
// Proceed to confirmation after taking the forced picture
// _navigateToConfirmationPage();
}
}
}
Expand Down Expand Up @@ -450,7 +459,8 @@ class _CameraPageState extends State<CameraPage> {
shape: BoxShape.circle,
),
child: RawMaterialButton(
onPressed: _handleButtonPress,
key: _buttonKey, // Assign the GlobalKey to this button
onPressed: disabledButton ? null : _handleButtonPress, // Disable if flag is set
shape: CircleBorder(),
elevation: 2.0,
child: null,
Expand Down

0 comments on commit dbe5929

Please sign in to comment.