picker_method.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Copyright 2019 The FlutterCandies author. All rights reserved.
  2. // Use of this source code is governed by an Apache license that can be found
  3. // in the LICENSE file.
  4. import 'package:flutter/material.dart';
  5. import 'package:wechat_camera_picker/wechat_camera_picker.dart';
  6. import '../extensions/l10n_extensions.dart';
  7. /// Provide common usages of the picker.
  8. /// 提供常见的选择器调用方式。
  9. List<PickMethod> pickMethods(BuildContext context) {
  10. return <PickMethod>[
  11. PickMethod(
  12. icon: '📷',
  13. name: context.l10n.pickMethodPhotosName,
  14. description: context.l10n.pickMethodPhotosDescription,
  15. method: (BuildContext context) => CameraPicker.pickFromCamera(context),
  16. ),
  17. PickMethod(
  18. icon: '📹',
  19. name: context.l10n.pickMethodPhotosAndVideosName,
  20. description: context.l10n.pickMethodPhotosAndVideosDescription,
  21. method: (BuildContext context) => CameraPicker.pickFromCamera(
  22. context,
  23. pickerConfig: const CameraPickerConfig(enableRecording: true),
  24. ),
  25. ),
  26. PickMethod(
  27. icon: '🎥',
  28. name: context.l10n.pickMethodVideosName,
  29. description: context.l10n.pickMethodVideosDescription,
  30. method: (BuildContext context) => CameraPicker.pickFromCamera(
  31. context,
  32. pickerConfig: const CameraPickerConfig(
  33. enableRecording: true,
  34. onlyEnableRecording: true,
  35. ),
  36. ),
  37. ),
  38. PickMethod(
  39. icon: '📽',
  40. name: context.l10n.pickMethodVideosByTapName,
  41. description: context.l10n.pickMethodVideosByTapDescription,
  42. method: (BuildContext context) => CameraPicker.pickFromCamera(
  43. context,
  44. pickerConfig: const CameraPickerConfig(
  45. enableRecording: true,
  46. onlyEnableRecording: true,
  47. enableTapRecording: true,
  48. ),
  49. ),
  50. ),
  51. PickMethod(
  52. icon: '🈲',
  53. name: context.l10n.pickMethodSilenceRecordingName,
  54. description: context.l10n.pickMethodSilenceRecordingDescription,
  55. method: (BuildContext context) => CameraPicker.pickFromCamera(
  56. context,
  57. pickerConfig: const CameraPickerConfig(
  58. enableRecording: true,
  59. onlyEnableRecording: true,
  60. enableTapRecording: true,
  61. enableAudio: false,
  62. ),
  63. ),
  64. ),
  65. PickMethod(
  66. icon: '⏳',
  67. name: context.l10n.pickMethodNoDurationLimitName,
  68. description: context.l10n.pickMethodNoDurationLimitDescription,
  69. method: (BuildContext context) => CameraPicker.pickFromCamera(
  70. context,
  71. pickerConfig: const CameraPickerConfig(
  72. enableRecording: true,
  73. onlyEnableRecording: true,
  74. enableTapRecording: true,
  75. maximumRecordingDuration: null,
  76. ),
  77. ),
  78. ),
  79. PickMethod(
  80. icon: '🎨',
  81. name: context.l10n.pickMethodCustomizableThemeName,
  82. description: context.l10n.pickMethodCustomizableThemeDescription,
  83. method: (BuildContext context) => CameraPicker.pickFromCamera(
  84. context,
  85. pickerConfig: CameraPickerConfig(
  86. theme: CameraPicker.themeData(Colors.blue),
  87. ),
  88. ),
  89. ),
  90. PickMethod(
  91. icon: '↩️',
  92. name: context.l10n.pickMethodRotateInTurnsName,
  93. description: context.l10n.pickMethodRotateInTurnsDescription,
  94. method: (BuildContext context) => CameraPicker.pickFromCamera(
  95. context,
  96. pickerConfig: const CameraPickerConfig(cameraQuarterTurns: 1),
  97. ),
  98. ),
  99. PickMethod(
  100. icon: '🔍',
  101. name: context.l10n.pickMethodScalingPreviewName,
  102. description: context.l10n.pickMethodScalingPreviewDescription,
  103. method: (BuildContext context) => CameraPicker.pickFromCamera(
  104. context,
  105. pickerConfig: const CameraPickerConfig(enableScaledPreview: true),
  106. ),
  107. ),
  108. PickMethod(
  109. icon: '🌀',
  110. name: context.l10n.pickMethodLowerResolutionName,
  111. description: context.l10n.pickMethodLowerResolutionDescription,
  112. method: (BuildContext context) => CameraPicker.pickFromCamera(
  113. context,
  114. pickerConfig: const CameraPickerConfig(
  115. resolutionPreset: ResolutionPreset.low,
  116. ),
  117. ),
  118. ),
  119. PickMethod(
  120. icon: '🤳',
  121. name: context.l10n.pickMethodPreferFrontCameraName,
  122. description: context.l10n.pickMethodPreferFrontCameraDescription,
  123. method: (BuildContext context) => CameraPicker.pickFromCamera(
  124. context,
  125. pickerConfig: const CameraPickerConfig(
  126. preferredLensDirection: CameraLensDirection.front,
  127. ),
  128. ),
  129. ),
  130. PickMethod(
  131. icon: '📸',
  132. name: context.l10n.pickMethodPreferFlashlightOnName,
  133. description: context.l10n.pickMethodPreferFlashlightOnDescription,
  134. method: (BuildContext context) => CameraPicker.pickFromCamera(
  135. context,
  136. pickerConfig: const CameraPickerConfig(
  137. preferredFlashMode: FlashMode.always,
  138. ),
  139. ),
  140. ),
  141. PickMethod(
  142. icon: '🪄',
  143. name: context.l10n.pickMethodForegroundBuilderName,
  144. description: context.l10n.pickMethodForegroundBuilderDescription,
  145. method: (BuildContext context) => CameraPicker.pickFromCamera(
  146. context,
  147. pickerConfig: CameraPickerConfig(
  148. foregroundBuilder: (
  149. BuildContext context,
  150. CameraController? controller,
  151. ) {
  152. return Center(
  153. child: Text(
  154. controller == null
  155. ? 'Waiting for initialize...'
  156. : '${controller.description.lensDirection}',
  157. style: const TextStyle(color: Colors.white),
  158. ),
  159. );
  160. },
  161. ),
  162. ),
  163. ),
  164. ];
  165. }
  166. /// Define a regular pick method.
  167. final class PickMethod {
  168. const PickMethod({
  169. required this.icon,
  170. required this.name,
  171. required this.description,
  172. required this.method,
  173. this.onLongPress,
  174. });
  175. final String icon;
  176. final String name;
  177. final String description;
  178. /// The core function that defines how to use the picker.
  179. final Future<AssetEntity?> Function(BuildContext context) method;
  180. final GestureLongPressCallback? onLongPress;
  181. }