showCreatePollingViewDialog function

void showCreatePollingViewDialog(
  1. BuildContext context,
  2. EnxController obj
)

Implementation

void showCreatePollingViewDialog(BuildContext context, EnxController obj) {
  int safeAreaHeight = (Get.window.viewPadding.bottom.toInt() == 0)
      ? 20
      : Get.window.viewPadding.bottom.toInt();
  double appBarHeight =  0.0;
  final _formKey = GlobalKey<FormState>();
  final ScrollController _scrollController = ScrollController();
  double keyboardPadding = MediaQuery.of(context).viewInsets.bottom;
  final FocusNode _focusNode = FocusNode();

  showGeneralDialog(
    context: context,
    barrierColor: Colors.white, // Background color
    barrierDismissible: false,
    pageBuilder: (context, __, ___) {
      double keyboardPadding = MediaQuery.of(context).viewInsets.bottom;

      // Scroll to end when the keyboard is opened
      void _scrollToEnd() {
        Future.delayed(Duration(milliseconds: 100), () {
          if (_scrollController.hasClients) {
            _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
          }
        });
      }

      // Listen to keyboard visibility changes
      _focusNode.addListener(() {
        if (_focusNode.hasFocus) {
          _scrollToEnd();
        }
      });
      return Center(
        child: Material(
          type: MaterialType.transparency, // Make the dialog background transparent
          child: SizedBox(
            width: MediaQuery.of(context).size.width -
                MediaQuery.of(context).padding.left +
                MediaQuery.of(context).padding.right,
            height: Platform.isIOS
                ? MediaQuery.of(context).size.height - safeAreaHeight
                : Get.height - appBarHeight - Get.window.viewPadding.top / 2.5 - Get.window.viewPadding.bottom,
            child:
                 Padding(
                  padding:  EdgeInsets.only(left: 15.0,right: 16.0,top: 16.0,bottom: keyboardPadding),
                  child: SingleChildScrollView(
                      controller: _scrollController,
                      child: _buildPortraitLayout(obj,context,_formKey)))



          ),
        ),
      );
    },
  );
}