Skip to content

Commit

Permalink
recoding app version 2: done rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunhThanhDe committed Sep 19, 2022
1 parent 3e0d84a commit 1f31b33
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 89 deletions.
9 changes: 9 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.box.project.recording_app">

<uses-feature
android:name="android.software.leanback"
android:required="false"
tools:targetApi="eclair" />
<uses-feature android:name="android.hardware.touchscreen"
android:required="false"
tools:targetApi="eclair" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
Expand All @@ -25,6 +33,7 @@
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Expand Down
36 changes: 33 additions & 3 deletions lib/camera_page.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
import 'dart:io';

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

import 'api/uploadFile.dart';
import 'custom_camera.dart';
import 'video_page.dart';

class CameraPage extends StatefulWidget {
const CameraPage({Key? key}) : super(key: key);

@override
_CameraPageState createState() => _CameraPageState();
CameraPageState createState() => CameraPageState();
}

class _CameraPageState extends State<CameraPage> {
class CameraPageState extends State<CameraPage> {
@override
Widget build(BuildContext context) {
return CustomCamera(
color: Colors.white70,
onImageCaptured: (value) {
final path = value.path;
final file = File(path);
if (path.contains('.jpg')) {
showDialog(
context: context,
builder: (context) {
return Scaffold(
appBar: AppBar(
title: Text('Photo'),
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)),
Expand Down
85 changes: 57 additions & 28 deletions lib/custom_camera.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

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

Expand Down Expand Up @@ -93,17 +94,36 @@ class _CustomCameraState extends State<CustomCamera> {
key: const ValueKey(0),
children: [
///Camera preview
SizedBox(
height: MediaQuery.of(context).size.height,
Positioned(
top: 90,
bottom: 90,
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: CameraPreview(
controller!,
),
),
),

//appbar
Positioned(
top: 0,
height: 90,
width: MediaQuery.of(context).size.width,
child: CameraPreview(
controller!,
child: Container(
alignment: Alignment.bottomCenter,
color: Colors.black,
child: const Text(
"Capturing...",
style: TextStyle(color: Colors.white, fontSize: 22),
),
),
),

///Side controlls
///Side controls
Positioned(
top: 40,
top: 60,
right: 20,
child: Column(
children: [
Expand All @@ -123,11 +143,13 @@ class _CustomCameraState extends State<CustomCamera> {

///Bottom Controls
Positioned(
bottom: 20,
bottom: 0,
height: 90,
child: Container(
color: Colors.black,
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.all(10),
// padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expand All @@ -141,22 +163,18 @@ class _CustomCameraState extends State<CustomCamera> {
size: 50,
),
),
GestureDetector(
onTap: () {
IconButton(
onPressed: () {
setState(() {
_cameraView = false;
});
},
child: Padding(
padding:
const EdgeInsets.only(top: 20.0, left: 10, right: 10),
child: Icon(
icon: Icon(
Icons.videocam,
color: widget.iconColor,
size: 60,
),
),
)
],
),
),
Expand All @@ -173,21 +191,26 @@ class _CustomCameraState extends State<CustomCamera> {
return Stack(
key: const ValueKey(1),
children: [
SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: CameraPreview(
controller!,
Positioned(
top: 90,
bottom: 90,
child: SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: CameraPreview(
controller!,
),
),
),

///Side controlls
///top controlls
Positioned(
top: 0,
height: 90,
child: Container(
color: Colors.black,
padding: const EdgeInsets.only(top: 35),
width: MediaQuery.of(context).size.width,
color: widget.iconColor,
height: 90,
child: Row(
children: [
Expand All @@ -197,10 +220,12 @@ class _CustomCameraState extends State<CustomCamera> {
child: Container(
alignment: Alignment.center,
child: Text(
_isRecording == false
? 'Video'
: 'Recording',
style: TextStyle(color: widget.iconColor, fontSize: 22),
_isRecording == false ? 'Video' : 'Recording',
style: TextStyle(
color: _isRecording == false
? widget.iconColor
: Colors.red,
fontSize: 22),
),
),
),
Expand All @@ -213,8 +238,10 @@ class _CustomCameraState extends State<CustomCamera> {

///Bottom Controls
Positioned(
bottom: 20,
bottom: 0,
height: 90,
child: Container(
color: Colors.black,
alignment: Alignment.center,
width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.all(20),
Expand Down Expand Up @@ -256,7 +283,9 @@ class _CustomCameraState extends State<CustomCamera> {
setState(() {});
},
icon: Icon(
Icons.play_circle,
_isRecording == false
? Icons.panorama_fish_eye
: Icons.circle_rounded,
color: widget.iconColor,
size: 50,
),
Expand Down
87 changes: 71 additions & 16 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import 'package:flutter/cupertino.dart';
import 'dart:io';

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

import 'camera_page.dart';

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

class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -16,7 +22,7 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: MyHomePage(),
home: const MyHomePage(),
);
}
}
Expand All @@ -28,12 +34,67 @@ class MyHomePage extends StatefulWidget {
State<MyHomePage> createState() => _MyHomePageState();
}

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

Future CheckUserConnection() async {
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
setState(() {
ActiveConnection = true;
Fluttertoast.showToast(
msg: "wifi đã kết nối",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 16.0
);
});
}
} on SocketException catch (_) {
setState(() {
ActiveConnection = false;
Fluttertoast.showToast(
msg: "Hãy kết nối wifi để có thể upload lên server",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 16.0
);
});
}
}

@override
void initState() {
CheckUserConnection();
super.initState();
WidgetsBinding.instance.addObserver(this);
}

@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.inactive ||
state == AppLifecycleState.detached) return;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
title: const Text(
'Camera Flutter App',
style: TextStyle(
fontSize: 20,
Expand All @@ -43,7 +104,7 @@ class _MyHomePageState extends State<MyHomePage> {
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
children: const [
Text(
'Thực hành phát triển ứng dụng record Video từ Camera và Upload video lên Server',
style: TextStyle(
Expand All @@ -63,20 +124,14 @@ class _MyHomePageState extends State<MyHomePage> {
splashColor: Colors.purple,
tooltip: 'Camera',
label: Row(
children: [
children: const [
Icon(Icons.not_started_outlined),
Text(' Start'),
],
),
onPressed: () {
var mySnackBar = SnackBar(
content: Text('wooooo'),
duration: Duration(seconds: 3),
backgroundColor: Colors.green,
);
ScaffoldMessenger.of(context).showSnackBar(mySnackBar);
Navigator.push(
context, CupertinoPageRoute(builder: (context) => CameraPage()));
context, MaterialPageRoute(builder: (context) => const CameraPage()));
},
),
);
Expand Down
Loading

0 comments on commit 1f31b33

Please sign in to comment.