import 'dart:developer';

import 'package:auto_size_text/auto_size_text.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hub/actions/actions.dart';
import 'package:hub/backend/api_requests/api_calls.dart';
import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart';
import 'package:hub/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_widget.dart';
import 'package:hub/components/templates_components/visit_request_template_component/visit_request_template_component_widget.dart';
import 'package:hub/components/templates_components/visitor_details_modal_template_component/visitor_details_modal_template_component_widget.dart';
import 'package:hub/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart';
import 'package:hub/flutter_flow/custom_functions.dart';
import 'package:hub/flutter_flow/flutter_flow_drop_down.dart';
import 'package:hub/flutter_flow/flutter_flow_icon_button.dart';
import 'package:hub/flutter_flow/flutter_flow_model.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/flutter_flow/flutter_flow_util.dart';
import 'package:hub/flutter_flow/flutter_flow_widgets.dart';
import 'package:hub/flutter_flow/form_field_controller.dart';
import 'package:hub/flutter_flow/nav/nav.dart';
import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart';
import 'package:provider/provider.dart';

class ScheduleCompleteVisitPageWidget extends StatefulWidget {
  const ScheduleCompleteVisitPageWidget({
    super.key,
    this.visitorStrList,
    this.visitStartDateStr,
    this.visitEndDateStr,
    this.visitReasonStr,
    this.visitLevelStr,
    this.visitTempBol,
    this.visitObsStr,
    this.visitorJsonList,
  });

  final String? visitorStrList;
  final String? visitStartDateStr;
  final String? visitEndDateStr;
  final String? visitReasonStr;
  final String? visitLevelStr;
  final bool? visitTempBol;
  final String? visitObsStr;
  final List<dynamic>? visitorJsonList;

  @override
  State<ScheduleCompleteVisitPageWidget> createState() =>
      _ScheduleCompleteVisitPageWidgetState();
}

class _ScheduleCompleteVisitPageWidgetState
    extends State<ScheduleCompleteVisitPageWidget>
    with TickerProviderStateMixin {
  late ScheduleCompleteVisitPageModel _model;
  int _visitHistoryLoadingIdx = 0;
  final int _visitHistoryLoadingCount = 10;
  List<dynamic> _visitHistoryList = [];
  ScrollController _visitHistoryController = ScrollController();

  final scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  void initState() {
    super.initState();
    _model = createModel(context, () => ScheduleCompleteVisitPageModel());

    // On page load action.
    SchedulerBinding.instance.addPostFrameCallback((_) async {
      if ((widget.visitorStrList != null && widget.visitorStrList != '') &&
          ((widget.visitorJsonList != null &&
                  (widget.visitorJsonList)!.isNotEmpty) !=
              null)) {
        _model.visitorJsonList = widget.visitorJsonList!
            .where((e) =>
                widget.visitorStrList ==
                getJsonField(
                  e,
                  r'''$.VTE_DOCUMENTO''',
                ).toString().toString())
            .toList()
            .toList()
            .cast<dynamic>();
        _model.visitorStrList = widget.visitorStrList!;
        setState(() {});
      } else {
        return;
      }
    });

    _model.tabBarController = TabController(
      vsync: this,
      length: 2,
      initialIndex: 0,
    )..addListener(() => setState(() {}));
    _model.textController1 ??= TextEditingController();
    _model.textFieldFocusNode1 ??= FocusNode();

    _model.textController2 ??= TextEditingController();
    _model.textFieldFocusNode2 ??= FocusNode();

    _model.switchValue = true;
    _model.textController3 ??= TextEditingController();
    _model.textFieldFocusNode3 ??= FocusNode();
  }

  void _loadMoreVisitHistory() async {
    // Simulate fetching data from an API or database
    Future<List<String>> fetchVisitHistory(int start, int limit) async {
      // Simulate network delay
      await Future.delayed(const Duration(seconds: 1));
      // Generate a list of visit history items
      return List.generate(limit, (index) => "Item ${start + index}");
    }

    // Calculate the start index for the next batch of items to load
    final int start = _visitHistoryLoadingIdx * _visitHistoryLoadingCount;
    // Fetch the next batch of items
    final List<String> newItems =
        await fetchVisitHistory(start, _visitHistoryLoadingCount);

    // If new items were fetched, add them to the list and update the index
    if (newItems.isNotEmpty) {
      _visitHistoryList.addAll(newItems);
      _visitHistoryLoadingIdx++;
      setState(() {});
    }
  }

  void_scrollListener() {
    if (_visitHistoryController.position.pixels ==
        _visitHistoryController.position.maxScrollExtent) {
      _loadMoreVisitHistory();
    }
  }

  @override
  void dispose() {
    _model.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    context.watch<FFAppState>();

    return GestureDetector(
      onTap: () => _model.unfocusNode.canRequestFocus
          ? FocusScope.of(context).requestFocus(_model.unfocusNode)
          : FocusScope.of(context).unfocus(),
      child: Scaffold(
        key: scaffoldKey,
        backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
        appBar: appBarScheduleCompleteVisit(context),
        body:
            bodyScheduleCompleteVisit(context, _model, setState, safeSetState),
      ),
    );
  }
}

PreferredSizeWidget appBarScheduleCompleteVisit(BuildContext context) {
  return AppBar(
    backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
    automaticallyImplyLeading: false,
    forceMaterialTransparency: true,
    elevation: 0.0,
    leading: FlutterFlowIconButton(
      borderColor: Colors.transparent,
      borderRadius: 30.0,
      borderWidth: 1.0,
      buttonSize: 60.0,
      icon: Icon(
        Icons.keyboard_arrow_left,
        color: FlutterFlowTheme.of(context).primaryText,
        size: 30.0,
      ),
      onPressed: () async {
        context.pop();
      },
    ),
    title: Text(
      FFLocalizations.of(context).getText(
        '61lcxdgm' /* Agendar Visita */,
      ),
      style: FlutterFlowTheme.of(context).headlineMedium.override(
            fontFamily: 'Nunito',
            color: FlutterFlowTheme.of(context).primaryText,
            fontSize: 15.0,
            letterSpacing: 0.0,
            fontWeight: FontWeight.bold,
            useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'),
          ),
    ),
    actions: const [],
    centerTitle: true,
  );
}

Widget bodyScheduleCompleteVisit(
    BuildContext context,
    ScheduleCompleteVisitPageModel _model,
    Function setState,
    Function safeSetState) {
  return SafeArea(
    top: true,
    child: Column(
      children: [
        Align(
          alignment: const Alignment(0.0, 0),
          child: TabBar(
            labelColor: FlutterFlowTheme.of(context).primaryText,
            unselectedLabelColor: FlutterFlowTheme.of(context).primaryText,
            labelStyle: FlutterFlowTheme.of(context).titleMedium.override(
                  fontFamily: FlutterFlowTheme.of(context).titleMediumFamily,
                  fontSize: 13.0,
                  letterSpacing: 0.0,
                  useGoogleFonts: GoogleFonts.asMap().containsKey(
                      FlutterFlowTheme.of(context).titleMediumFamily),
                ),
            unselectedLabelStyle: const TextStyle(),
            indicatorColor: FlutterFlowTheme.of(context).primary,
            padding: const EdgeInsets.all(4.0),
            tabs: [
              Tab(
                text: FFLocalizations.of(context).getText(
                  'ueth1f4g' /* Cadastrar Visita */,
                ),
              ),
              Tab(
                text: FFLocalizations.of(context).getText(
                  'k4uraqam' /* Histórico de Visitas */,
                ),
              ),
            ],
            controller: _model.tabBarController,
            onTap: (i) async {
              [() async {}, () async {}][i]();
            },
          ),
        ),
        Expanded(
          child: TabBarView(
            controller: _model.tabBarController,
            children: [
              scheduleVisit(context, _model, setState, safeSetState),
              visitHistory(context, _model, safeSetState),
            ],
          ),
        ),
      ],
    ),
  );
}

