Skip to content
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 Widget Implementation #31

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
9 changes: 5 additions & 4 deletions flutter_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:imacs/screens/camera_screen.dart';
import 'package:imacs/screens/home_screen.dart';
import 'package:imacs/screens/log_displayer_screen.dart';
import 'package:imacs/widgets/nav_bar_widget.dart';

void main() async {
Expand All @@ -18,10 +20,9 @@ class App extends StatelessWidget {
),
routes: {
'/': (BuildContext context) => HomePage(title: 'WARG IMACS'),
'/logs': (BuildContext context) =>
const PlaceholderScreen(title: 'Logs'),
'/camera': (BuildContext context) =>
const PlaceholderScreen(title: 'Camera'),
'/logs': (BuildContext context) => const LogDisplayerScreen(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the logs screen as a placeholder for now

fileContext: '', fileName: ''), // TODO: pass in ctx & name
'/camera': (BuildContext context) => CameraScreen(title: 'Camera'),
'/sitl': (BuildContext context) =>
const PlaceholderScreen(title: 'SITL'),
},
Expand Down
18 changes: 18 additions & 0 deletions flutter_app/lib/screens/camera_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:imacs/widgets/nav_bar_widget.dart';
import 'package:imacs/widgets/camera_widget.dart';

class CameraScreen extends StatelessWidget {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add doc strings to file, see other files for examples

const CameraScreen({Key? key, required this.title}) : super(key: key);
final String title;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: CameraWidget(),
bottomNavigationBar: const NavBar());
}
}
59 changes: 59 additions & 0 deletions flutter_app/lib/widgets/camera_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:camera_universal/camera_universal.dart';

/// Widget to display camera feed
class CameraWidget extends StatefulWidget {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the doc string more descriptive

final CameraController cameraController = CameraController();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is never used, you can remove this and make the constructor const


CameraWidget({super.key});
@override
State<CameraWidget> createState() => CameraWidgetState();
}

class CameraWidgetState extends State<CameraWidget> {
CameraController cameraController = CameraController();
@override
void initState() {
super.initState();
task();
}

Future<void> task() async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename function to be more descriptive and add doc string

await cameraController.initializeCameras();
await cameraController.initializeCamera(
setState: setState,
);
await cameraController.activateCamera(
setState: setState,
mounted: () {
return mounted;
},
);
}

@override
void dispose() {
cameraController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Camera(
cameraController: cameraController,
onCameraNotInit: (context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add log messages to each of the fail states

return const SizedBox.shrink();
},
onCameraNotSelect: (context) {
return const SizedBox.shrink();
},
onCameraNotActive: (context) {
return const SizedBox.shrink();
},
onPlatformNotSupported: (context) {
return const SizedBox.shrink();
},
));
}
}
113 changes: 111 additions & 2 deletions flutter_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,62 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
camera:
dependency: transitive
description:
name: camera
sha256: dfa8fc5a1adaeb95e7a54d86a5bd56f4bb0e035515354c8ac6d262e35cec2ec8
url: "https://pub.dev"
source: hosted
version: "0.10.6"
camera_android:
dependency: transitive
description:
name: camera_android
sha256: d8b17e36353cca3fd37e92f3fce28e7249730e078c72e9b43ee7c7ad2e2f7082
url: "https://pub.dev"
source: hosted
version: "0.10.9+16"
camera_avfoundation:
dependency: transitive
description:
name: camera_avfoundation
sha256: "2e4c568f70e406ccb87376bc06b53d2f5bebaab71e2fbcc1a950e31449381bcf"
url: "https://pub.dev"
source: hosted
version: "0.9.17+5"
camera_platform_interface:
dependency: transitive
description:
name: camera_platform_interface
sha256: b3ede1f171532e0d83111fe0980b46d17f1aa9788a07a2fbed07366bbdbb9061
url: "https://pub.dev"
source: hosted
version: "2.8.0"
camera_universal:
dependency: "direct main"
description:
name: camera_universal
sha256: "9d3f9ef623db7b960bbd49be6e95cbf5d9ae479e4f3b19f6aebd62efbb23a6eb"
url: "https://pub.dev"
source: hosted
version: "0.0.3"
camera_web:
dependency: transitive
description:
name: camera_web
sha256: "595f28c89d1fb62d77c73c633193755b781c6d2e0ebcd8dc25b763b514e6ba8f"
url: "https://pub.dev"
source: hosted
version: "0.3.5"
camera_windows:
dependency: transitive
description:
name: camera_windows
sha256: "1f6d1b90048267d69c629deae94ed11a5db76c32afe21b9b58d2a7f1f89cf94d"
url: "https://pub.dev"
source: hosted
version: "0.2.6"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -81,6 +137,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.0"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "7caf6a750a0c04effbb52a676dce9a4a592e10ad35c34d6d2d0e4811160d5670"
url: "https://pub.dev"
source: hosted
version: "0.3.4+2"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -159,11 +223,24 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "9b78450b89f059e96c9ebb355fa6b3df1d6b330436e0b885fb49594c41721398"
url: "https://pub.dev"
source: hosted
version: "2.0.23"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
frontend_server_client:
dependency: transitive
description:
Expand Down Expand Up @@ -324,6 +401,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.3"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
pool:
dependency: transitive
description:
Expand Down Expand Up @@ -417,6 +502,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
stream_transform:
dependency: transitive
description:
name: stream_transform
sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -465,6 +558,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
universal_io:
dependency: transitive
description:
name: universal_io
sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad"
url: "https://pub.dev"
source: hosted
version: "2.2.2"
vector_math:
dependency: transitive
description:
Expand All @@ -489,6 +590,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -514,5 +623,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.24.0"
1 change: 1 addition & 0 deletions flutter_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
camera_universal: ^0.0.3

dev_dependencies:
flutter_test:
Expand Down
1 change: 1 addition & 0 deletions flutter_app/test/unit/camera_widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to complete this file to pass CI/CD

Loading