camera_engine.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. pickerConfig: CameraPickerConfig(
  14. enableRecording: false,
  15. theme: ThemeData(
  16. brightness: Brightness.dark,
  17. colorScheme: const ColorScheme.dark(
  18. secondary: AppColorsTheme.colorPrimary, //内部按钮是这个颜色
  19. ),
  20. appBarTheme: AppBarTheme(
  21. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  22. statusBarColor: Colors.transparent,
  23. statusBarBrightness: Brightness.dark,
  24. statusBarIconBrightness: Brightness.light,
  25. ),
  26. ),
  27. ),
  28. ),
  29. );
  30. }
  31. /// 录制视频
  32. static Future<AssetEntity?> takeVideo(
  33. BuildContext context, {
  34. int maxRecordInSeconds = 30,
  35. }) async {
  36. return await CameraPicker.pickFromCamera(
  37. context,
  38. pickerConfig: CameraPickerConfig(
  39. enableRecording: true,
  40. onlyEnableRecording: true,
  41. enableTapRecording: false,
  42. enableAudio: true,
  43. shouldAutoPreviewVideo: true,
  44. maximumRecordingDuration: Duration(seconds: maxRecordInSeconds),
  45. theme: ThemeData(
  46. brightness: Brightness.dark,
  47. colorScheme: const ColorScheme.dark(
  48. secondary: AppColorsTheme.colorPrimary,
  49. ),
  50. appBarTheme: AppBarTheme(
  51. systemOverlayStyle: SystemUiOverlayStyle.light.copyWith(
  52. statusBarColor: Colors.transparent,
  53. statusBarBrightness: Brightness.dark,
  54. statusBarIconBrightness: Brightness.light,
  55. ),
  56. ),
  57. ),
  58. ),
  59. );
  60. }
  61. }