import 'dart:io'; import 'package:ctjt_flutter/common/states.dart'; import 'package:ctjt_flutter/common/styles.dart'; import 'package:ctjt_flutter/common/trtc/calling/ui/TRTCCallingContact.dart'; import 'package:ctjt_flutter/common/trtc/calling/ui/VideoCall/TRTCCallingVideo.dart'; import 'package:ctjt_flutter/common/trtc/calling/ui/base/CallingScenes.dart'; import 'package:ctjt_flutter/common/utils.dart'; import 'package:ctjt_flutter/pages/about.dart'; import 'package:ctjt_flutter/pages/home.dart'; import 'package:ctjt_flutter/pages/remote_call.dart'; import 'package:device_info/device_info.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; // 注意,加入Bugly构建的时候需要使用命令指定目标架构,然后apk命令手工安装生成的包 // 命令如:flutter build apk --release --target-platform android-arm64 // void main() => FlutterBugly.postCatchedException(() async { // runApp(MyApp()); // initScreen(); // // FlutterBugly.init(androidAppId: "xxxx", iOSAppId: "xxxx"); // }); void main() { FlutterError.onError = (FlutterErrorDetails details) { FlutterError.dumpErrorToConsole(details); }; WidgetsFlutterBinding.ensureInitialized(); _initScreen().then((_) { runApp(MyApp()); }); } Future _initScreen() async { // 强制竖屏 await SystemChrome.setPreferredOrientations( [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); var deviceInfo = DeviceInfoPlugin(); // 如果是安卓,设置状态栏背景色透明 if (Platform.isAndroid) { SystemChrome.setSystemUIOverlayStyle(Styles.statusBarStyle); var androidInfo = await deviceInfo.androidInfo; print('Running on ${androidInfo.model}'); } else if (Platform.isIOS) { var iosInfo = await deviceInfo.iosInfo; print('Running on ${iosInfo.utsname.machine}'); } } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { _requestPermissions(context); // 动态申请权限 return ScreenUtilInit( // 屏幕自适应 designSize: Size(1125, 2436), // 填入设计稿中设备的屏幕尺寸,单位dp builder: () => MultiProvider( // 启动应用时需要初始化状态通知 providers: [ ChangeNotifierProvider(create: (_) => UserStatus()), ChangeNotifierProvider(create: (_) => AppVersion()), ChangeNotifierProvider(create: (_) => AppDownloadProcess()), ], child: MaterialApp( title: 'Flutter项目原型', debugShowCheckedModeBanner: false, theme: ThemeData( primaryColor: Styles.primaryColor, //primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), builder: (context, widget) { return MediaQuery( // 设置文字大小不随系统设置改变 data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), child: widget!, ); }, // 注册路由 home: HomePage(), routes: { "/index": (context) => HomePage(), "/about": (context) => AboutPage(), "/remote_call": (context) => RemoteCallPage(), "/calling/audioContact": (context) => TRTCCallingContact(CallingScenes.AudioOneVOne), "/calling/callingView": (context) => TRTCCallingVideo(), }, ), )); } } // 动态申请权限 Future _requestPermissions(BuildContext context) async { await Utils.checkPermission(Permission.storage, init: true); await Utils.checkPermission(Permission.microphone, init: true); // await Utils.checkPermission(Permission.camera, init: true); // await Utils.checkPermission(Permission.bluetooth, init: true); }