Skip to content

Commit

Permalink
recoding app version 3: rotate camera and img for tv
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunhThanhDe committed Sep 19, 2022
1 parent 27313fc commit 5051eef
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 69 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
android:required="false"
tools:targetApi="eclair" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:label="recording_app"
Expand Down
5 changes: 3 additions & 2 deletions lib/api/uploadFile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:http/http.dart' as http;

Future<bool> uploadFile(BuildContext context, File file) async {
showDialog(
// // The user CANNOT close this dialog by pressing outsite it
// The user CANNOT close this dialog by pressing outsite it
barrierDismissible: false,
context: context,
builder: (_) {
Expand Down Expand Up @@ -35,10 +35,11 @@ Future<bool> uploadFile(BuildContext context, File file) async {
);
});
var request = http.MultipartRequest(
'POST', Uri.parse('http://192.168.1.64:5000/uploadFile'));
'POST', Uri.parse('http://192.168.1.40:5000/uploadFile'));
request.files.add(await http.MultipartFile.fromPath('file', file.path));
var response = await request.send();

Navigator.of(context).pop();
// Close the dialog programmatically
if (response.statusCode == 200) {
return true;
Expand Down
70 changes: 34 additions & 36 deletions lib/camera_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
Expand Down Expand Up @@ -27,39 +28,39 @@ class CameraPageState extends State<CameraPage> {
context: context,
builder: (context) {
return Scaffold(
appBar: AppBar(
title: const Text('Photo'),
centerTitle: true,
backgroundColor: Colors.black,
actions: [
IconButton(
onPressed: () async {
var request = await uploadFile(context, file).whenComplete((){
Navigator.of(context).pop();
});
if(request){
Fluttertoast.showToast(
msg: "Upload Success!!!!!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0
);
}
},
icon: const Icon(
Icons.cloud_upload,
color: Colors.white,
size: 35,
))
],
),
body: AlertDialog(
content: Image.file(File(path)),
),
);
appBar: AppBar(
title: const Text('Photo'),
centerTitle: true,
backgroundColor: Colors.black,
actions: [
IconButton(
onPressed: () async {
var request = await uploadFile(context, file)
.whenComplete(() {});
if (request) {
Fluttertoast.showToast(
msg: "Upload Success!!!!!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0);
}
},
icon: const Icon(
Icons.cloud_upload,
color: Colors.white,
size: 35,
))
],
),
body: Transform.rotate(
angle: 90 * pi / 180,
child: AlertDialog(
content: Image.file(File(path)),
),
));
});
}
},
Expand All @@ -73,10 +74,7 @@ class CameraPageState extends State<CameraPage> {
);
Navigator.push(context, route);
}
///Show video preview .mp4
},
);
// return Container();
}
}

35 changes: 21 additions & 14 deletions lib/custom_camera.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:math';

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -93,15 +94,18 @@ class _CustomCameraState extends State<CustomCamera> {
// Stack là một bộ chứa cho phép đặt các widget con của nó chồng lên nhau
key: const ValueKey(0),
children: [
///Camera preview
//Camera preview
Positioned(
top: 90,
bottom: 90,
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: CameraPreview(
controller!,
child: RotatedBox(
quarterTurns: 1 - controller!.description.sensorOrientation ~/ 90,
child: CameraPreview(
controller!,
),
),
),
),
Expand Down Expand Up @@ -169,12 +173,12 @@ class _CustomCameraState extends State<CustomCamera> {
_cameraView = false;
});
},
icon: Icon(
Icons.videocam,
color: widget.iconColor,
size: 60,
),
icon: Icon(
Icons.videocam,
color: widget.iconColor,
size: 60,
),
),
],
),
),
Expand All @@ -197,8 +201,11 @@ class _CustomCameraState extends State<CustomCamera> {
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: CameraPreview(
controller!,
child: RotatedBox(
quarterTurns: 1 - controller!.description.sensorOrientation ~/ 90,
child: CameraPreview(
controller!,
),
),
),
),
Expand Down Expand Up @@ -344,12 +351,12 @@ class _CustomCameraState extends State<CustomCamera> {
Widget cameraSwitcherWidget() {
return IconButton(
onPressed: () {
if (_isFrontCamera == false) {
setCamera(1);
_isFrontCamera = true;
} else {
if (_isFrontCamera == true) {
setCamera(0);
_isFrontCamera = false;
} else {
setCamera(1);
_isFrontCamera = true;
}
setState(() {});
},
Expand Down
10 changes: 6 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

import 'camera_page.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
// SystemChrome.setEnabledSystemUIMode(
// SystemUiMode.manual, overlays: SystemUiOverlay.values);
runApp(const MyApp());
}

Expand All @@ -34,7 +34,7 @@ class MyHomePage extends StatefulWidget {
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver{
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
bool ActiveConnection = false;

Future CheckUserConnection() async {
Expand Down Expand Up @@ -70,6 +70,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver{
}
}


@override
void initState() {
CheckUserConnection();
Expand Down Expand Up @@ -131,7 +132,8 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver{
),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => const CameraPage()));
context,
MaterialPageRoute(builder: (context) => const CameraPage()));
},
),
);
Expand Down
22 changes: 9 additions & 13 deletions lib/video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,16 @@ class _VideoPageState extends State<VideoPage> {
IconButton(
onPressed: () async {
var request =
await uploadFile(context, widget.file).whenComplete(() {
Navigator.of(context).pop();
});
await uploadFile(context, widget.file).whenComplete(() {});
if (request) {
setState(() {
Fluttertoast.showToast(
msg: "Upload Success!!!!!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0);
});
await Fluttertoast.showToast(
msg: "Upload Success!!!!!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0);
}
},
icon: const Icon(
Expand Down

0 comments on commit 5051eef

Please sign in to comment.