import 'dart:async';

import 'package:flutter/material.dart';
import 'package:fis_common/logger/logger.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import 'global.dart';
import 'routes/routes.dart';

void main() async {
  runZonedGuarded(
    () async {
      try {
        WidgetsFlutterBinding.ensureInitialized();
        await Global.init();
      } catch (e) {
        logger.e('Global init Error', e);
      }
      runApp(const _App());
    },
    (error, stack) {
      // GlobalErrorHandler.handle(error, stack);
    },
  );
}

class _App extends StatelessWidget {
  const _App();

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: "家医一体机",
      theme: ThemeData(
        // primaryColor: const Color.fromRGBO(0, 178, 237, 1),
        primaryColor: Colors.blue,
        // colorScheme: ColorScheme.fromSeed(
        //   // seedColor: const Color.fromRGBO(44, 119, 229, 1),
        //   // seedColor: Colors.lightBlue,
        //   seedColor: const Color.fromRGBO(0, 178, 237, 1),
        // ),
        // colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      debugShowCheckedModeBanner: false,
      getPages: Routes.routes,
      initialRoute: "splash",
      // initialRoute: "/patient/create",
      // initialRoute: "/",
      builder: EasyLoading.init(
        builder: (context, widget) {
          const designWidth = 1280.0; // 设计尺寸宽度：1280
          final size = MediaQuery.of(context).size;
          final scale = size.width / designWidth; // 计算缩放比例
          return FittedBox(
            fit: BoxFit.fitWidth,
            child: SizedBox(
              width: designWidth,
              height: size.height / scale,
              child: Center(child: widget ?? const SizedBox()),
            ),
          );
          // return widget ?? const SizedBox();
        },
      ),
    );
  }
}