Widget scheduleVisit(
    BuildContext context,
    ScheduleCompleteVisitPageModel _model,
    Function setState,
    Function safeSetState) {
  return SingleChildScrollView(
    child: Column(
      mainAxisSize: MainAxisSize.max,
      children: [
        Form(
          autovalidateMode: AutovalidateMode.onUserInteraction,
          child: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Column(mainAxisSize: MainAxisSize.max, children: [
                Align(
                  alignment: const AlignmentDirectional(-1.0, 0.0),
                  child: Padding(
                    padding: const EdgeInsetsDirectional.fromSTEB(
                        20.0, 30.0, 0.0, 24.0),
                    child: Text(
                      FFLocalizations.of(context).getText(
                        '98evnbbe' /* Qual o período de validade da ... */,
                      ),
                      textAlign: TextAlign.start,
                      style: FlutterFlowTheme.of(context).bodyMedium.override(
                            fontFamily:
                                FlutterFlowTheme.of(context).bodyMediumFamily,
                            letterSpacing: 0.0,
                            fontWeight: FontWeight.bold,
                            useGoogleFonts: GoogleFonts.asMap().containsKey(
                                FlutterFlowTheme.of(context).bodyMediumFamily),
                          ),
                    ),
                  ),
                ),
                Row(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    SizedBox(
                      width: MediaQuery.of(context).size.width,
                      height: 60.0,
                      // decoration: const BoxDecoration(),
                      child: Stack(
                        children: [
                          Padding(
                            padding: const EdgeInsetsDirectional.fromSTEB(
                                24.0, 0.0, 24.0, 0.0),
                            child: TextFormField(
                                controller: _model.textController1,
                                readOnly: true,
                                focusNode: _model.textFieldFocusNode1,
                                autovalidateMode:
                                    AutovalidateMode.onUserInteraction,
                                autofocus: false,
                                obscureText: false,
                                decoration: InputDecoration(
                                  isDense: true,
                                  labelStyle: FlutterFlowTheme.of(context)
                                      .labelMedium
                                      .override(
                                        fontFamily: FlutterFlowTheme.of(context)
                                            .labelMediumFamily,
                                        color: FlutterFlowTheme.of(context)
                                            .primaryText,
                                        letterSpacing: 0.0,
                                        useGoogleFonts: GoogleFonts.asMap()
                                            .containsKey(
                                                FlutterFlowTheme.of(context)
                                                    .labelMediumFamily),
                                      ),
                                  hintText: FFLocalizations.of(context).getText(
                                    '53cbwqh9' /* Quando você inicia a visita? */,
                                  ),
                                  hintStyle: FlutterFlowTheme.of(context)
                                      .labelMedium
                                      .override(
                                        fontFamily: FlutterFlowTheme.of(context)
                                            .labelMediumFamily,
                                        color: FlutterFlowTheme.of(context)
                                            .primaryText,
                                        letterSpacing: 0.0,
                                        useGoogleFonts: GoogleFonts.asMap()
                                            .containsKey(
                                                FlutterFlowTheme.of(context)
                                                    .labelMediumFamily),
                                        lineHeight: 1.0,
                                      ),
                                  enabledBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                      color:
                                          FlutterFlowTheme.of(context).accent4,
                                      width: 0.5,
                                    ),
                                    borderRadius: BorderRadius.circular(8.0),
                                  ),
                                  focusedBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                      color:
                                          FlutterFlowTheme.of(context).primary,
                                      width: 0.5,
                                    ),
                                    borderRadius: BorderRadius.circular(8.0),
                                  ),
                                  errorBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                      color: FlutterFlowTheme.of(context).error,
                                      width: 0.5,
                                    ),
                                    borderRadius: BorderRadius.circular(8.0),
                                  ),
                                  focusedErrorBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                      color: FlutterFlowTheme.of(context).error,
                                      width: 0.5,
                                    ),
                                    borderRadius: BorderRadius.circular(8.0),
                                  ),
                                  suffixIcon: Icon(
                                    Icons.date_range,
                                    color: FlutterFlowTheme.of(context).accent1,
                                  ),
                                ),
                                style: FlutterFlowTheme.of(context)
                                    .bodyMedium
                                    .override(
                                      fontFamily: FlutterFlowTheme.of(context)
                                          .bodyMediumFamily,
                                      letterSpacing: 0.0,
                                      useGoogleFonts: GoogleFonts.asMap()
                                          .containsKey(
                                              FlutterFlowTheme.of(context)
                                                  .bodyMediumFamily),
                                      lineHeight: 1.8,
                                    ),
                                textAlign: TextAlign.center,
                                validator: _model.textController1Validator
                                    .asValidator(context)),
                          ),
                          Padding(
                            padding: const EdgeInsetsDirectional.fromSTEB(
                                24.0, 0.0, 24.0, 0.0),
                            child: InkWell(
                              splashColor: Colors.transparent,
                              focusColor: Colors.transparent,
                              hoverColor: Colors.transparent,
                              highlightColor: Colors.transparent,
                              onTap: () async {
                                final datePicked1Date = await showDatePicker(
                                  context: context,
                                  initialDate: getCurrentTimestamp,
                                  firstDate: getCurrentTimestamp,
                                  lastDate: DateTime(2050),
                                  builder: (context, child) {
                                    return wrapInMaterialDatePickerTheme(
                                      context,
                                      child!,
                                      headerBackgroundColor:
                                          FlutterFlowTheme.of(context).primary,
                                      headerForegroundColor:
                                          FlutterFlowTheme.of(context).info,
                                      headerTextStyle: FlutterFlowTheme.of(
                                              context)
                                          .headlineLarge
                                          .override(
                                            fontFamily:
                                                FlutterFlowTheme.of(context)
                                                    .headlineLargeFamily,
                                            fontSize: 32.0,
                                            letterSpacing: 0.0,
                                            fontWeight: FontWeight.w600,
                                            useGoogleFonts: GoogleFonts.asMap()
                                                .containsKey(
                                                    FlutterFlowTheme.of(context)
                                                        .headlineLargeFamily),
                                          ),
                                      pickerBackgroundColor:
                                          FlutterFlowTheme.of(context)
                                              .primaryBackground,
                                      pickerForegroundColor:
                                          FlutterFlowTheme.of(context)
                                              .primaryText,
                                      selectedDateTimeBackgroundColor:
                                          FlutterFlowTheme.of(context).primary,
                                      selectedDateTimeForegroundColor:
                                          FlutterFlowTheme.of(context).info,
                                      actionButtonForegroundColor:
                                          FlutterFlowTheme.of(context)
                                              .primaryText,
                                      iconSize: 24.0,
                                    );
                                  },
                                );

                                TimeOfDay? datePicked1Time;
                                if (datePicked1Date != null) {
                                  datePicked1Time = await showTimePicker(
                                    context: context,
                                    initialTime: TimeOfDay.fromDateTime(
                                        getCurrentTimestamp),
                                    builder: (context, child) {
                                      return wrapInMaterialTimePickerTheme(
                                        context,
                                        child!,
                                        headerBackgroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primary,
                                        headerForegroundColor:
                                            FlutterFlowTheme.of(context).info,
                                        headerTextStyle: FlutterFlowTheme.of(
                                                context)
                                            .headlineLarge
                                            .override(
                                              fontFamily:
                                                  FlutterFlowTheme.of(context)
                                                      .headlineLargeFamily,
                                              fontSize: 32.0,
                                              letterSpacing: 0.0,
                                              fontWeight: FontWeight.w600,
                                              useGoogleFonts: GoogleFonts
                                                      .asMap()
                                                  .containsKey(
                                                      FlutterFlowTheme.of(
                                                              context)
                                                          .headlineLargeFamily),
                                            ),
                                        pickerBackgroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primaryBackground,
                                        pickerForegroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primaryText,
                                        selectedDateTimeBackgroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primary,
                                        selectedDateTimeForegroundColor:
                                            FlutterFlowTheme.of(context).info,
                                        actionButtonForegroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primaryText,
                                        iconSize: 24.0,
                                      );
                                    },
                                  );
                                }

                                if (datePicked1Date != null &&
                                    datePicked1Time != null) {
                                  safeSetState(() {
                                    _model.datePicked1 = DateTime(
                                      datePicked1Date.year,
                                      datePicked1Date.month,
                                      datePicked1Date.day,
                                      datePicked1Time!.hour,
                                      datePicked1Time.minute,
                                    );
                                  });
                                }
                                setState(() {
                                  _model.textController1?.text = dateTimeFormat(
                                    'd/M/y H:mm:ss',
                                    _model.datePicked1,
                                    locale: FFLocalizations.of(context)
                                        .languageCode,
                                  );
                                  _model.textController1?.selection =
                                      TextSelection.collapsed(
                                          offset: _model
                                              .textController1!.text.length);
                                });
                              },
                              child: Container(
                                width: double.infinity,
                                height: 80.0,
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(8.0),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Row(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    SizedBox(
                      width: MediaQuery.of(context).size.width,
                      height: 60.0,
                      // decoration: const BoxDecoration(),
                      child: Stack(
                        children: [
                          Padding(
                            padding: const EdgeInsetsDirectional.fromSTEB(
                                24.0, 0.0, 24.0, 0.0),
                            child: TextFormField(
                              readOnly: true,
                              controller: _model.textController2,
                              focusNode: _model.textFieldFocusNode2,
                              autovalidateMode:
                                  AutovalidateMode.onUserInteraction,
                              autofocus: false,
                              obscureText: false,
                              decoration: InputDecoration(
                                isDense: true,
                                labelStyle: FlutterFlowTheme.of(context)
                                    .labelMedium
                                    .override(
                                      fontFamily: FlutterFlowTheme.of(context)
                                          .labelMediumFamily,
                                      color: FlutterFlowTheme.of(context)
                                          .primaryText,
                                      letterSpacing: 0.0,
                                      useGoogleFonts: GoogleFonts.asMap()
                                          .containsKey(
                                              FlutterFlowTheme.of(context)
                                                  .labelMediumFamily),
                                    ),
                                hintText: FFLocalizations.of(context).getText(
                                  'xpgc5e8d' /* Quando a visita terminá? */,
                                ),
                                hintStyle: FlutterFlowTheme.of(context)
                                    .labelMedium
                                    .override(
                                      fontFamily: FlutterFlowTheme.of(context)
                                          .labelMediumFamily,
                                      color: FlutterFlowTheme.of(context)
                                          .primaryText,
                                      letterSpacing: 0.0,
                                      useGoogleFonts: GoogleFonts.asMap()
                                          .containsKey(
                                              FlutterFlowTheme.of(context)
                                                  .labelMediumFamily),
                                      lineHeight: 1.0,
                                    ),
                                enabledBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                    color: FlutterFlowTheme.of(context).accent4,
                                    width: 0.5,
                                  ),
                                  borderRadius: BorderRadius.circular(8.0),
                                ),
                                focusedBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                    color: FlutterFlowTheme.of(context).primary,
                                    width: 0.5,
                                  ),
                                  borderRadius: BorderRadius.circular(8.0),
                                ),
                                errorBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                    color: FlutterFlowTheme.of(context).error,
                                    width: 0.5,
                                  ),
                                  borderRadius: BorderRadius.circular(8.0),
                                ),
                                focusedErrorBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                    color: FlutterFlowTheme.of(context).error,
                                    width: 0.5,
                                  ),
                                  borderRadius: BorderRadius.circular(8.0),
                                ),
                                suffixIcon: Icon(
                                  Icons.date_range,
                                  color: FlutterFlowTheme.of(context).accent1,
                                ),
                              ),
                              style: FlutterFlowTheme.of(context)
                                  .bodyMedium
                                  .override(
                                    fontFamily: FlutterFlowTheme.of(context)
                                        .bodyMediumFamily,
                                    letterSpacing: 0.0,
                                    useGoogleFonts: GoogleFonts.asMap()
                                        .containsKey(
                                            FlutterFlowTheme.of(context)
                                                .bodyMediumFamily),
                                    lineHeight: 1.8,
                                  ),
                              textAlign: TextAlign.center,
                              validator: _model.textController2Validator
                                  .asValidator(context),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsetsDirectional.fromSTEB(
                                24.0, 0.0, 24.0, 0.0),
                            child: InkWell(
                              splashColor: Colors.transparent,
                              focusColor: Colors.transparent,
                              hoverColor: Colors.transparent,
                              highlightColor: Colors.transparent,
                              onTap: () async {
                                final datePicked2Date = await showDatePicker(
                                  context: context,
                                  initialDate: getCurrentTimestamp,
                                  firstDate: getCurrentTimestamp,
                                  lastDate: DateTime(2050),
                                  builder: (context, child) {
                                    return wrapInMaterialDatePickerTheme(
                                      context,
                                      child!,
                                      headerBackgroundColor:
                                          FlutterFlowTheme.of(context).primary,
                                      headerForegroundColor:
                                          FlutterFlowTheme.of(context).info,
                                      headerTextStyle: FlutterFlowTheme.of(
                                              context)
                                          .headlineLarge
                                          .override(
                                            fontFamily:
                                                FlutterFlowTheme.of(context)
                                                    .headlineLargeFamily,
                                            fontSize: 32.0,
                                            letterSpacing: 0.0,
                                            fontWeight: FontWeight.w600,
                                            useGoogleFonts: GoogleFonts.asMap()
                                                .containsKey(
                                                    FlutterFlowTheme.of(context)
                                                        .headlineLargeFamily),
                                          ),
                                      pickerBackgroundColor:
                                          FlutterFlowTheme.of(context)
                                              .primaryBackground,
                                      pickerForegroundColor:
                                          FlutterFlowTheme.of(context)
                                              .primaryText,
                                      selectedDateTimeBackgroundColor:
                                          FlutterFlowTheme.of(context).primary,
                                      selectedDateTimeForegroundColor:
                                          FlutterFlowTheme.of(context).info,
                                      actionButtonForegroundColor:
                                          FlutterFlowTheme.of(context)
                                              .primaryText,
                                      iconSize: 24.0,
                                    );
                                  },
                                );

                                TimeOfDay? datePicked2Time;
                                if (datePicked2Date != null) {
                                  datePicked2Time = await showTimePicker(
                                    context: context,
                                    initialTime: TimeOfDay.fromDateTime(
                                        getCurrentTimestamp),
                                    builder: (context, child) {
                                      return wrapInMaterialTimePickerTheme(
                                        context,
                                        child!,
                                        headerBackgroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primary,
                                        headerForegroundColor:
                                            FlutterFlowTheme.of(context).info,
                                        headerTextStyle: FlutterFlowTheme.of(
                                                context)
                                            .headlineLarge
                                            .override(
                                              fontFamily:
                                                  FlutterFlowTheme.of(context)
                                                      .headlineLargeFamily,
                                              fontSize: 32.0,
                                              letterSpacing: 0.0,
                                              fontWeight: FontWeight.w600,
                                              useGoogleFonts: GoogleFonts
                                                      .asMap()
                                                  .containsKey(
                                                      FlutterFlowTheme.of(
                                                              context)
                                                          .headlineLargeFamily),
                                            ),
                                        pickerBackgroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primaryBackground,
                                        pickerForegroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primaryText,
                                        selectedDateTimeBackgroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primary,
                                        selectedDateTimeForegroundColor:
                                            FlutterFlowTheme.of(context).info,
                                        actionButtonForegroundColor:
                                            FlutterFlowTheme.of(context)
                                                .primaryText,
                                        iconSize: 24.0,
                                      );
                                    },
                                  );
                                }

                                if (datePicked2Date != null &&
                                    datePicked2Time != null) {
                                  safeSetState(() {
                                    _model.datePicked2 = DateTime(
                                      datePicked2Date.year,
                                      datePicked2Date.month,
                                      datePicked2Date.day,
                                      datePicked2Time!.hour,
                                      datePicked2Time.minute,
                                    );
                                  });
                                }
                                setState(() {
                                  _model.textController2?.text = dateTimeFormat(
                                    'd/M/y H:mm:ss',
                                    _model.datePicked2,
                                    locale: FFLocalizations.of(context)
                                        .languageCode,
                                  );
                                  _model.textController2?.selection =
                                      TextSelection.collapsed(
                                          offset: _model
                                              .textController2!.text.length);
                                });
                              },
                              child: Container(
                                width: double.infinity,
                                height: 80.0,
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(8.0),
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ]
                  // .divide(const SizedBox(height: 0.0)),
                  ),
              Column(
                mainAxisSize: MainAxisSize.max,
                children: [
                  Align(
                    alignment: const AlignmentDirectional(-1.0, 0.0),
                    child: Padding(
                      padding: const EdgeInsetsDirectional.fromSTEB(
                          20.0, 24.0, 0.0, 30.0),
                      child: Text(
                        FFLocalizations.of(context).getText(
                          'u0jocx7e' /* Quais visitantes você deseja c... */,
                        ),
                        textAlign: TextAlign.start,
                        style: FlutterFlowTheme.of(context).bodyMedium.override(
                              fontFamily:
                                  FlutterFlowTheme.of(context).bodyMediumFamily,
                              letterSpacing: 0.0,
                              fontWeight: FontWeight.bold,
                              useGoogleFonts: GoogleFonts.asMap().containsKey(
                                  FlutterFlowTheme.of(context)
                                      .bodyMediumFamily),
                            ),
                      ),
                    ),
                  ),
                  if (_model.visitorJsonList.isNotEmpty)
                    Builder(
                      builder: (context) {
                        final visitorListView =
                            _model.visitorJsonList.map((e) => e).toList();
                        return ListView.separated(
                          padding: const EdgeInsets.fromLTRB(
                            0,
                            0,
                            20,
                            20,
                          ),
                          shrinkWrap: true,
                          scrollDirection: Axis.vertical,
                          itemCount: visitorListView.length,
                          separatorBuilder: (_, __) =>
                              const SizedBox(height: 5.0),
                          itemBuilder: (context, visitorListViewIndex) {
                            final visitorListViewItem =
                                visitorListView[visitorListViewIndex];
                            return InkWell(
                              splashColor: Colors.transparent,
                              focusColor: Colors.transparent,
                              hoverColor: Colors.transparent,
                              highlightColor: Colors.transparent,
                              onTap: () async {
                                // await showModalBottomSheet(
                                //   isScrollControlled: true,
                                //   backgroundColor: Colors.transparent,
                                //   enableDrag: false,
                                //   context: context,
                                //   builder: (context) {
                                //     return GestureDetector(
                                //       onTap: () => _model
                                //               .unfocusNode.canRequestFocus
                                //           ? FocusScope.of(context)
                                //               .requestFocus(_model.unfocusNode)
                                //           : FocusScope.of(context).unfocus(),
                                //       child: Padding(
                                //         padding:
                                //             MediaQuery.viewInsetsOf(context),
                                //         child:
                                //             const VisitorDetailsModalTemplateComponentWidget(
                                //           visitorImageURL: '',
                                //           visitorEmail: '',
                                //           visitorName: '',
                                //           visitorPhone: '',
                                //           visitorType: '',
                                //         ),
                                //       ),
                                //     );
                                //   },
                                // ).then((value) => safeSetState(() {}));
                              },
                              onLongPress: () async {
                                // _model.removeFromVisitorJsonList(
                                //     visitorListViewItem);
                                // setState(() {});
                              },
                              child: Container(
                                width: MediaQuery.of(context).size.width,
                                height: 70.0,
                                decoration: BoxDecoration(
                                  color: FlutterFlowTheme.of(context)
                                      .primaryBackground,
                                ),
                                child: Row(
                                  mainAxisSize: MainAxisSize.max,
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    Container(
                                      width: 50.0,
                                      height: 50.0,
                                      clipBehavior: Clip.antiAlias,
                                      decoration: const BoxDecoration(
                                        shape: BoxShape.circle,
                                      ),
                                      child: CachedNetworkImage(
                                        fadeInDuration:
                                            const Duration(milliseconds: 500),
                                        fadeOutDuration:
                                            const Duration(milliseconds: 500),
                                        imageUrl:
                                            "https://freaccess.com.br/freaccess/getImage.php?devUUID=${FFAppState().devUUID}&userUUID=${FFAppState().userUUID}&cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=${getJsonField(
                                          visitorListViewItem,
                                          r'''$.VTE_DOCUMENTO''',
                                        ).toString()}&tipo=E",
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                    Text(
                                      getJsonField(
                                        visitorListViewItem,
                                        r'''$.VTE_NOME''',
                                      ).toString(),
                                      style: FlutterFlowTheme.of(context)
                                          .bodyMedium
                                          .override(
                                            fontFamily:
                                                FlutterFlowTheme.of(context)
                                                    .bodyMediumFamily,
                                            letterSpacing: 0.0,
                                            useGoogleFonts: GoogleFonts.asMap()
                                                .containsKey(
                                                    FlutterFlowTheme.of(context)
                                                        .bodyMediumFamily),
                                          ),
                                    ),
                                    Expanded(
                                      child: Row(
                                        mainAxisSize: MainAxisSize.max,
                                        mainAxisAlignment:
                                            MainAxisAlignment.end,
                                        children: [
                                          IconButton(
                                              onPressed: () async {
                                                _model
                                                    .removeFromVisitorJsonList(
                                                        visitorListViewItem);
                                                setState(() {});
                                              },
                                              icon: const Icon(Icons.close)),
                                        ],
                                      ),
                                    ),
                                  ]
                                      .divide(const SizedBox(width: 30.0))
                                      .addToStart(const SizedBox(width: 30.0)),
                                ),
                              ),
                            );
                          },
                        );
                      },
                    ),
                  Stack(
                    children: [
                      Align(
                        alignment: const AlignmentDirectional(0.01, 0.0),
                        child: Padding(
                          padding: const EdgeInsetsDirectional.fromSTEB(
                              0.0, 0.0, 0.0, 20.0),
                          child: FFButtonWidget(
                            onPressed: () async {
                              await showModalBottomSheet(
                                isScrollControlled: true,
                                isDismissible: true,
                                backgroundColor: FlutterFlowTheme.of(context)
                                    .primaryBackground,
                                enableDrag: true,
                                context: context,
                                builder: (context) {
                                  return GestureDetector(
                                    onTap: () => _model
                                            .unfocusNode.canRequestFocus
                                        ? FocusScope.of(context)
                                            .requestFocus(_model.unfocusNode)
                                        : FocusScope.of(context).unfocus(),
                                    child: SizedBox(
                                      height:
                                          MediaQuery.of(context).size.height *
                                              0.7,
                                      width: MediaQuery.of(context).size.width,
                                      child: Padding(
                                        padding:
                                            MediaQuery.viewInsetsOf(context),
                                        child:
                                            VisitorSearchModalTemplateComponentWidget(
                                          getVisitors: (visitorsParam) async {
                                            _model.visitorJsonList =
                                                visitorsParam!
                                                    .toList()
                                                    .cast<dynamic>();
                                            setState(() {});
                                          },
                                          getDocs: (docsParam) async {
                                            _model.visitorStrList =
                                                strListToStr(
                                                    docsParam!.toList());
                                            setState(() {});
                                          },
                                        ),
                                      ),
                                    ),
                                  );
                                },
                              ).then((value) => safeSetState(() {}));
                            },
                            text: '',
                            icon: Icon(
                              Icons.add,
                              color: FlutterFlowTheme.of(context).primary,
                              size: 30.0,
                            ),
                            options: FFButtonOptions(
                              width: MediaQuery.sizeOf(context).width * 0.8,
                              height: 80.0,
                              padding: const EdgeInsetsDirectional.fromSTEB(
                                  0.0, 0.0, 0.0, 0.0),
                              iconPadding: const EdgeInsetsDirectional.fromSTEB(
                                  14.0, 0.0, 0.0, 20.0),
                              color: FlutterFlowTheme.of(context)
                                  .primaryBackground,
                              textStyle: FlutterFlowTheme.of(context)
                                  .titleSmall
                                  .override(
                                    fontFamily: FlutterFlowTheme.of(context)
                                        .titleSmallFamily,
                                    color: FlutterFlowTheme.of(context)
                                        .primaryText,
                                    fontSize: 16.0,
                                    letterSpacing: 0.0,
                                    useGoogleFonts: GoogleFonts.asMap()
                                        .containsKey(
                                            FlutterFlowTheme.of(context)
                                                .titleSmallFamily),
                                  ),
                              borderSide: BorderSide(
                                color: FlutterFlowTheme.of(context).accent4,
                                width: 1.0,
                              ),
                              borderRadius: BorderRadius.circular(8.0),
                            ),
                          ),
                        ),
                      ),
                      Align(
                        alignment: const AlignmentDirectional(0.0, 0.0),
                        child: Padding(
                          padding: const EdgeInsetsDirectional.fromSTEB(
                              0.0, 50.0, 0.0, 0.0),
                          child: Container(
                            width: MediaQuery.sizeOf(context).width * 0.8,
                            height: 20.0,
                            decoration: const BoxDecoration(),
                            child: Align(
                              alignment: const AlignmentDirectional(0.0, 0.0),
                              child: AutoSizeText(
                                FFLocalizations.of(context).getText(
                                  'r8soavtz' /* Clique para adicionar um visit... */,
                                ),
                                style: FlutterFlowTheme.of(context)
                                    .bodyMedium
                                    .override(
                                      fontFamily: FlutterFlowTheme.of(context)
                                          .bodyMediumFamily,
                                      color: FlutterFlowTheme.of(context)
                                          .primaryText,
                                      letterSpacing: 0.0,
                                      useGoogleFonts: GoogleFonts.asMap()
                                          .containsKey(
                                              FlutterFlowTheme.of(context)
                                                  .bodyMediumFamily),
                                    ),
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
              Column(
                mainAxisSize: MainAxisSize.max,
                children: [
                  Align(
                    alignment: const AlignmentDirectional(-1.0, 0.0),
                    child: Padding(
                      padding: const EdgeInsetsDirectional.fromSTEB(
                          20.0, 24.0, 0.0, 24.0),
                      child: Text(
                        FFLocalizations.of(context).getText(
                          '0meymh6u' /* Quais são os motivos da visita... */,
                        ),
                        textAlign: TextAlign.start,
                        style: FlutterFlowTheme.of(context).bodyMedium.override(
                              fontFamily:
                                  FlutterFlowTheme.of(context).bodyMediumFamily,
                              letterSpacing: 0.0,
                              fontWeight: FontWeight.bold,
                              useGoogleFonts: GoogleFonts.asMap().containsKey(
                                  FlutterFlowTheme.of(context)
                                      .bodyMediumFamily),
                            ),
                      ),
                    ),
                  ),
                  Column(
                    children: [
                      Row(
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Expanded(
                            child: Padding(
                              padding: const EdgeInsetsDirectional.fromSTEB(
                                  24.0, 0.0, 24.0, 0.0),
                              child: Container(
                                width: 100.0,
                                height: 45.0,
                                decoration: const BoxDecoration(),
                                child: FutureBuilder<ApiCallResponse>(
                                  future: PhpGroup.getDadosCall.call(
                                    devUUID: FFAppState().devUUID,
                                    userUUID: FFAppState().userUUID,
                                    cliUUID: FFAppState().cliUUID,
                                    atividade: 'getDados',
                                  ),
                                  builder: (context, snapshot) {
                                    // Customize what your widget looks like when it's loading.
                                    if (!snapshot.hasData) {
                                      return Center(
                                        child: SizedBox(
                                          width: 50.0,
                                          height: 50.0,
                                          child: SpinKitCircle(
                                            color: FlutterFlowTheme.of(context)
                                                .primary,
                                            size: 50.0,
                                          ),
                                        ),
                                      );
                                    }
                                    final dropDownGetDadosResponse =
                                        snapshot.data!;
                                    final reasonsJsonList =
                                        PhpGroup.getDadosCall.reasonsJsonList(
                                      dropDownGetDadosResponse.jsonBody,
                                    );
                                    return FlutterFlowDropDown<String>(
                                      fillColor: FlutterFlowTheme.of(context)
                                          .primaryBackground,
                                      controller:
                                          _model.dropDownValueController1 ??=
                                              FormFieldController<String>(
                                        _model.dropDownValue1 ??= '',
                                      ),
                                      options: reasonsJsonList != null &&
                                              reasonsJsonList != []
                                          ? List<String>.from(
                                              PhpGroup.getDadosCall
                                                  .reasonsJsonList(
                                                    dropDownGetDadosResponse
                                                        .jsonBody,
                                                  )!
                                                  .map((e) => e.toString())
                                                  .toList())
                                          : [],
                                      optionLabels: PhpGroup.getDadosCall
                                          .reasonsMotDescStrList(
                                        dropDownGetDadosResponse.jsonBody,
                                      ),
                                      onChanged: (val) => setState(
                                          () => _model.dropDownValue1 = val),
                                      width: double.infinity,
                                      height: double.infinity,
                                      textStyle: FlutterFlowTheme.of(context)
                                          .bodyMedium
                                          .override(
                                            fontFamily:
                                                FlutterFlowTheme.of(context)
                                                    .bodyMediumFamily,
                                            letterSpacing: 0.0,
                                            useGoogleFonts: GoogleFonts.asMap()
                                                .containsKey(
                                                    FlutterFlowTheme.of(context)
                                                        .bodyMediumFamily),
                                          ),
                                      hintText:
                                          FFLocalizations.of(context).getText(
                                        '6p3e0bzr' /* Escolha um motivo aqui */,
                                      ),
                                      icon: Icon(
                                        Icons.keyboard_arrow_down_rounded,
                                        color: FlutterFlowTheme.of(context)
                                            .accent1,
                                        size: 24.0,
                                      ),
                                      elevation: 2.0,
                                      borderColor:
                                          FlutterFlowTheme.of(context).accent4,
                                      borderWidth: 0.5,
                                      borderRadius: 10.0,
                                      margin:
                                          const EdgeInsetsDirectional.fromSTEB(
                                              16.0, 0.0, 16.0, 0.0),
                                      hidesUnderline: true,
                                      isOverButton: true,
                                      isSearchable: false,
                                      isMultiSelect: false,
                                    );
                                  },
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      if (_model.dropDownValue1 == '')
                        Row(
                          mainAxisSize: MainAxisSize.max,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Padding(
                              padding: const EdgeInsets.symmetric(
                                  horizontal: 30.0, vertical: 5.0),
                              child: Text(
                                  FFLocalizations.of(context).getVariableText(
                                    enText: 'Field is Required',
                                    ptText: 'Campo Obrigatório',
                                  ),
                                  style: TextStyle(
                                      color: FlutterFlowTheme.of(context)
                                          .customColor6,
                                      fontSize: 12.0)),
                            ),
                          ],
                        ),
                    ],
                  ),
                  Column(
                    children: [
                      Row(
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Expanded(
                            child: Padding(
                              padding: const EdgeInsetsDirectional.fromSTEB(
                                  24.0, 0.0, 24.0, 0.0),
                              child: Container(
                                width: 100.0,
                                height: 45.0,
                                decoration: const BoxDecoration(),
                                child: FutureBuilder<ApiCallResponse>(
                                  future: PhpGroup.getDadosCall.call(
                                    devUUID: FFAppState().devUUID,
                                    userUUID: FFAppState().userUUID,
                                    cliUUID: FFAppState().cliUUID,
                                    atividade: 'getDados',
                                  ),
                                  builder: (context, snapshot) {
                                    // Customize what your widget looks like when it's loading.
                                    if (!snapshot.hasData) {
                                      return Center(
                                        child: SizedBox(
                                          width: 50.0,
                                          height: 50.0,
                                          child: SpinKitCircle(
                                            color: FlutterFlowTheme.of(context)
                                                .primary,
                                            size: 50.0,
                                          ),
                                        ),
                                      );
                                    }
                                    final dropDownGetDadosResponse =
                                        snapshot.data!;
                                    final lavelList =
                                        PhpGroup.getDadosCall.levelJsonList(
                                      dropDownGetDadosResponse.jsonBody,
                                    );
                                    return FlutterFlowDropDown<String>(
                                      controller:
                                          _model.dropDownValueController2 ??=
                                              FormFieldController<String>(
                                        _model.dropDownValue2 ??= '',
                                      ),
                                      options:
                                          lavelList != null && lavelList != []
                                              ? List<String>.from(lavelList!
                                                  .map((e) => e.toString())
                                                  .toList())
                                              : [],
                                      optionLabels: PhpGroup.getDadosCall
                                          .levelNACDescricaoStrList(
                                        dropDownGetDadosResponse.jsonBody,
                                      ),
                                      onChanged: (val) => setState(
                                          () => _model.dropDownValue2 = val),
                                      width: double.infinity,
                                      height: double.infinity,
                                      textStyle: FlutterFlowTheme.of(context)
                                          .bodyMedium
                                          .override(
                                            fontFamily:
                                                FlutterFlowTheme.of(context)
                                                    .bodyMediumFamily,
                                            letterSpacing: 0.0,
                                            useGoogleFonts: GoogleFonts.asMap()
                                                .containsKey(
                                                    FlutterFlowTheme.of(context)
                                                        .bodyMediumFamily),
                                          ),
                                      hintText:
                                          FFLocalizations.of(context).getText(
                                        '2wun8p6c' /* Escolha um nível de acesso aqu... */,
                                      ),
                                      icon: Icon(
                                        Icons.keyboard_arrow_down_rounded,
                                        color: FlutterFlowTheme.of(context)
                                            .accent1,
                                        size: 24.0,
                                      ),
                                      elevation: 2.0,
                                      borderColor:
                                          FlutterFlowTheme.of(context).accent4,
                                      borderWidth: 0.5,
                                      borderRadius: 10.0,
                                      margin:
                                          const EdgeInsetsDirectional.fromSTEB(
                                              16.0, 0.0, 16.0, 0.0),
                                      hidesUnderline: true,
                                      fillColor: FlutterFlowTheme.of(context)
                                          .primaryBackground,
                                      isOverButton: true,
                                      isSearchable: false,
                                      isMultiSelect: false,
                                    );
                                  },
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                      if (_model.dropDownValue1 == '')
                        Row(
                          mainAxisSize: MainAxisSize.max,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Padding(
                              padding: const EdgeInsets.symmetric(
                                  horizontal: 30.0, vertical: 5.0),
                              child: Text(
                                  FFLocalizations.of(context).getVariableText(
                                    enText: 'Field is Required',
                                    ptText: 'Campo Obrigatório',
                                  ),
                                  style: TextStyle(
                                      color: FlutterFlowTheme.of(context)
                                          .customColor6,
                                      fontSize: 12.0)),
                            ),
                          ],
                        ),
                    ],
                  ),
                ].divide(const SizedBox(height: 10.0)),
              ),
              Column(
                mainAxisSize: MainAxisSize.max,
                children: [
                  Align(
                    alignment: const AlignmentDirectional(-1.0, 0.0),
                    child: Padding(
                      padding: const EdgeInsetsDirectional.fromSTEB(
                          20.0, 24.0, 0.0, 24.0),
                      child: Text(
                        FFLocalizations.of(context).getText(
                          '8rk26eg1' /* Visita se encerra após o prime... */,
                        ),
                        textAlign: TextAlign.start,
                        style: FlutterFlowTheme.of(context).bodyMedium.override(
                              fontFamily:
                                  FlutterFlowTheme.of(context).bodyMediumFamily,
                              letterSpacing: 0.0,
                              fontWeight: FontWeight.bold,
                              useGoogleFonts: GoogleFonts.asMap().containsKey(
                                  FlutterFlowTheme.of(context)
                                      .bodyMediumFamily),
                            ),
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsetsDirectional.fromSTEB(
                        30.0, 0.0, 30.0, 20.0),
                    child: Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Flexible(
                          child: Padding(
                            padding: const EdgeInsetsDirectional.fromSTEB(
                                0.0, 0.0, 130.0, 0.0),
                            child: Text(
                              FFLocalizations.of(context).getText(
                                'lgv0q5ht' /* Visita única */,
                              ),
                              textAlign: TextAlign.start,
                              style: FlutterFlowTheme.of(context)
                                  .bodyMedium
                                  .override(
                                    fontFamily: FlutterFlowTheme.of(context)
                                        .bodyMediumFamily,
                                    letterSpacing: 0.0,
                                    useGoogleFonts: GoogleFonts.asMap()
                                        .containsKey(
                                            FlutterFlowTheme.of(context)
                                                .bodyMediumFamily),
                                  ),
                            ),
                          ),
                        ),
                        Switch.adaptive(
                          value: _model.switchValue!,
                          onChanged: (newValue) async {
                            setState(() => _model.switchValue = newValue);
                          },
                          applyCupertinoTheme: false,
                          focusColor: FlutterFlowTheme.of(context).primary,
                          trackColor: WidgetStateProperty.resolveWith(
                            (states) {
                              if (states.contains(WidgetState.disabled)) {
                                return FlutterFlowTheme.of(context).alternate;
                              }
                              return FlutterFlowTheme.of(context).alternate;
                            },
                          ),
                          hoverColor:
                              FlutterFlowTheme.of(context).primaryBackground,
                          // thumbColor: WidgetStateColor.resolveWith(
                          //   (states) {
                          //     if (states.contains(WidgetState.disabled)) {
                          //       return FlutterFlowTheme.of(context)
                          //           .alternate;
                          //     }
                          //     return FlutterFlowTheme.of(context)
                          //         .alternate;
                          //   },
                          // ),
                          overlayColor: WidgetStateProperty.resolveWith(
                            (states) {
                              if (states.contains(WidgetState.disabled)) {
                                return FlutterFlowTheme.of(context).accent4;
                              }
                              return FlutterFlowTheme.of(context)
                                  .primaryBackground;
                            },
                          ),
                          trackOutlineColor: WidgetStateProperty.resolveWith(
                            (states) {
                              if (states.contains(WidgetState.disabled)) {
                                return FlutterFlowTheme.of(context).accent4;
                              }
                              return FlutterFlowTheme.of(context)
                                  .primaryBackground;
                            },
                          ),
                          activeColor: FlutterFlowTheme.of(context).success,
                          activeTrackColor:
                              FlutterFlowTheme.of(context).primaryBackground,
                          inactiveTrackColor:
                              FlutterFlowTheme.of(context).primaryBackground,
                          inactiveThumbColor:
                              FlutterFlowTheme.of(context).error,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
              Column(
                mainAxisSize: MainAxisSize.max,
                children: [
                  Align(
                    alignment: const AlignmentDirectional(-1.0, 0.0),
                    child: Padding(
                      padding: const EdgeInsetsDirectional.fromSTEB(
                          20.0, 0.0, 0.0, 24.0),
                      child: Text(
                        FFLocalizations.of(context).getText(
                          'eftcs67c' /* Você tem alguma observação sob... */,
                        ),
                        textAlign: TextAlign.start,
                        style: FlutterFlowTheme.of(context).bodyMedium.override(
                              fontFamily:
                                  FlutterFlowTheme.of(context).bodyMediumFamily,
                              letterSpacing: 0.0,
                              fontWeight: FontWeight.w600,
                              useGoogleFonts: GoogleFonts.asMap().containsKey(
                                  FlutterFlowTheme.of(context)
                                      .bodyMediumFamily),
                            ),
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsetsDirectional.fromSTEB(
                        24.0, 0.0, 24.0, 0.0),
                    child: SizedBox(
                      width: double.infinity,
                      child: TextFormField(
                        controller: _model.textController3,
                        focusNode: _model.textFieldFocusNode3,
                        autofocus: false,
                        textInputAction: TextInputAction.next,
                        obscureText: false,
                        decoration: InputDecoration(
                          isDense: false,
                          labelText: FFLocalizations.of(context).getText(
                            't0q2vuup' /* Observações da Visita */,
                          ),
                          labelStyle: FlutterFlowTheme.of(context)
                              .labelMedium
                              .override(
                                fontFamily: FlutterFlowTheme.of(context)
                                    .labelMediumFamily,
                                color: FlutterFlowTheme.of(context).primaryText,
                                letterSpacing: 0.0,
                                useGoogleFonts: GoogleFonts.asMap().containsKey(
                                    FlutterFlowTheme.of(context)
                                        .labelMediumFamily),
                              ),
                          hintText: FFLocalizations.of(context).getText(
                            'w18iztdm' /* Escreva as suas observações aq... */,
                          ),
                          hintStyle: FlutterFlowTheme.of(context)
                              .labelMedium
                              .override(
                                fontFamily: FlutterFlowTheme.of(context)
                                    .labelMediumFamily,
                                color: FlutterFlowTheme.of(context).primaryText,
                                letterSpacing: 0.0,
                                useGoogleFonts: GoogleFonts.asMap().containsKey(
                                    FlutterFlowTheme.of(context)
                                        .labelMediumFamily),
                              ),
                          enabledBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                              color: FlutterFlowTheme.of(context).accent4,
                              width: 0.5,
                            ),
                            borderRadius: BorderRadius.circular(10.0),
                          ),
                          focusedBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                              color: FlutterFlowTheme.of(context).primary,
                              width: 0.5,
                            ),
                            borderRadius: BorderRadius.circular(10.0),
                          ),
                          errorBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                              color: FlutterFlowTheme.of(context).error,
                              width: 0.5,
                            ),
                            borderRadius: BorderRadius.circular(10.0),
                          ),
                          focusedErrorBorder: OutlineInputBorder(
                            borderSide: BorderSide(
                              color: FlutterFlowTheme.of(context).error,
                              width: 0.5,
                            ),
                            borderRadius: BorderRadius.circular(10.0),
                          ),
                          suffixIcon: Icon(
                            Icons.text_fields,
                            color: FlutterFlowTheme.of(context).accent1,
                          ),
                        ),
                        style: FlutterFlowTheme.of(context).bodyMedium.override(
                              fontFamily:
                                  FlutterFlowTheme.of(context).bodyMediumFamily,
                              color: FlutterFlowTheme.of(context).primaryText,
                              letterSpacing: 0.0,
                              useGoogleFonts: GoogleFonts.asMap().containsKey(
                                  FlutterFlowTheme.of(context)
                                      .bodyMediumFamily),
                            ),
                        textAlign: TextAlign.start,
                        maxLines: null,
                        maxLength: 80,
                        validator: _model.textController3Validator
                            .asValidator(context),
                      ),
                    ),
                  ),
                ],
              ),
              Container(
                width: 100.0,
                height: 54.0,
                decoration: const BoxDecoration(),
              ),
            ],
          ),
        ),
        FFButtonWidget(
          text: FFLocalizations.of(context).getVariableText(
            enText: 'Schedule',
            ptText: 'Agendar',
          ),
          onPressed: _model.isValid()
              ? () async {
                  await showDialog(
                    context: context,
                    builder: (context) {
                      return GestureDetector(
                        onTap: () => _model.unfocusNode.canRequestFocus
                            ? FocusScope.of(context)
                                .requestFocus(_model.unfocusNode)
                            : FocusScope.of(context).unfocus(),
                        child: Dialog(
                          alignment: Alignment.topCenter,
                          child: SizedBox(
                            // width: MediaQuery.of(context).size.width,
                            // height: MediaQuery.of(context).size.height * 0.7,
                            child: VisitDetailsModalTemplateComponentWidget(
                              visitStartDateStr: _model.textController1.text,
                              visitEndDateStr: _model.textController2.text,
                              visitReasonStr: _model.dropDownValue1,
                              visitLevelStr: _model.dropDownValue2,
                              visitTempStr:
                                  _model.switchValue == true ? 'Sim' : 'Não',
                              visitObsStr: _model.textController3.text,
                              visitorStrList: _model.visitorStrList,
                              visitorJsonList: _model.visitorJsonList,
                              updateToggleIdx: () async {},
                              repeatVisitSchedule: () async {},
                            ),
                          ),
                        ),
                      );
                    },
                  ).then((value) => safeSetState(() {}));
                }
              : null,
          options: FFButtonOptions(
              height: MediaQuery.of(context).size.height * 0.05,
              width: MediaQuery.of(context).size.height * 0.2,
              color: FlutterFlowTheme.of(context).primary,
              borderRadius: const BorderRadius.only(
                bottomLeft: Radius.circular(15.0),
                bottomRight: Radius.circular(15.0),
                topLeft: Radius.circular(15.0),
                topRight: Radius.circular(15.0),
              ),
              disabledColor: FlutterFlowTheme.of(context).customColor5),
          showLoadingIndicator: true,
        ),
      ].addToEnd(const SizedBox(height: 30.0)),
    ),
  );
}

Widget visitHistory(
  BuildContext context,
  ScheduleCompleteVisitPageModel _model,
  Function safeSetState,
) {
  return Container(
    width: double.infinity,
    height: 900.0,
    decoration: BoxDecoration(
      color: FlutterFlowTheme.of(context).primaryBackground,
    ),
    child: SingleChildScrollView(
      child: FutureBuilder<ApiCallResponse>(
        future: _model.visitHistory(
          requestFn: () => PhpGroup.getVisitsCall.call(
            devUUID: FFAppState().devUUID,
            userUUID: FFAppState().userUUID,
            cliID: FFAppState().cliUUID,
            atividade: 'getVisitas',
          ),
        ),
        builder: (context, snapshot) {
          // Customize what your widget looks like when it's loading.
          if (!snapshot.hasData) {
            return Center(
              child: SizedBox(
                width: 50.0,
                height: 50.0,
                child: SpinKitCircle(
                  color: FlutterFlowTheme.of(context).primary,
                  size: 50.0,
                ),
              ),
            );
          }
          final wrapGetVisitsResponse = snapshot.data!;
          return Builder(
            builder: (context) {
              final visitaWrap = PhpGroup.getVisitsCall
                      .visitasList(
                        wrapGetVisitsResponse.jsonBody,
                      )
                      ?.toList() ??
                  [];
              return ListView.builder(
                  itemCount: visitaWrap.length,
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                  physics: const BouncingScrollPhysics(),
                  addAutomaticKeepAlives: true,
                  cacheExtent: 1000.0,
                  addRepaintBoundaries: true,
                  addSemanticIndexes: true,
                  itemBuilder: (context, index) {
                    final visitaWrapItem = visitaWrap[index];
                    // visitaWrap.length, (visitaWrapIndex) {

                    return CardItemTemplateComponentWidget(
                        imageHashMap: Map<String, String>.from({
                          'key': visitaWrapItem['VTE_DOCUMENTO'] ?? '',
                          'value': 'E',
                        }),
                        labelsHashMap: Map<String, String>.from({
                          'Nome:': visitaWrapItem['VTE_NOME'] ?? '',
                          'Inicio:': visitaWrapItem['VAW_DTINICIO'] ?? '',
                          'Fim:': visitaWrapItem['VAW_DTFIM'] ?? '',
                        }),
                        statusHashMap: [
                          visitaWrapItem['VAW_STATUS'] == 'A'
                              ? Map<String, Color>.from({
                                  FFLocalizations.of(context).getVariableText(
                                    ptText: 'Ativo',
                                    enText: 'Active',
                                  ): FlutterFlowTheme.of(context).success,
                                })
                              : visitaWrapItem['VAW_STATUS'] == 'F' ||
                                      visitaWrapItem['VAW_STATUS'] == 'B' ||
                                      visitaWrapItem['VAW_STATUS'] == 'C' ||
                                      visitaWrapItem['VAW_STATUS'] == 'I'
                                  ? Map<String, Color>.from({
                                      FFLocalizations.of(context)
                                          .getVariableText(
                                        ptText: 'Pendente',
                                        enText: 'Pending',
                                      ): FlutterFlowTheme.of(context).warning,
                                    })
                                  : Map<String, Color>.from({
                                      FFLocalizations.of(context)
                                          .getVariableText(
                                        ptText: 'Cancelado',
                                        enText: 'Canceled',
                                      ): FlutterFlowTheme.of(context).error,
                                    }),
                        ],
                        onTapCardItemAction: () async {
                          showModalBottomSheet(
                            isScrollControlled: true,
                            isDismissible: true,
                            backgroundColor: Colors.transparent,
                            useSafeArea: true,
                            context: context,
                            builder: (context) {
                              return VisitRequestTemplateComponentWidget(
                                vteName: 'Lorem Ipsus',
                                vteReason: 'Lorem Ipsus',
                                vawDate: 'Lorem Ipsus',
                                vawStatus: 'Lorem Ipsus',
                                vteMsg: 'Lorem Ipsus',
                                vteUUID: 'Lorem Ipsus',
                                cliUUID: FFAppState().cliUUID,
                                msgUUID: 'Lorem Ipsus',
                                vawDestino: 'Lorem Ipsus',
                                vawUUID: 'Lorem Ipsus',
                                vawName: 'Lorem Ipsus',
                                vawRef: 'Lorem Ipsus',
                                labelsHashMap: Map<String, String>.from({
                                  'Nome:': visitaWrapItem['VTE_NOME'] ?? '',
                                  'Inicio:':
                                      visitaWrapItem['VAW_DTINICIO'] ?? '',
                                  'Fim:': visitaWrapItem['VAW_DTFIM'] ?? '',
                                }),
                                imageHashMap: Map<String, String>.from({
                                  'key': visitaWrapItem['VTE_DOCUMENTO'] ?? '',
                                  'value': 'E',
                                }),
                                statusHashMap: [
                                  visitaWrapItem['VAW_STATUS'] == 'A'
                                      ? Map<String, Color>.from({
                                          FFLocalizations.of(context)
                                              .getVariableText(
                                            ptText: 'Ativo',
                                            enText: 'Active',
                                          ): FlutterFlowTheme.of(context)
                                              .success,
                                        })
                                      : visitaWrapItem['VAW_STATUS'] == 'F' ||
                                              visitaWrapItem['VAW_STATUS'] ==
                                                  'B' ||
                                              visitaWrapItem['VAW_STATUS'] ==
                                                  'C' ||
                                              visitaWrapItem['VAW_STATUS'] ==
                                                  'I'
                                          ? Map<String, Color>.from({
                                              FFLocalizations.of(context)
                                                  .getVariableText(
                                                ptText: 'Pendente',
                                                enText: 'Pending',
                                              ): FlutterFlowTheme.of(context)
                                                  .warning,
                                            })
                                          : Map<String, Color>.from({
                                              FFLocalizations.of(context)
                                                  .getVariableText(
                                                ptText: 'Cancelado',
                                                enText: 'Canceled',
                                              ): FlutterFlowTheme.of(context)
                                                  .error,
                                            }),
                                ],
                                changeStatusAction: changeStatusAction,
                                // vteDocument: liberationHistoryItem['VTE_DOCUMENTO'],
                              );
                            },
                          ).then((_) {
                            // PushNotificationManager _pushNotificationService =
                            //     PushNotificationManager();

                            // _pushNotificationService.onMessageReceived
                            //     .listen((received) {
                            //   if (received.data['click_action'] ==
                            //       'cancel_request') {
                            //     log('Aprovado');
                            //     _pushNotificationService.dispose();
                            //     snackbar(context, opt: true);
                            //     context.pushReplacementNamed(
                            //       'liberationHistory',
                            //       extra: <String, dynamic>{
                            //         kTransitionInfoKey: const TransitionInfo(
                            //           hasTransition: true,
                            //           transitionType: PageTransitionType.scale,
                            //           alignment: Alignment.bottomCenter,
                            //         ),
                            //       },
                            //     );
                            //   }
                            // });
                          });

                          // await showModalBottomSheet(
                          //   isScrollControlled: true,
                          //   backgroundColor: Colors.transparent,
                          //   enableDrag: true,
                          //   isDismissible: true,
                          //   useSafeArea: true,
                          //   context: context,
                          //   builder: (context) {
                          //     return GestureDetector(
                          //       onTap: () => _model.unfocusNode.canRequestFocus
                          //           ? FocusScope.of(context)
                          //               .requestFocus(_model.unfocusNode)
                          //           : FocusScope.of(context).unfocus(),
                          //       child: VisitDetailsModalTemplateComponentWidget(
                          //         visitStatusStr: visitaWrapItem['VAW_STATUS'],
                          //         visitStartDateStr:
                          //             visitaWrapItem['VAW_DTINICIO'],
                          //         visitEndDateStr: visitaWrapItem['VAW_DTFIM'],
                          //         visitReasonStr:
                          //             visitaWrapItem['MOT_DESCRICAO'],
                          //         visitLevelStr:
                          //             visitaWrapItem['NAC_DESCRICAO'],
                          //         visitTempStr:
                          //             visitaWrapItem['VTE_UNICA'].toString(),
                          //         visitObsStr: visitaWrapItem['VAW_OBS'],
                          //         visitorImgPath: valueOrDefault<String>(
                          //           "https://freaccess.com.br/freaccess/getImage.php?devUUID=${FFAppState().devUUID}&userUUID=${FFAppState().userUUID}&cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=${getJsonField(
                          //             visitaWrapItem,
                          //             r'''$.VTE_DOCUMENTO''',
                          //           ).toString()}&tipo=E",
                          //           'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg',
                          //         ),
                          //         visitorStrList:
                          //             visitaWrapItem['VTE_DOCUMENTO'],
                          //         visitIdStr: visitaWrapItem['VAW_ID'],
                          //         visitStatusColor:
                          //             visitaWrapItem['VAW_STATUS'] == 'A'
                          //                 ? FlutterFlowTheme.of(context).success
                          //                 : FlutterFlowTheme.of(context).error,
                          //         visitorJsonList:
                          //             PhpGroup.getVisitsCall.visitasList(
                          //           wrapGetVisitsResponse.jsonBody,
                          //         ),
                          //         updateToggleIdx: () async {},
                          //         repeatVisitSchedule: () async {},
                          //       ),
                          //     );
                          //   },
                          // ).then((value) => safeSetState(() {}));
                        });
                  });
            },
          );
        },
      ),
    ),
  );
}
