fist commit ftc staff app clone
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import 'dart:io';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
||||
import 'package:ftc_mobile_app/utilities/frequent_functions.dart';
|
||||
import 'package:ftc_mobile_app/web_services/client_services.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class AddEditMemoryBoxScreenController extends GetxController {
|
||||
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
TextEditingController documentTitleController = TextEditingController();
|
||||
TextEditingController noteDetailsController = TextEditingController();
|
||||
|
||||
late final String serviceUserId;
|
||||
|
||||
final file = Rx<File?>(null);
|
||||
|
||||
//Should stores full path of file or url
|
||||
final filePath = "".obs;
|
||||
|
||||
onFileChooseButtonTap() async {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles(type: FileType.media);
|
||||
|
||||
if (result != null && result.files.single.path != null) {
|
||||
if (result.files.single.path!.isVideoFileName ||
|
||||
result.files.single.path!.isImageFileName) {
|
||||
file.value = File(result.files.single.path!);
|
||||
filePath.value = result.files.single.path!;
|
||||
} else {
|
||||
FrequentFunctions.showToast(message: "Unsupported File");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveButtonPress() async {
|
||||
if (file() == null) {
|
||||
FrequentFunctions.showToast(message: "Please select file first");
|
||||
return;
|
||||
}
|
||||
if (noteDetailsController.text.trim().isEmpty) {
|
||||
FrequentFunctions.showToast(message: "Note details field is required");
|
||||
return;
|
||||
}
|
||||
|
||||
var response = await ClientService()
|
||||
.addMemoryBoxFile(
|
||||
userId: serviceUserId,
|
||||
filePath: file.value!.path,
|
||||
noteDetails: noteDetailsController.text,
|
||||
)
|
||||
.showLoader();
|
||||
|
||||
if (response == true) {
|
||||
backButtonPressed(argument: true);
|
||||
} else {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateButtonPress(String id) async {
|
||||
if (noteDetailsController.text.trim().isEmpty) {
|
||||
FrequentFunctions.showToast(message: "Note details field is required");
|
||||
return;
|
||||
}
|
||||
|
||||
var response = await ClientService()
|
||||
.updateMemoryBoxFile(
|
||||
id: id,
|
||||
userId: serviceUserId,
|
||||
filePath: file.value?.path ?? "",
|
||||
noteDetails: noteDetailsController.text,
|
||||
)
|
||||
.showLoader();
|
||||
|
||||
if (response == true) {
|
||||
backButtonPressed(argument: true);
|
||||
} else {
|
||||
FrequentFunctions.showToast(message: response);
|
||||
}
|
||||
}
|
||||
|
||||
void backButtonPressed({dynamic argument}) {
|
||||
Navigator.of(screenKey.currentContext!).pop(argument);
|
||||
}
|
||||
|
||||
void removeFocus() {
|
||||
FocusScope.of(screenKey.currentContext!).unfocus();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
noteDetailsController.dispose();
|
||||
Get.delete<AddEditMemoryBoxScreenController>();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user