import 'package:fis_ui/widgets/webview/webview.dart';
import 'package:flutter/material.dart';
import 'package:fis_ui/index.dart';
import 'package:flyinsono/managers/interfaces/webview_controller.dart';
import 'package:get/get.dart';
import 'package:fis_common/logger/logger.dart';

class VBoxSettingPage extends StatefulWidget implements FWidget {
  final String url;
  VBoxSettingPage({required this.url});
  @override
  _VBoxSettingPage createState() => _VBoxSettingPage();
}

class _VBoxSettingPage extends State<VBoxSettingPage> {
  final webviewControllerManager = Get.find<IWebviewControllerManager>();

  @override
  FWidget build(BuildContext context) {
    if (webviewControllerManager.isDialogExist) {
      logger.w("diaglos exist while create webview for sonopost setting page");
    }
    return FLayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        return FWebViewX(
          height: constraints.maxHeight,
          width: constraints.maxWidth,
          initialContent: widget.url,

          //Sonopost setting is more important than general dialog
          ignoreAllGestures: false,
          //kIsMobile ? false : webviewControllerManager.isDialogExist,
          onWebViewCreated: (controller) {
            webviewControllerManager.initWebviewController(controller);
          },
        );
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
    Get.find<IWebviewControllerManager>().disposeWebviewController();
  }
}
