main.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import 'dart:io';
  2. import 'package:ctjt_flutter/common/states.dart';
  3. import 'package:ctjt_flutter/common/styles.dart';
  4. import 'package:ctjt_flutter/common/trtc/calling/ui/TRTCCallingContact.dart';
  5. import 'package:ctjt_flutter/common/trtc/calling/ui/VideoCall/TRTCCallingVideo.dart';
  6. import 'package:ctjt_flutter/common/trtc/calling/ui/base/CallingScenes.dart';
  7. import 'package:ctjt_flutter/common/utils.dart';
  8. import 'package:ctjt_flutter/pages/about.dart';
  9. import 'package:ctjt_flutter/pages/home.dart';
  10. import 'package:ctjt_flutter/pages/remote_call.dart';
  11. import 'package:device_info/device_info.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:flutter/services.dart';
  14. import 'package:flutter_screenutil/flutter_screenutil.dart';
  15. import 'package:permission_handler/permission_handler.dart';
  16. import 'package:provider/provider.dart';
  17. // 注意,加入Bugly构建的时候需要使用命令指定目标架构,然后apk命令手工安装生成的包
  18. // 命令如:flutter build apk --release --target-platform android-arm64
  19. // void main() => FlutterBugly.postCatchedException(() async {
  20. // runApp(MyApp());
  21. // initScreen();
  22. //
  23. // FlutterBugly.init(androidAppId: "xxxx", iOSAppId: "xxxx");
  24. // });
  25. void main() {
  26. FlutterError.onError = (FlutterErrorDetails details) {
  27. FlutterError.dumpErrorToConsole(details);
  28. };
  29. WidgetsFlutterBinding.ensureInitialized();
  30. _initScreen().then((_) {
  31. runApp(MyApp());
  32. });
  33. }
  34. Future<void> _initScreen() async {
  35. // 强制竖屏
  36. await SystemChrome.setPreferredOrientations(
  37. [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  38. var deviceInfo = DeviceInfoPlugin();
  39. // 如果是安卓,设置状态栏背景色透明
  40. if (Platform.isAndroid) {
  41. SystemChrome.setSystemUIOverlayStyle(Styles.statusBarStyle);
  42. var androidInfo = await deviceInfo.androidInfo;
  43. print('Running on ${androidInfo.model}');
  44. } else if (Platform.isIOS) {
  45. var iosInfo = await deviceInfo.iosInfo;
  46. print('Running on ${iosInfo.utsname.machine}');
  47. }
  48. }
  49. class MyApp extends StatelessWidget {
  50. @override
  51. Widget build(BuildContext context) {
  52. _requestPermissions(context); // 动态申请权限
  53. return ScreenUtilInit( // 屏幕自适应
  54. designSize: Size(1125, 2436), // 填入设计稿中设备的屏幕尺寸,单位dp
  55. builder: () => MultiProvider( // 启动应用时需要初始化状态通知
  56. providers: [
  57. ChangeNotifierProvider(create: (_) => UserStatus()),
  58. ChangeNotifierProvider(create: (_) => AppVersion()),
  59. ChangeNotifierProvider(create: (_) => AppDownloadProcess()),
  60. ],
  61. child: MaterialApp(
  62. title: 'Flutter项目原型',
  63. debugShowCheckedModeBanner: false,
  64. theme: ThemeData(
  65. primaryColor: Styles.primaryColor,
  66. //primarySwatch: Colors.blue,
  67. visualDensity: VisualDensity.adaptivePlatformDensity,
  68. ),
  69. builder: (context, widget) {
  70. return MediaQuery(
  71. // 设置文字大小不随系统设置改变
  72. data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
  73. child: widget!,
  74. );
  75. },
  76. // 注册路由
  77. home: HomePage(),
  78. routes: {
  79. "/index": (context) => HomePage(),
  80. "/about": (context) => AboutPage(),
  81. "/remote_call": (context) => RemoteCallPage(),
  82. "/calling/audioContact": (context) =>
  83. TRTCCallingContact(CallingScenes.AudioOneVOne),
  84. "/calling/callingView": (context) => TRTCCallingVideo(),
  85. },
  86. ),
  87. ));
  88. }
  89. }
  90. // 动态申请权限
  91. Future<Null> _requestPermissions(BuildContext context) async {
  92. await Utils.checkPermission(Permission.storage, init: true);
  93. await Utils.checkPermission(Permission.microphone, init: true);
  94. // await Utils.checkPermission(Permission.camera, init: true);
  95. // await Utils.checkPermission(Permission.bluetooth, init: true);
  96. }