import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
import 'package:vbvs_app/controller/device/device_type_controller.dart';
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';

class SleepReportPage extends StatefulWidget {
  var sleepUri;
  SleepReportPage({super.key, required this.sleepUri});

  @override
  State<SleepReportPage> createState() => _SleepReportPageState();
}

class _SleepReportPageState extends State<SleepReportPage> {
  GlobalController globalController = Get.find();
  UserInfoController userInfoController = Get.find();
  BlueteethBindController blueteethBindController = Get.find();
  ThemeController themeController = Get.find();
  DeviceTypeController deviceTypeController = Get.find();

  ValueNotifier<bool> isPageLoading = ValueNotifier<bool>(true);

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    // 清理 ValueNotifier
    isPageLoading.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, bodySize) => GestureDetector(
        onTap: () => FocusScope.of(context).unfocus(),
        child: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage('assets/img/bgNoImg.png'), // 本地图片
              fit: BoxFit.fill, // 填满整个 Container
            ),
          ),
          child: Scaffold(
            backgroundColor: Colors.transparent, // 背景透明
            appBar: AppBar(
              backgroundColor: themeController.currentColor.sc17,
              automaticallyImplyLeading: false,
              iconTheme: IconThemeData(color: themeController.currentColor.sc3),
              titleSpacing: 0,
              title: Container(
                width: double.infinity,
                height: 180.rpx,
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    /// 居中标题
                    Text(
                      '健康报告'.tr,
                      style: TextStyle(
                            fontFamily: 'Readex Pro',
                            color: themeController.currentColor.sc3,
                            letterSpacing: 0,
                            fontSize: 30.rpx,
                          ),
                    ),

                    /// 左边返回按钮
                    Positioned(
                      left: 0,
                      child: returnIconButtomNew,
                    ),
                  ],
                ),
              ),
            ),
            body: SafeArea(
              top: true,
              child: Stack(
                children: [
                  InAppWebView(
                    key: UniqueKey(),
                    initialUrlRequest: URLRequest(url: WebUri(widget.sleepUri)),
                    onLoadStart: (controller, url) {
                      // 页面开始加载时显示加载指示器
                      isPageLoading.value = true;
                    },
                    onLoadStop: (controller, url) {
                      // 页面加载完成后隐藏加载指示器
                      isPageLoading.value = false;
                    },
                  ),
                  ValueListenableBuilder<bool>(
                    valueListenable: isPageLoading,
                    builder: (context, isLoading, child) {
                      return isLoading
                          ? Center(
                              child: CircularProgressIndicator(), // 加载指示器
                            )
                          : SizedBox.shrink();
                    },
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

 
}
