Skip to content

Commit

Permalink
recoding app version 5: final, The application can run on android tv,…
Browse files Browse the repository at this point in the history
… phone
  • Loading branch information
ChunhThanhDe committed Sep 23, 2022
1 parent bd97812 commit beafd89
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 102 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# recording_app

A new Flutter project.
The application can run on android tv, phone

## Getting Started

Expand Down
5 changes: 3 additions & 2 deletions lib/api/uploadFile.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -34,8 +35,7 @@ Future<bool> uploadFile(BuildContext context, File file) async {
),
);
});
var request = http.MultipartRequest(
'POST', Uri.parse('http://192.168.1.40:5000/uploadFile'));
var request = http.MultipartRequest('POST', Uri.parse('http://192.168.88.156:5000/uploadFile'));
request.files.add(await http.MultipartFile.fromPath('file', file.path));
var response = await request.send();

Expand All @@ -47,3 +47,4 @@ Future<bool> uploadFile(BuildContext context, File file) async {
return false;
}
}

46 changes: 24 additions & 22 deletions lib/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class CameraPage extends StatefulWidget {
CameraPageState createState() => CameraPageState();
}

class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{

class CameraPageState extends State<CameraPage> with WidgetsBindingObserver {
//rotate BuilderFuture
int quarterTurns = 0;

Future<void> CheckUserConnection() async {
Future<void> checkUserConnection() async {
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
Expand All @@ -32,8 +31,7 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 16.0
);
fontSize: 16.0);
});
}
} on SocketException catch (_) {
Expand All @@ -45,15 +43,14 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 16.0
);
fontSize: 16.0);
});
}
}

@override
void initState() {
CheckUserConnection();
checkUserConnection();
super.initState();
WidgetsBinding.instance.addObserver(this);
}
Expand All @@ -67,14 +64,16 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.inactive || state == AppLifecycleState.detached) {
if (state == AppLifecycleState.inactive ||
state == AppLifecycleState.detached) {
return;
}
}

@override
Widget build(BuildContext context) {
if (MediaQuery.of(context).size.width > MediaQuery.of(context).size.height ) {
if (MediaQuery.of(context).size.width >
MediaQuery.of(context).size.height) {
quarterTurns = 1;
}
return CustomCamera(
Expand All @@ -101,21 +100,14 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
builder: (context) => const CameraPage()));
},
),
// Builder(
// builder: (BuildContext context) {
// return IconButton(
// icon: const Icon(Icons.menu),
// onPressed: () { Scaffold.of(context).openDrawer(); },
// tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
// );
// },
// ),
title: const Text('Photo'),
centerTitle: true,
backgroundColor: Colors.black,
actions: [
IconButton(
onPressed: () async {
onPressed:
//() => _uploadFile(file),
() async {
var request = await uploadFile(context, file)
.whenComplete(() {});
if (request) {
Expand All @@ -127,6 +119,15 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0);
} else {
await Fluttertoast.showToast(
msg: "Something wrong, you should check connect internet or Url ",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0);
}
},
icon: const Icon(
Expand All @@ -137,7 +138,7 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
],
),
body: RotatedBox(
quarterTurns: quarterTurns,
quarterTurns: quarterTurns,
child: PhotoView(
imageProvider: FileImage(file),
),
Expand All @@ -155,7 +156,8 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver{
// );
Navigator.push(
context,
MaterialPageRoute(builder: (context) => VideoPage(filePath: path, file: file)));
MaterialPageRoute(
builder: (context) => VideoPage(filePath: path, file: file)));
}
},
);
Expand Down
167 changes: 104 additions & 63 deletions lib/custom_camera.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:async';

import 'dart:developer';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -53,6 +53,7 @@ class _CustomCameraState extends State<CustomCamera>

Future initCamera() async {
cameras = await availableCameras();
log('initCamera: $cameras');
setState(() {});
}

