-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera Feature (WIP) #170
Draft
cathli66
wants to merge
2
commits into
master
Choose a base branch
from
cl893/photos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Camera Feature (WIP) #170
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:camera/camera.dart'; | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
import 'package:flutter_svg/flutter_svg.dart'; | ||
|
||
class CameraPage extends StatefulWidget { | ||
const CameraPage({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<CameraPage> createState() => _CameraPageState(); | ||
} | ||
|
||
class _CameraPageState extends State<CameraPage> { | ||
late List<CameraDescription> _cameras; | ||
late CameraController _controller; | ||
int _selected = 0; | ||
String imagePath = ""; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
setupCamera(); | ||
} | ||
|
||
Future<void> setupCamera() async { | ||
await [ | ||
Permission.camera, | ||
].request(); | ||
_cameras = await availableCameras(); | ||
|
||
_controller = CameraController(_cameras[_selected], ResolutionPreset.max); | ||
_controller.initialize().then((_) { | ||
if (!mounted) { | ||
return; | ||
} | ||
setState(() {}); | ||
}).catchError((Object e) { | ||
if (e is CameraException) { | ||
switch (e.code) { | ||
case 'CameraAccessDenied': | ||
// Handle access errors here. | ||
break; | ||
default: | ||
// Handle other errors here. | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
toggleCamera() async { | ||
int newSelected = (_selected + 1) % _cameras.length; | ||
_selected = newSelected; | ||
|
||
var controller = | ||
await CameraController(_cameras[_selected], ResolutionPreset.max); | ||
setState(() => _controller = controller); | ||
} | ||
|
||
void takePhoto() async { | ||
try { | ||
final image = await _controller.takePicture(); | ||
setState(() { | ||
imagePath = image.path; | ||
//TODO: save image path to backend | ||
}); | ||
} catch (e) { | ||
print(e); | ||
} | ||
} | ||
|
||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Container( | ||
padding: EdgeInsets.only(top: 80.0), | ||
decoration: BoxDecoration( | ||
gradient: LinearGradient( | ||
colors: [ | ||
Color.fromARGB(255, 237, 86, 86), | ||
Color.fromARGB(77, 237, 86, 86) | ||
], // Adjust colors as needed | ||
begin: Alignment.topCenter, | ||
end: Alignment.bottomCenter, | ||
stops: [0.0, 0.5], // Adjust stops as needed | ||
tileMode: TileMode.clamp, | ||
), | ||
), | ||
child: Column( | ||
children: [ | ||
Row( | ||
children: [ | ||
TextButton( | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}, | ||
style: TextButton.styleFrom( | ||
backgroundColor: Color.fromARGB(0, 0, 0, 0)), | ||
child: Row( | ||
children: [ | ||
Padding( | ||
padding: EdgeInsets.only(right: 8.0), | ||
child: SvgPicture.asset( | ||
"assets/icons/back.svg", | ||
width: 6, | ||
height: 14, | ||
colorFilter: ColorFilter.mode( | ||
Color.fromARGB(255, 96, 67, 91), BlendMode.srcIn), | ||
), | ||
), | ||
Text( | ||
"Leave Photo", | ||
style: TextStyle( | ||
fontSize: 14, | ||
fontWeight: FontWeight.w400, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
Spacer(), | ||
ElevatedButton( | ||
onPressed: () {}, | ||
child: Text( | ||
"Challenge", | ||
style: TextStyle( | ||
fontSize: 12, | ||
fontWeight: FontWeight.w400, | ||
), | ||
), | ||
) | ||
], | ||
), | ||
Text( | ||
"Remember this moment with a photo!", | ||
style: TextStyle( | ||
fontSize: 18, | ||
fontWeight: FontWeight.w700, | ||
), | ||
), | ||
imagePath == "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you can use a better state here instead of imagePath == "". It's confusing to see why an empty image path means we have a camera preview. If you plan to keep this, please add a comment explaining why you make this comparison. |
||
? Container( | ||
width: 600, | ||
height: 600, | ||
child: AspectRatio( | ||
aspectRatio: _controller.value.aspectRatio, | ||
child: CameraPreview(_controller), | ||
), | ||
) | ||
: Container( | ||
width: 600, | ||
height: 600, | ||
child: Image.file( | ||
File(imagePath), | ||
), | ||
), | ||
IconButton( | ||
onPressed: takePhoto, | ||
icon: SvgPicture.asset('assets/icons/Shutter.svg'), | ||
), | ||
// Image.file(), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a return type here Future<...> otherwise this returns dynamic