// ignore_for_file: use_build_context_synchronously
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';
import '../Ad7_viewModel/Ad7_view_model_screen.dart';
import 'Ad7_fields.dart';import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
import '../../../../utils/image_constant.dart';
import '../../../../utils/size_utils.dart';
import '../../../../theme/app_style.dart';
import '../../../../widgets/app_bar/appbar_image.dart';
import '../../../../widgets/app_bar/appbar_title.dart';
import '../../../../widgets/app_bar/custom_app_bar.dart';
import '../../../../widgets/custom_button.dart';
import '../../../../widgets/custom_text_form_field.dart'; 
import '../../../../widgets/custom_dropdown_field.dart';
import 'dart:math';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'package:intl/intl.dart';
 
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../../../../Reuseable/reusable_date_picker_field.dart';
import '../../../../Reuseable/reusable_date_time_picker_field.dart'
;import 'package:multi_select_flutter/multi_select_flutter.dart';
import 'package:just_audio/just_audio.dart';
import 'package:video_player/video_player.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:lottie/lottie.dart';
import '../../../../utils/toast_messages/toast_message_util.dart';
import 'dart:io';
import '../../../../Reuseable/reusable_text_field.dart';
import '../../../../Reuseable/reusable_dropdown_field.dart';




class Ad7CreateEntityScreen extends StatefulWidget {
  const Ad7CreateEntityScreen({super.key});

  @override
  _Ad7CreateEntityScreenState createState() => _Ad7CreateEntityScreenState();
}

class _Ad7CreateEntityScreenState extends State<Ad7CreateEntityScreen> {

final Map<String, dynamic> formData = {};
  final _formKey = GlobalKey<FormState>();
  
  @override
  Widget build(BuildContext context) {
    return Consumer<Ad7ViewModelScreen>(
      builder: (context, viewModel, child) {
        return EntityCreateScreen(
          fields: Ad7Fields.getFields(context),
          onSubmit: (data) => _handleSubmit(data),
          title: 'Ad7',
          isLoading: viewModel.isLoading,
          errorMessage:
              viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
        );
      },
    );
  }

  Future<void> _handleSubmit(Map<String, dynamic> formData) async {
    final provider =
        Provider.of<Ad7ViewModelScreen>(context, listen: false);
    final success = await provider.createEntity(formData);

    if (success && mounted) {
      Navigator.pop(context);
    }
  }
}