Expand Down Expand Up @@ -135,7 +136,13 @@ class _CustomCameraState extends State<CustomCamera>
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
cameraSwitcherWidget(),
IconButton(
onPressed: () => SystemNavigator.pop(),
icon: const Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 30,
)),
const Text(
"Capturing...",
style: TextStyle(color: Colors.white, fontSize: 22),
Expand All @@ -158,7 +165,18 @@ class _CustomCameraState extends State<CustomCamera>
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
cameraSwitcherWidget(),
IconButton(
onPressed: () {
setState(() {
_cameraView = false;
});
},
icon: const Icon(
Icons.videocam,
color: Colors.white,
size: 35,
),
),
Stack(
children: [
const Icon(
Expand All @@ -178,22 +196,40 @@ class _CustomCameraState extends State<CustomCamera>
),
],
),
IconButton(
onPressed: () {
setState(() {
_cameraView = false;
});
},
icon: const Icon(
Icons.videocam,
color: Colors.white,
size: 44,
),
),
cameraSwitcherWidget(),
],
),
),
)
),

///Side Controls
Positioned(
right: 0,
top: 90,
child: DropdownButton<ResolutionPreset>(
dropdownColor: Colors.black87,
underline: Container(),
value: currentResolutionPreset,
items: [
for (ResolutionPreset preset in resolutionPresets)
DropdownMenuItem(
value: preset,
child: Text(
preset.toString().split('.')[1].toUpperCase(),
style: const TextStyle(color: Colors.white),
),
)
],
onChanged: (value) {
setState(() {
currentResolutionPreset = value!;
controller =
CameraController(cameras![0], currentResolutionPreset);
});
setCamera(0);
},
),
),
],
);
}
Expand All @@ -206,6 +242,8 @@ class _CustomCameraState extends State<CustomCamera>
return Stack(
key: const ValueKey(1),
children: [

///Camera Preview
Positioned(
top: 90,
bottom: 90,
Expand All @@ -221,7 +259,7 @@ class _CustomCameraState extends State<CustomCamera>
),
),

///top controlls
///top controls
Positioned(
top: 0,
height: 90,
Expand All @@ -233,12 +271,14 @@ class _CustomCameraState extends State<CustomCamera>
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
///Front Camera toggle
const Icon(
Icons.line_weight,
color: Colors.white,
size: 44,
),
///Back
IconButton(
onPressed: () => SystemNavigator.pop(),
icon: const Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 30,
)),
Expanded(
child: _isRecording == false
? const Text(
Expand Down Expand Up @@ -279,7 +319,6 @@ class _CustomCameraState extends State<CustomCamera>
),
),
),

///Flash toggle
flashToggleWidget()
],
Expand All @@ -298,7 +337,44 @@ class _CustomCameraState extends State<CustomCamera>
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
_isRecording
? Stack(
children: [
const Icon(
Icons.circle,
color: Colors.black38,
size: 60,
),
IconButton(
onPressed: () async {
//pause and resume video
if (_isRecording == true) {
//pause
if (_isPaused == true) {
///resume
await controller!.resumeVideoRecording();
_stopWatchTimer.onStartTimer();
_isPaused = false;
} else {
///resume
controller!.pauseVideoRecording();
_isPaused = true;
_stopWatchTimer.onStopTimer();
}
}
setState(() {});
},
icon: Icon(
_isPaused == false
? Icons.pause
: Icons.play_arrow,
color: Colors.white,
size: 35,
),
),
],
)
: IconButton(
onPressed: () {
setState(() {
///Show camera view
Expand Down Expand Up @@ -348,48 +424,13 @@ class _CustomCameraState extends State<CustomCamera>
),
],
),
_isRecording
? Stack(
children: [
const Icon(
Icons.circle,
color: Colors.black38,
size: 60,
),
IconButton(
onPressed: () async {
//pause and resume video
if (_isRecording == true) {
//pause
if (_isPaused == true) {
///resume
await controller!.resumeVideoRecording();
_stopWatchTimer.onStartTimer();
_isPaused = false;
} else {
///resume
controller!.pauseVideoRecording();
_isPaused = true;
_stopWatchTimer.onStopTimer();
}
}
setState(() {});
},
icon: Icon(
_isPaused == false
? Icons.pause
: Icons.play_arrow,
color: Colors.white,
size: 30,
),
),
],
)
: cameraSwitcherWidget(),
cameraSwitcherWidget(),
],
),
),
),

///Side Controls
Positioned(
right: 0,
top: 90,
Expand Down
Loading

0 comments on commit beafd89

Please sign in to comment.