// import 'dart:html' as html; // import 'package:file_picker/file_picker.dart'; // import 'package:flutter/foundation.dart'; // import 'package:flutter/material.dart'; // import 'package:google_fonts/google_fonts.dart'; // import 'package:http/http.dart' as http; // // import 'package:flutter/material.dart'; // import 'package:file_picker/file_picker.dart'; // import 'package:http/http.dart' as http; // import 'package:http_parser/http_parser.dart'; // import 'package:flutter/foundation.dart' show kIsWeb; // // class ThemedUploadField extends FormField { // ThemedUploadField({ // super.key, // String? hintText, // double? txtwidth, // double? txtheight, // Color? backgroundColor, // Color? borderColor, // Color? errorBorderColor, // FormFieldValidator? validator, // Function(String fileName, dynamic file)? onFileSelected, // }) : super( // validator: validator, // builder: (FormFieldState state) { // return _ThemedUploadFieldBody( // hintText: hintText, // txtwidth: txtwidth, // txtheight: txtheight, // backgroundColor: backgroundColor, // borderColor: borderColor, // errorBorderColor: errorBorderColor, // onFileSelected: (fileName, file) { // state.didChange(fileName); // update validation state // onFileSelected?.call(fileName, file); // }, // errorText: state.errorText, // ); // }, // ); // } // // class _ThemedUploadFieldBody extends StatefulWidget { // const _ThemedUploadFieldBody({ // this.hintText, // this.txtwidth, // this.txtheight, // this.backgroundColor, // this.borderColor, // this.errorBorderColor, // this.onFileSelected, // this.errorText, // }); // // final String? hintText; // final double? txtwidth; // final double? txtheight; // final Color? backgroundColor; // final Color? borderColor; // final Color? errorBorderColor; // final Function(String fileName, dynamic file)? onFileSelected; // final String? errorText; // // @override // State<_ThemedUploadFieldBody> createState() => _ThemedUploadFieldBodyState(); // } // // class _ThemedUploadFieldBodyState extends State<_ThemedUploadFieldBody> { // String? selectedFileName; // // // void pickPDFWeb() { // // final uploadInput = html.FileUploadInputElement(); // // uploadInput.accept = '.pdf'; // // uploadInput.click(); // // // // uploadInput.onChange.listen((e) { // // final file = uploadInput.files!.first; // // // // // Ensure PDF type // // if (!file.type.contains("pdf")) { // // ScaffoldMessenger.of( // // context, // // ).showSnackBar(SnackBar(content: Text("Only PDF files allowed"))); // // return; // // } // // // // // Size check (3 MB) // // const maxFileSize = 3 * 1024 * 1024; // // if (file.size > maxFileSize) { // // ScaffoldMessenger.of( // // context, // // ).showSnackBar(SnackBar(content: Text("File exceeds 3MB"))); // // return; // // } // // // // setState(() => selectedFileName = file.name); // // widget.onFileSelected?.call(file.name, file); // // }); // // } // // Future pickPDF() async { // try { // final result = await FilePicker.platform.pickFiles( // type: FileType.custom, // allowedExtensions: ['pdf'], // withData: true, // ); // // if (result != null && result.files.isNotEmpty) { // final file = result.files.first; // PlatformFile // // if (file.extension?.toLowerCase() != "pdf") { // ScaffoldMessenger.of(context).showSnackBar( // const SnackBar(content: Text("Only PDF files allowed")), // ); // return; // } // // if (file.size > 3 * 1024 * 1024) { // ScaffoldMessenger.of( // context, // ).showSnackBar(const SnackBar(content: Text("File exceeds 3MB"))); // return; // } // // setState(() => selectedFileName = file.name); // // // Always pass PlatformFile // widget.onFileSelected?.call(file.name, file); // } // } catch (e, st) { // debugPrint("File picker error: $e\n$st"); // 👈 safer logging // // ScaffoldMessenger.of( // // context, // // ).showSnackBar(const SnackBar(content: Text("Error picking file"))); // } // } // // @override // Widget build(BuildContext context) { // return Column( // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // Container( // width: widget.txtwidth ?? MediaQuery.of(context).size.width, // height: widget.txtheight, // child: DecoratedBox( // decoration: BoxDecoration(borderRadius: BorderRadius.circular(10)), // child: InkWell( // onTap: pickPDF, // borderRadius: BorderRadius.circular(10), // child: Container( // padding: const EdgeInsets.symmetric( // vertical: 10, // horizontal: 15, // ), // decoration: BoxDecoration( // color: widget.backgroundColor ?? Colors.white, // borderRadius: BorderRadius.circular(10), // border: Border.all( // color: widget.errorText != null // ? (widget.errorBorderColor ?? Colors.red) // : (widget.borderColor ?? Colors.grey.shade50), // width: 1, // ), // ), // child: Row( // mainAxisAlignment: MainAxisAlignment.spaceBetween, // children: [ // Expanded( // child: Text( // selectedFileName ?? // widget.hintText ?? // "Upload Documents", // style: TextStyle( // fontSize: 12, // color: widget.errorText != null // ? Colors.red // : Colors.black, // ), // overflow: TextOverflow.ellipsis, // ), // ), // const Icon(Icons.file_upload_outlined, color: Colors.black), // ], // ), // ), // ), // ), // ), // // if (widget.errorText != null) // // Padding( // // padding: const EdgeInsets.only(left: 8, top: 4), // // child: Text( // // widget.errorText!, // // style: const TextStyle(color: Colors.red, fontSize: 10), // // ), // // ), // ], // ); // } // }