import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:odf/tools/home/home_page.dart';
import 'package:odf/tools/login/login_page.dart';
import 'package:odf/tools/search/search_page.dart';
import 'package:odf/tools/set/change_password_page.dart';
import 'package:odf/tools/set/set_page.dart';
import 'package:odf/tools/start_page.dart';

import 'common/Global.dart';

void main() async {
  await runZonedGuarded(() async {
    WidgetsFlutterBinding.ensureInitialized();
    Global.initialize().then((e) {
      Global();
      runApp(const MyApp());
      if (Platform.isAndroid) {
        // 以下两行 设置android状态栏为透明的沉浸。写在组件渲染之后，是为了在渲染后进行set赋值，覆盖状态栏，写在渲染之前MaterialApp组件会覆盖掉这个值。
        SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
        SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      }
    });
  }, (error, stackTrace) {
    print("error==$error");
  });
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    //白色
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '光缆资源管理',
      home: const StartPage(),
      //注册路由
      routes: <String, WidgetBuilder>{
        '/LoginPage': (BuildContext context) => const LoginPage(),
        '/HomePage': (BuildContext context) => const HomePage(),
        '/SearchPage': (BuildContext context) => const SearchPage(),
        '/SetPage': (BuildContext context) => const SetPage(),
        '/ChangePasswordPage': (BuildContext context) => const ChangePasswordPage(),
      },
      //显示网格
      debugShowMaterialGrid: false,
      //去掉右上角的debug
      debugShowCheckedModeBanner: false,
      //加载初始化
      builder: EasyLoading.init(),
    );
  }
}
