KonectarApp/lib/view/helpdesk.dart

227 lines
7.4 KiB
Dart
Raw Normal View History

2024-11-19 12:57:30 +00:00
import 'dart:convert';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:konectar_events/contacts_module/ui_screen/interactionform/widget/custombutton.dart';
import 'package:konectar_events/utils/constants.dart';
import 'package:konectar_events/widgets/customappbar.dart';
import 'package:konectar_events/widgets/customtextfield.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:path/path.dart' as p;
class HelpDeskScreen extends StatefulWidget {
const HelpDeskScreen({super.key});
@override
State<HelpDeskScreen> createState() => _HelpDeskScreenState();
}
class _HelpDeskScreenState extends State<HelpDeskScreen> {
TextEditingController subjectTextController = TextEditingController(text: "");
TextEditingController TextController = TextEditingController(text: "");
String? _selectedValue;
final List<String> type = [
"Question",
"Software Issue",
"Content Issue",
"Training Request",
"Callback Request",
"Feature Request",
];
Widget dropDown({
Widget? underline,
Widget? icon,
TextStyle? style,
TextStyle? hintStyle,
Color? dropdownColor,
}) =>
DropdownButton<String>(
value: _selectedValue,
underline: underline,
icon: Align(alignment: Alignment.centerRight, child: icon),
dropdownColor: dropdownColor,
isExpanded: true,
style: TextStyle(
//fontFamily: "SourceSerif",
color: Colors.black,
fontSize: 14.0,
),
// iconEnabledColor: iconEnabledColor,
onChanged: (String? newValue) {
setState(() {
_selectedValue = newValue;
});
},
hint: Text("Select Type", style: hintStyle),
items: type
.map((session) => DropdownMenuItem<String>(
value: session, child: Text(session)))
.toList());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Help Desk",
style: TextStyle(color: Colors.white),
),
automaticallyImplyLeading: false,
backgroundColor: EventsConstants.blueColor,
centerTitle: true,
),
body: Container(
height: MediaQuery.of(context).size.height / 2,
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
),
CustomTextField(
labelText: "Subject*", controller: subjectTextController),
SizedBox(
height: 30,
),
Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8.0)),
child: dropDown(underline: Container())),
SizedBox(
height: 30,
),
TextFormField(
validator: (value) {
// add email validation
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
// bool emailValid = RegExp(
// r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+")
// .hasMatch(value);
// if (!emailValid) {
// return 'Please enter a valid email';
// }
return null;
},
maxLines: 3,
decoration: const InputDecoration(
labelText: 'Description',
hintText: 'Description',
border: OutlineInputBorder(),
),
),
SizedBox(
height: 10,
),
Row(
children: [
Text("Attach a file :"),
SizedBox(
width: 10,
),
CustomButton(
backgroundColor: const Color.fromARGB(255, 233, 229, 229),
onPressed: () async {
// sectionItem.selectedValue = [];
// sectionItem.extension = [];
// sectionItem.fileName = [];
await getEncodedFile();
setState(() {});
},
width: 120,
height: 40,
fontsize: 12,
textColor: Colors.black,
title: "Choose file"),
],
),
SizedBox(
height: 30,
),
Center(
child: CustomButton(
backgroundColor: EventsConstants.blueColor,
onPressed: () => (),
title: "Submit",
textColor: Colors.white,
),
)
],
),
),
);
}
Future<void> getEncodedFile() async {
String base64Image = '';
var status = Platform.isAndroid
? await Permission.manageExternalStorage.status
: await Permission.storage.status;
if (status.isGranted) {
FilePickerResult? result =
await FilePicker.platform.pickFiles(allowMultiple: true);
if (result != null) {
print(result.files.first.path);
print(result.files.last.path);
for (var files in result.files) {
File file = File(files.path!);
print("check file path : ${file.path}");
var fileName = file.path.split('/').last;
// Get the application folder directory
Directory? directory = Platform.isAndroid
? await getExternalStorageDirectory() //FOR ANDROID
: await getApplicationDocumentsDirectory();
String newPath = ""; //FOR ios
String convertedDirectoryPath = (directory?.path).toString();
print("see the converted directory path $convertedDirectoryPath");
newPath = "$convertedDirectoryPath/konectar/files";
print("new path :$newPath");
directory = Directory(newPath);
if (!await directory.exists()) {
await directory.create(recursive: true);
}
File newFile = await file.copy('${directory.path}/$fileName');
print("new path is ${newFile.path}");
final extension = p.extension(newFile.path);
List<int> imageBytes = await newFile.readAsBytes();
Uint8List imageUint8List = Uint8List.fromList(imageBytes);
base64Image = base64Encode(imageUint8List);
// sectionItem.selectedValue!.add(base64Image);
// sectionItem.extension!.add(extension);
// sectionItem.fileName!.add(fileName);
}
}
} else {
print("not permitted");
await requestPermission(Platform.isAndroid
? Permission.manageExternalStorage
: Permission.storage);
}
}
Future<void> requestPermission(Permission permission) async {
final status = await permission.request();
setState(() {
print(status);
// _permissionStatus = status;
// print(_permissionStatus);
});
}
}