Skip to content

Commit

Permalink
recoding app: update for Dart 3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunhThanhDe committed Feb 19, 2024
1 parent abd2895 commit 54c600a
Show file tree
Hide file tree
Showing 9 changed files with 434 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,28 @@

import io.flutter.embedding.android.FlutterActivity;

import android.view.KeyEvent;

public class MainActivity extends FlutterActivity {
}
private boolean isEnterKeyDown = false;

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (!isEnterKeyDown) {
// Generate the Enter down event
KeyEvent enterDownEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER);
isEnterKeyDown = true;
return super.dispatchKeyEvent(enterDownEvent);
}
} else if (event.getAction() == KeyEvent.ACTION_UP && isEnterKeyDown) {
// Generate the Enter up event
KeyEvent enterUpEvent = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER);
isEnterKeyDown = false;
return super.dispatchKeyEvent(enterUpEvent);
}
}
return super.dispatchKeyEvent(event);
}
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
8 changes: 4 additions & 4 deletions lib/api/uploadFile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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 outside it
barrierDismissible: false,
context: context,
builder: (_) {
return Dialog(
return const Dialog(
// The background color
backgroundColor: Colors.black,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: const [
children: [
// The loading indicator
CircularProgressIndicator(
color: Colors.white,
Expand Down
70 changes: 33 additions & 37 deletions lib/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver {
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
setState(() {
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(() {
Fluttertoast.showToast(
msg: "Hãy kết nối wifi để có thể upload lên server",
msg: "wifi đã kết nối",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 16.0);
fontSize: 16.0,
);
});
}
} on SocketException catch (_) {
setState(() {
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,
);
});
}
}
Expand All @@ -64,16 +66,14 @@ 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 @@ -95,9 +95,9 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver {
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CameraPage()));
context,
MaterialPageRoute(builder: (context) => const CameraPage()),
);
},
),
title: const Text('Photo'),
Expand All @@ -108,17 +108,17 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver {
onPressed:
//() => _uploadFile(file),
() async {
var request = await uploadFile(context, file)
.whenComplete(() {});
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);
msg: "Upload Success!!!!!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.white54,
textColor: Colors.white,
fontSize: 20.0,
);
} else {
await Fluttertoast.showToast(
msg: "Something wrong, you should check connect internet or Url ",
Expand Down Expand Up @@ -150,14 +150,10 @@ class CameraPageState extends State<CameraPage> with WidgetsBindingObserver {
File file = File(value.path);
final path = value.path;
if (path.contains('.mp4')) {
// final route = MaterialPageRoute(
// fullscreenDialog: false,
// builder: (_) => VideoPage(filePath: path, file: file),
// );
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoPage(filePath: path, file: file)));
context,
MaterialPageRoute(builder: (context) => VideoPage(filePath: path, file: file)),
);
}
},
);
Expand Down
Loading

0 comments on commit 54c600a

Please sign in to comment.