import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:news_getx/data/services/config.dart';
import 'package:news_getx/data/services/storage.dart';
import 'package:news_getx/data/services/user.dart';
import 'package:news_getx/utils/loading.dart';

/// 全局静态数据
class Global {
  /// 初始化
  static Future init() async {
    WidgetsFlutterBinding.ensureInitialized();
    await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

    // 调整系统UI
    setSystemUi();
    
    // 初始换easyLoading
    Loading();

    await Get.putAsync<StorageService>(() => StorageService().init());

    Get.put<ConfigService>(ConfigService());
    Get.put<UserService>(UserService());
  }

  static void setSystemUi() {
    if (GetPlatform.isAndroid) {
      // android 状态栏为透明的沉浸
      SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarDividerColor: Colors.transparent,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}