Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "7482962148e8d758338d8a28f589f317e1e42ba4"
revision: "54e66469a933b60ddf175f858f82eaeb97e48c8d"
channel: "stable"

project_type: app
Expand All @@ -13,14 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: 7482962148e8d758338d8a28f589f317e1e42ba4
base_revision: 7482962148e8d758338d8a28f589f317e1e42ba4
- platform: android
create_revision: 7482962148e8d758338d8a28f589f317e1e42ba4
base_revision: 7482962148e8d758338d8a28f589f317e1e42ba4
- platform: ios
create_revision: 7482962148e8d758338d8a28f589f317e1e42ba4
base_revision: 7482962148e8d758338d8a28f589f317e1e42ba4
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
- platform: web
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d

# User provided section

Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {
applicationId "com.example.test_app"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:label="test_app"
android:name="${applicationName}"
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:test_app/screens/HomePage.dart';

void main() {

runApp(const MyApp());
}

Expand Down
20 changes: 20 additions & 0 deletions lib/screens/HomePage.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// ignore_for_file: file_names

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:test_app/screens/ChatPage.dart';
import 'package:test_app/screens/camera.dart';

class HomePage extends StatefulWidget {
const HomePage({super.key});
Expand All @@ -11,6 +13,7 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {

List menuItems = [
"New Group",
"New Broadcast",
Expand Down Expand Up @@ -84,6 +87,23 @@ class _HomePageState extends State<HomePage> {
Text("What's UP"),
Row(
children: [
IconButton(
onPressed:() async {
WidgetsFlutterBinding.ensureInitialized();
try {
final List cameras = await availableCameras();
print(cameras);
final firstCamera = cameras.first;

Navigator.push(context,MaterialPageRoute(builder: (context)=>TakePictureScreen(camera: firstCamera))
);
} catch (e) {
print("camera not found ");
}

},
icon:Icon(Icons.camera_alt),
),
Icon(Icons.search),
PopupMenuButton<String>(
onSelected: (value) => {print(value)},
Expand Down
121 changes: 121 additions & 0 deletions lib/screens/camera.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import 'dart:io';

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class TakePictureScreen extends StatefulWidget {
const TakePictureScreen({
super.key,
required this.camera,
});

final CameraDescription camera;

@override
TakePictureScreenState createState() => TakePictureScreenState();
}

class TakePictureScreenState extends State<TakePictureScreen> {
late CameraController _controller;
late Future<void> _initializeControllerFuture;

@override
void initState() {
super.initState();
// To display the current output from the Camera,
// create a CameraController.
_controller = CameraController(
// Get a specific camera from the list of available cameras.
widget.camera,
// Define the resolution to use.
ResolutionPreset.medium,
);

// Next, initialize the controller. This returns a Future.
_initializeControllerFuture = _controller.initialize();
}

@override
void dispose() {
// Dispose of the controller when the widget is disposed.
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Take a picture')),
// You must wait until the controller is initialized before displaying the
// camera preview. Use a FutureBuilder to display a loading spinner until the
// controller has finished initializing.
body: Column(
children: [
Expanded(
child: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// If the Future is complete, display the preview.
return CameraPreview(_controller);
} else {
// Otherwise, display a loading indicator.
return const Center(child: CircularProgressIndicator());
}
},
),
),
IconButton(

onPressed: () async {

try {
// Ensure that the camera is initialized.
await _initializeControllerFuture;

// Attempt to take a picture and get the file `image`
// where it was saved.
final image = await _controller.takePicture();

if (!context.mounted) return;


await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(

imagePath: image.path,
),
),
);
} catch (e) {

print(e);
}
},
icon: Icon(Icons.camera_alt),
),
],
),

);
}
}

// A widget that displays the picture taken by the user.
class DisplayPictureScreen extends StatelessWidget {
final String imagePath;

const DisplayPictureScreen({super.key, required this.imagePath});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Display the Picture')),
// The image is stored as a file on the device. Use the `Image.file`
// constructor with the given path to display the image.
body: Image.file(File(imagePath)),
);
}
}
Loading