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

import 'package:Chat/tools/HomePage.dart';
import 'package:Chat/tools/upload/upload_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'common/Global.dart';

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

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

  @override
  State<ChatApp> createState() => _ChatAppState();
}

class _ChatAppState extends State<ChatApp> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AI聊天',
      home: const Homepage(),
      //注册路由
      routes: <String, WidgetBuilder>{
        '/HomePage': (BuildContext context) => const Homepage(),
        '/UploadPage': (BuildContext context) => const UploadPage(),
      },
      debugShowMaterialGrid: false,
      //显示网格
      debugShowCheckedModeBanner: false,
      //去掉右上角的debug
      builder: EasyLoading.init(),
    );
  }
}
