camera_engine.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:wechat_camera_picker/wechat_camera_picker.dart';
  4. import 'package:flutter/services.dart';
  5. /*
  6. * 照相机的引擎封装,目前用的 CameraPicker 插件
  7. */
  8. class CameraEngine {
  9. /// 拍照
  10. static Future<AssetEntity?> takePhoto(BuildContext context) async {
  11. return await CameraPicker.pickFromCamera(
  12. context,
  13. locale: Localizations.localeOf(context),
  14. pickerConfig: CameraPickerConfig(
  15. enableRecording: false,
  16. lockCaptureOrientation: DeviceOrientation.portraitUp,
  17. cameraQuarterTurns: 0,
  18. theme: ThemeData(
  19. brightness: Brightness.dark,
  20. colorScheme: const ColorScheme.dark(
  21. secondary: AppColorsTheme.colorPrimary, //内部按钮是这个颜色
  22. ),
  23. appBarTheme: AppBarTheme(
  24. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  25. statusBarColor: Colors.transparent,
  26. statusBarBrightness: Brightness.dark,
  27. statusBarIconBrightness: Brightness.light,
  28. ),
  29. ),
  30. ),
  31. ),
  32. );
  33. }
  34. /// 录制视频
  35. static Future<AssetEntity?> takeVideo(
  36. BuildContext context, {
  37. int maxRecordInSeconds = 30,
  38. }) async {
  39. return await CameraPicker.pickFromCamera(
  40. context,
  41. locale: Localizations.localeOf(context),
  42. pickerConfig: CameraPickerConfig(
  43. enableRecording: true,
  44. lockCaptureOrientation: DeviceOrientation.portraitUp,
  45. cameraQuarterTurns: 0,
  46. onlyEnableRecording: true,
  47. enableTapRecording: false,
  48. enableAudio: true,
  49. shouldAutoPreviewVideo: true,
  50. maximumRecordingDuration: Duration(seconds: maxRecordInSeconds),
  51. theme: ThemeData(
  52. brightness: Brightness.dark,
  53. colorScheme: const ColorScheme.dark(
  54. secondary: AppColorsTheme.colorPrimary,
  55. ),
  56. appBarTheme: AppBarTheme(
  57. systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(
  58. statusBarColor: Colors.transparent,
  59. statusBarBrightness: Brightness.dark,
  60. statusBarIconBrightness: Brightness.light,
  61. ),
  62. ),
  63. ),
  64. ),
  65. );
  66. }
  67. }