camera_engine.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'package:flutter/material.dart';
  2. import 'package:wechat_camera_picker/wechat_camera_picker.dart';
  3. import 'package:flutter/services.dart';
  4. /*
  5. * 照相机的引擎封装,目前用的 CameraPicker 插件
  6. */
  7. class CameraEngine {
  8. /// 拍照
  9. static Future<AssetEntity?> takePhoto(BuildContext context) async {
  10. return await CameraPicker.pickFromCamera(
  11. context,
  12. pickerConfig: CameraPickerConfig(
  13. enableRecording: false,
  14. theme: ThemeData(
  15. brightness: Brightness.dark,
  16. appBarTheme: AppBarTheme(
  17. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  18. statusBarColor: Colors.transparent,
  19. statusBarBrightness: Brightness.dark,
  20. statusBarIconBrightness: Brightness.light,
  21. ),
  22. ),
  23. ),
  24. ),
  25. );
  26. }
  27. /// 录制视频
  28. static Future<AssetEntity?> takeVideo(
  29. BuildContext context, {
  30. int maxRecordInSeconds = 30,
  31. }) async {
  32. return await CameraPicker.pickFromCamera(
  33. context,
  34. pickerConfig: CameraPickerConfig(
  35. enableRecording: true,
  36. onlyEnableRecording: true,
  37. enableTapRecording: false,
  38. enableAudio: true,
  39. shouldAutoPreviewVideo: true,
  40. maximumRecordingDuration: Duration(seconds: maxRecordInSeconds),
  41. theme: ThemeData(
  42. brightness: Brightness.dark,
  43. appBarTheme: AppBarTheme(
  44. systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
  45. statusBarColor: Colors.transparent,
  46. statusBarBrightness: Brightness.dark,
  47. statusBarIconBrightness: Brightness.light,
  48. ),
  49. ),
  50. ),
  51. ),
  52. );
  53. }
  54. }