import 'dart:io';

import 'package:flutter/material.dart';
import 'package:fun_selfie_app/utils/routes.dart';
import 'package:fun_selfie_app/utils/storage.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter/services.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  String initPage = '';
  Future<dynamic> future = Future(() async {
    return await StorageUtil.getString('userMsg');
  });
  await future.then((value) {
    if (value == '') {
      initPage = '/login';
    } else {
      initPage = '/';
    }
  });
  runApp(MyApp(initPage: initPage));
  if (Platform.isAndroid) {
    //设置Android头部的导航栏透明
    SystemUiOverlayStyle systemUiOverlayStyle =
        const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  MyApp({super.key, required this.initPage}) {
    RouterFluro.initRoues();
  }
  final String initPage;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: '趣味自拍',
        initialRoute: initPage,
        onGenerateRoute: RouterFluro.fluroRouter.generator,

        //添加国际化
        localizationsDelegates: const [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('zh', 'CH'),
          Locale('en', 'US'),
        ],
        locale: const Locale('zh'),
        theme: ThemeData(
            primarySwatch: Colors.blue,
            textTheme: const TextTheme(
                titleMedium: TextStyle(fontSize: 20),
                titleSmall: TextStyle(fontSize: 14)),
            iconTheme: const IconThemeData(size: 40),
            appBarTheme: const AppBarTheme(
                toolbarTextStyle: TextStyle(fontSize: 18),
                titleTextStyle: TextStyle(fontSize: 26))));
  }
}
