Compare commits
34 Commits
5ddcb95358
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 41fcd730f0 | |||
| 7ab03dd912 | |||
| 29cfbdf8c4 | |||
| 7031765b4d | |||
| 942d15e54c | |||
| 6b168ccd62 | |||
| 551d10dec4 | |||
| e1446337e9 | |||
| 26098114d2 | |||
| 1e08b70c39 | |||
| e821bd68a7 | |||
| 9c21915bf7 | |||
| 1221b16c7f | |||
| 54738d53f9 | |||
| 4d83f38960 | |||
| 36da37c6c0 | |||
| 0183bd9a6d | |||
| 016aad49b7 | |||
| a39fcdb929 | |||
| 0a2cfe27ac | |||
| d598b36449 | |||
| c0aa2db6db | |||
| 0d06975313 | |||
| f6440ea8b7 | |||
| 1e936bfc12 | |||
| 4c5bf22638 | |||
| e387dfad0a | |||
| 846c6a8edb | |||
| f49d208042 | |||
| 124b4c1882 | |||
| 7c342c4477 | |||
| dfbdbbdb66 | |||
| 1b404525d2 | |||
| 77d9c35592 |
5
.gitignore
vendored
@@ -12,12 +12,13 @@
|
|||||||
.swiftpm/
|
.swiftpm/
|
||||||
migrate_working_dir/
|
migrate_working_dir/
|
||||||
.vscode
|
.vscode
|
||||||
|
pubspec.lock
|
||||||
# IntelliJ related
|
# IntelliJ related
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
*.iws
|
*.iws
|
||||||
.idea/
|
.idea/
|
||||||
|
.cursor
|
||||||
|
|
||||||
# The .vscode folder contains launch configuration and tasks you configure in
|
# The .vscode folder contains launch configuration and tasks you configure in
|
||||||
# VS Code which you may wish to be included in version control, so this line
|
# VS Code which you may wish to be included in version control, so this line
|
||||||
@@ -44,3 +45,5 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
/android/.kotlin
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ plugins {
|
|||||||
id("dev.flutter.flutter-gradle-plugin")
|
id("dev.flutter.flutter-gradle-plugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
val appPackageName = "com.gdfw.fxjk"
|
val appPackageName = "com.qxy.dronex"
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = appPackageName
|
namespace = appPackageName
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<!-- The INTERNET permission is required for development. Specifically,
|
|
||||||
the Flutter tool needs it to communicate with the running application
|
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
|
||||||
-->
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
|
||||||
</manifest>
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.gdfw.fxjk">
|
package="com.qxy.dronex">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
android:required="true" />
|
android:required="true" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="飞行极控"
|
android:label="飞行极控录像工作台"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
@@ -36,8 +37,8 @@
|
|||||||
android:resource="@style/NormalTheme"
|
android:resource="@style/NormalTheme"
|
||||||
/>
|
/>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
@@ -52,8 +53,8 @@
|
|||||||
</application>
|
</application>
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
<action android:name="android.intent.action.PROCESS_TEXT" />
|
||||||
<data android:mimeType="text/plain"/>
|
<data android:mimeType="text/plain" />
|
||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
package com.gdfw.fxjk
|
|
||||||
|
|
||||||
import android.content.pm.ApplicationInfo
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.camera.view.PreviewView
|
|
||||||
import com.gdfw.fxjk.recording.RecordingPlatformHandler
|
|
||||||
import com.gdfw.fxjk.recording.RecordingPreviewFactory
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
class MainActivity : FlutterActivity() {
|
|
||||||
private var platformHandler: RecordingPlatformHandler? = null
|
|
||||||
private var platformInfoChannel: MethodChannel? = null
|
|
||||||
|
|
||||||
var recordingPreviewView: PreviewView? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
|
||||||
super.configureFlutterEngine(flutterEngine)
|
|
||||||
flutterEngine
|
|
||||||
.platformViewsController
|
|
||||||
.registry
|
|
||||||
.registerViewFactory(
|
|
||||||
"recording-camera-preview",
|
|
||||||
RecordingPreviewFactory(this),
|
|
||||||
)
|
|
||||||
|
|
||||||
platformInfoChannel =
|
|
||||||
MethodChannel(
|
|
||||||
flutterEngine.dartExecutor.binaryMessenger,
|
|
||||||
AppConstants.PLATFORM_INFO_CHANNEL,
|
|
||||||
).also { channel ->
|
|
||||||
channel.setMethodCallHandler { call, result ->
|
|
||||||
when (call.method) {
|
|
||||||
"packageInfo" -> result.success(packageInfoMap())
|
|
||||||
"deviceInfo" -> result.success(deviceInfoMap())
|
|
||||||
else -> result.notImplemented()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
platformHandler =
|
|
||||||
RecordingPlatformHandler(
|
|
||||||
this,
|
|
||||||
flutterEngine.dartExecutor.binaryMessenger,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun attachRecordingPreview(previewView: PreviewView) {
|
|
||||||
recordingPreviewView = previewView
|
|
||||||
}
|
|
||||||
|
|
||||||
fun detachRecordingPreview(previewView: PreviewView? = null) {
|
|
||||||
if (previewView == null || recordingPreviewView === previewView) {
|
|
||||||
recordingPreviewView = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
platformInfoChannel?.setMethodCallHandler(null)
|
|
||||||
platformInfoChannel = null
|
|
||||||
platformHandler?.dispose()
|
|
||||||
platformHandler = null
|
|
||||||
super.onDestroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun packageInfoMap(): Map<String, String> {
|
|
||||||
val packageInfo =
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
packageManager.getPackageInfo(
|
|
||||||
packageName,
|
|
||||||
android.content.pm.PackageManager.PackageInfoFlags.of(0),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
packageManager.getPackageInfo(packageName, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
val appName =
|
|
||||||
applicationInfo.loadLabel(packageManager)?.toString().orEmpty()
|
|
||||||
val versionCode =
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
||||||
packageInfo.longVersionCode.toString()
|
|
||||||
} else {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
packageInfo.versionCode.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapOf(
|
|
||||||
"appName" to appName,
|
|
||||||
"packageName" to packageName,
|
|
||||||
"version" to packageInfo.versionName.orEmpty(),
|
|
||||||
"buildNumber" to versionCode,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun deviceInfoMap(): Map<String, Any> {
|
|
||||||
val flags = applicationInfo.flags
|
|
||||||
val isEmulator =
|
|
||||||
Build.FINGERPRINT.startsWith("generic") ||
|
|
||||||
Build.FINGERPRINT.startsWith("unknown") ||
|
|
||||||
Build.MODEL.contains("google_sdk") ||
|
|
||||||
Build.MODEL.contains("Emulator") ||
|
|
||||||
Build.MODEL.contains("Android SDK built for x86") ||
|
|
||||||
Build.MANUFACTURER.contains("Genymotion") ||
|
|
||||||
Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic") ||
|
|
||||||
Build.PRODUCT == "google_sdk" ||
|
|
||||||
flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 &&
|
|
||||||
Build.HARDWARE.contains("ranchu")
|
|
||||||
|
|
||||||
return mapOf(
|
|
||||||
"platform" to "android",
|
|
||||||
"brand" to Build.BRAND,
|
|
||||||
"model" to Build.MODEL,
|
|
||||||
"systemVersion" to Build.VERSION.RELEASE,
|
|
||||||
"isPhysicalDevice" to !isEmulator,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,236 +0,0 @@
|
|||||||
package com.gdfw.fxjk.recording
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.camera.core.CameraSelector
|
|
||||||
import androidx.camera.core.Preview
|
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
|
||||||
import androidx.camera.video.Quality
|
|
||||||
import androidx.camera.video.QualitySelector
|
|
||||||
import androidx.camera.video.Recorder
|
|
||||||
import androidx.camera.video.Recording
|
|
||||||
import androidx.camera.video.VideoCapture
|
|
||||||
import androidx.camera.video.VideoRecordEvent
|
|
||||||
import androidx.camera.view.PreviewView
|
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import java.util.concurrent.Executor
|
|
||||||
|
|
||||||
class RecordingCameraController(
|
|
||||||
private val appContext: Context,
|
|
||||||
) {
|
|
||||||
private val mainExecutor: Executor = ContextCompat.getMainExecutor(appContext)
|
|
||||||
|
|
||||||
private var cameraProvider: ProcessCameraProvider? = null
|
|
||||||
private var preview: Preview? = null
|
|
||||||
private var videoCapture: VideoCapture<Recorder>? = null
|
|
||||||
private var activeRecording: Recording? = null
|
|
||||||
private var boundLifecycleOwner: LifecycleOwner? = null
|
|
||||||
|
|
||||||
var status: RecordingStatus = RecordingStatus(RecordingState.IDLE)
|
|
||||||
private set
|
|
||||||
|
|
||||||
var statusListener: ((RecordingStatus) -> Unit)? = null
|
|
||||||
|
|
||||||
private var recordingStartedAt: Long = 0L
|
|
||||||
private var latestOutputPath: String? = null
|
|
||||||
private var pendingStopCallback: ((String?) -> Unit)? = null
|
|
||||||
|
|
||||||
fun bindPreview(
|
|
||||||
lifecycleOwner: LifecycleOwner,
|
|
||||||
previewView: PreviewView,
|
|
||||||
onReady: (Boolean) -> Unit,
|
|
||||||
) {
|
|
||||||
val future = ProcessCameraProvider.getInstance(appContext)
|
|
||||||
future.addListener(
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
val provider = future.get()
|
|
||||||
cameraProvider = provider
|
|
||||||
boundLifecycleOwner = lifecycleOwner
|
|
||||||
|
|
||||||
preview =
|
|
||||||
Preview.Builder().build().also {
|
|
||||||
it.surfaceProvider = previewView.surfaceProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
val recorder =
|
|
||||||
Recorder.Builder()
|
|
||||||
.setQualitySelector(QualitySelector.from(Quality.HD))
|
|
||||||
.build()
|
|
||||||
videoCapture = VideoCapture.withOutput(recorder)
|
|
||||||
|
|
||||||
provider.unbindAll()
|
|
||||||
provider.bindToLifecycle(
|
|
||||||
lifecycleOwner,
|
|
||||||
CameraSelector.DEFAULT_BACK_CAMERA,
|
|
||||||
preview,
|
|
||||||
videoCapture,
|
|
||||||
)
|
|
||||||
|
|
||||||
updateStatus(RecordingStatus(RecordingState.PREVIEWING))
|
|
||||||
onReady(true)
|
|
||||||
} catch (error: Exception) {
|
|
||||||
Log.e(TAG, "bindPreview failed", error)
|
|
||||||
updateStatus(
|
|
||||||
RecordingStatus(
|
|
||||||
RecordingState.ERROR,
|
|
||||||
message = error.message,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
onReady(false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mainExecutor,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun rebindForRecording(
|
|
||||||
lifecycleOwner: LifecycleOwner,
|
|
||||||
previewView: PreviewView,
|
|
||||||
onReady: (Boolean) -> Unit,
|
|
||||||
) {
|
|
||||||
val provider = cameraProvider
|
|
||||||
if (provider == null) {
|
|
||||||
bindPreview(lifecycleOwner, previewView, onReady)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
boundLifecycleOwner = lifecycleOwner
|
|
||||||
provider.unbindAll()
|
|
||||||
provider.bindToLifecycle(
|
|
||||||
lifecycleOwner,
|
|
||||||
CameraSelector.DEFAULT_BACK_CAMERA,
|
|
||||||
preview,
|
|
||||||
videoCapture,
|
|
||||||
)
|
|
||||||
onReady(true)
|
|
||||||
} catch (error: Exception) {
|
|
||||||
Log.e(TAG, "rebindForRecording failed", error)
|
|
||||||
onReady(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun startRecording(
|
|
||||||
withAudio: Boolean,
|
|
||||||
displayName: String?,
|
|
||||||
onStarted: (Boolean, String?) -> Unit,
|
|
||||||
) {
|
|
||||||
val capture = videoCapture
|
|
||||||
if (capture == null || boundLifecycleOwner == null) {
|
|
||||||
onStarted(false, "Camera not ready")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (activeRecording != null) {
|
|
||||||
onStarted(false, "Already recording")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val outputOptions =
|
|
||||||
RecordingOutputFactory.buildMediaStoreOutputOptions(
|
|
||||||
appContext,
|
|
||||||
displayName,
|
|
||||||
)
|
|
||||||
latestOutputPath = null
|
|
||||||
|
|
||||||
val pending =
|
|
||||||
capture.output.prepareRecording(appContext, outputOptions).apply {
|
|
||||||
if (withAudio) {
|
|
||||||
val granted =
|
|
||||||
ContextCompat.checkSelfPermission(
|
|
||||||
appContext,
|
|
||||||
android.Manifest.permission.RECORD_AUDIO,
|
|
||||||
) == android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
||||||
if (granted) {
|
|
||||||
withAudioEnabled()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recordingStartedAt = System.currentTimeMillis()
|
|
||||||
updateStatus(
|
|
||||||
RecordingStatus(
|
|
||||||
RecordingState.RECORDING,
|
|
||||||
outputPath = latestOutputPath,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
activeRecording =
|
|
||||||
pending.start(mainExecutor) { event ->
|
|
||||||
when (event) {
|
|
||||||
is VideoRecordEvent.Start -> Unit
|
|
||||||
is VideoRecordEvent.Finalize -> {
|
|
||||||
activeRecording = null
|
|
||||||
if (event.hasError()) {
|
|
||||||
updateStatus(
|
|
||||||
RecordingStatus(
|
|
||||||
RecordingState.ERROR,
|
|
||||||
message = event.cause?.message ?: "Recording failed",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
latestOutputPath = event.outputResults.outputUri.toString()
|
|
||||||
updateStatus(
|
|
||||||
RecordingStatus(
|
|
||||||
RecordingState.PREVIEWING,
|
|
||||||
outputPath = latestOutputPath,
|
|
||||||
elapsedMillis = System.currentTimeMillis() - recordingStartedAt,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val stopCallback = pendingStopCallback
|
|
||||||
pendingStopCallback = null
|
|
||||||
stopCallback?.invoke(latestOutputPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onStarted(true, latestOutputPath ?: "recording")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stopRecording(onStopped: (String?) -> Unit) {
|
|
||||||
val recording = activeRecording
|
|
||||||
if (recording == null) {
|
|
||||||
onStopped(latestOutputPath)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingStopCallback = onStopped
|
|
||||||
updateStatus(
|
|
||||||
RecordingStatus(
|
|
||||||
RecordingState.STOPPING,
|
|
||||||
outputPath = latestOutputPath,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
recording.stop()
|
|
||||||
activeRecording = null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unbind() {
|
|
||||||
activeRecording?.stop()
|
|
||||||
activeRecording = null
|
|
||||||
cameraProvider?.unbindAll()
|
|
||||||
cameraProvider = null
|
|
||||||
preview = null
|
|
||||||
videoCapture = null
|
|
||||||
boundLifecycleOwner = null
|
|
||||||
updateStatus(RecordingStatus(RecordingState.IDLE))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun elapsedMillis(): Long {
|
|
||||||
if (status.state != RecordingState.RECORDING) return 0L
|
|
||||||
return System.currentTimeMillis() - recordingStartedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateStatus(next: RecordingStatus) {
|
|
||||||
status = next
|
|
||||||
statusListener?.invoke(next)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "RecordingCamera"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.gdfw.fxjk.recording
|
|
||||||
|
|
||||||
enum class RecordingState {
|
|
||||||
IDLE,
|
|
||||||
PREVIEWING,
|
|
||||||
RECORDING,
|
|
||||||
STOPPING,
|
|
||||||
ERROR,
|
|
||||||
}
|
|
||||||
|
|
||||||
data class RecordingStatus(
|
|
||||||
val state: RecordingState,
|
|
||||||
val outputPath: String? = null,
|
|
||||||
val elapsedMillis: Long = 0L,
|
|
||||||
val message: String? = null,
|
|
||||||
) {
|
|
||||||
fun toMap(): Map<String, Any?> =
|
|
||||||
mapOf(
|
|
||||||
"state" to state.name.lowercase(),
|
|
||||||
"outputPath" to outputPath,
|
|
||||||
"elapsedMillis" to elapsedMillis,
|
|
||||||
"message" to message,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.gdfw.fxjk
|
package com.qxy.dronex
|
||||||
|
|
||||||
object AppConstants {
|
object AppConstants {
|
||||||
const val PACKAGE_NAME = "com.gdfw.fxjk"
|
const val PACKAGE_NAME = "com.qxy.dronex"
|
||||||
const val PLATFORM_INFO_CHANNEL = "$PACKAGE_NAME/platform_info"
|
const val PLATFORM_INFO_CHANNEL = "$PACKAGE_NAME/platform_info"
|
||||||
const val RECORDING_METHOD_CHANNEL = "$PACKAGE_NAME/recording"
|
const val RECORDING_METHOD_CHANNEL = "$PACKAGE_NAME/recording"
|
||||||
const val RECORDING_EVENT_CHANNEL = "$PACKAGE_NAME/recording_events"
|
const val RECORDING_EVENT_CHANNEL = "$PACKAGE_NAME/recording_events"
|
||||||
145
android/app/src/main/kotlin/com/qxy/dronex/MainActivity.kt
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
package com.qxy.dronex
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.os.BatteryManager
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Environment
|
||||||
|
import android.os.StatFs
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import com.qxy.dronex.recording.RecordingPlatformHandler
|
||||||
|
import com.qxy.dronex.recording.RecordingPreviewFactory
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
|
||||||
|
class MainActivity : FlutterActivity() {
|
||||||
|
private var platformHandler: RecordingPlatformHandler? = null
|
||||||
|
private var platformInfoChannel: MethodChannel? = null
|
||||||
|
|
||||||
|
var recordingPreviewView: PreviewView? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
super.configureFlutterEngine(flutterEngine)
|
||||||
|
flutterEngine.platformViewsController.registry.registerViewFactory(
|
||||||
|
"recording-camera-preview",
|
||||||
|
RecordingPreviewFactory(this),
|
||||||
|
)
|
||||||
|
|
||||||
|
platformInfoChannel =
|
||||||
|
MethodChannel(
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
AppConstants.PLATFORM_INFO_CHANNEL,
|
||||||
|
)
|
||||||
|
.also { channel ->
|
||||||
|
channel.setMethodCallHandler { call, result ->
|
||||||
|
when (call.method) {
|
||||||
|
"packageInfo" -> result.success(packageInfoMap())
|
||||||
|
"deviceInfo" -> result.success(deviceInfoMap())
|
||||||
|
"deviceHealth" -> result.success(deviceHealthMap())
|
||||||
|
else -> result.notImplemented()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
platformHandler =
|
||||||
|
RecordingPlatformHandler(
|
||||||
|
this,
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attachRecordingPreview(previewView: PreviewView) {
|
||||||
|
recordingPreviewView = previewView
|
||||||
|
}
|
||||||
|
|
||||||
|
fun detachRecordingPreview(previewView: PreviewView? = null) {
|
||||||
|
if (previewView == null || recordingPreviewView === previewView) {
|
||||||
|
recordingPreviewView = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
platformInfoChannel?.setMethodCallHandler(null)
|
||||||
|
platformInfoChannel = null
|
||||||
|
platformHandler?.dispose()
|
||||||
|
platformHandler = null
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun packageInfoMap(): Map<String, String> {
|
||||||
|
val packageInfo =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
packageManager.getPackageInfo(
|
||||||
|
packageName,
|
||||||
|
android.content.pm.PackageManager.PackageInfoFlags.of(0),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION") packageManager.getPackageInfo(packageName, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
val appName = applicationInfo.loadLabel(packageManager)?.toString().orEmpty()
|
||||||
|
val versionCode =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
packageInfo.longVersionCode.toString()
|
||||||
|
} else {
|
||||||
|
@Suppress("DEPRECATION") packageInfo.versionCode.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapOf(
|
||||||
|
"appName" to appName,
|
||||||
|
"packageName" to packageName,
|
||||||
|
"version" to packageInfo.versionName.orEmpty(),
|
||||||
|
"buildNumber" to versionCode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deviceInfoMap(): Map<String, Any> {
|
||||||
|
val flags = applicationInfo.flags
|
||||||
|
val isEmulator =
|
||||||
|
Build.FINGERPRINT.startsWith("generic") ||
|
||||||
|
Build.FINGERPRINT.startsWith("unknown") ||
|
||||||
|
Build.MODEL.contains("google_sdk") ||
|
||||||
|
Build.MODEL.contains("Emulator") ||
|
||||||
|
Build.MODEL.contains("Android SDK built for x86") ||
|
||||||
|
Build.MANUFACTURER.contains("Genymotion") ||
|
||||||
|
Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic") ||
|
||||||
|
Build.PRODUCT == "google_sdk" ||
|
||||||
|
flags and ApplicationInfo.FLAG_DEBUGGABLE != 0 &&
|
||||||
|
Build.HARDWARE.contains("ranchu")
|
||||||
|
|
||||||
|
return mapOf(
|
||||||
|
"platform" to "android",
|
||||||
|
"brand" to Build.BRAND,
|
||||||
|
"model" to Build.MODEL,
|
||||||
|
"systemVersion" to Build.VERSION.RELEASE,
|
||||||
|
"isPhysicalDevice" to !isEmulator,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deviceHealthMap(): Map<String, Any?> {
|
||||||
|
val batteryLevelPercent = readBatteryLevelPercent()
|
||||||
|
val storageAvailablePercent = readStorageAvailablePercent()
|
||||||
|
return mapOf(
|
||||||
|
"batteryLevelPercent" to batteryLevelPercent,
|
||||||
|
"storageAvailablePercent" to storageAvailablePercent,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readBatteryLevelPercent(): Int? {
|
||||||
|
val batteryManager = getSystemService(Context.BATTERY_SERVICE) as? BatteryManager
|
||||||
|
?: return null
|
||||||
|
val level =
|
||||||
|
batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||||
|
return if (level in 0..100) level else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readStorageAvailablePercent(): Double {
|
||||||
|
val stat = StatFs(Environment.getDataDirectory().path)
|
||||||
|
val totalBytes = stat.totalBytes
|
||||||
|
if (totalBytes <= 0L) return 100.0
|
||||||
|
val availableBytes = stat.availableBytes
|
||||||
|
return availableBytes.toDouble() / totalBytes.toDouble() * 100.0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
|
|
||||||
@@ -16,7 +15,8 @@ object DoNotDisturbHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun openAccessSettings(context: Context) {
|
fun openAccessSettings(context: Context) {
|
||||||
val intent = Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS).apply {
|
val intent =
|
||||||
|
Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
}
|
}
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.camera.core.CameraSelector
|
||||||
|
import androidx.camera.core.Preview
|
||||||
|
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||||
|
import androidx.camera.video.Quality
|
||||||
|
import androidx.camera.video.QualitySelector
|
||||||
|
import androidx.camera.video.Recorder
|
||||||
|
import androidx.camera.video.Recording
|
||||||
|
import androidx.camera.video.VideoCapture
|
||||||
|
import androidx.camera.video.VideoRecordEvent
|
||||||
|
import androidx.camera.view.PreviewView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import java.util.concurrent.Executor
|
||||||
|
|
||||||
|
class RecordingCameraController(
|
||||||
|
private val appContext: Context,
|
||||||
|
) {
|
||||||
|
private val mainExecutor: Executor = ContextCompat.getMainExecutor(appContext)
|
||||||
|
|
||||||
|
private var cameraProvider: ProcessCameraProvider? = null
|
||||||
|
private var preview: Preview? = null
|
||||||
|
private var videoCapture: VideoCapture<Recorder>? = null
|
||||||
|
private var activeRecording: Recording? = null
|
||||||
|
private var boundLifecycleOwner: LifecycleOwner? = null
|
||||||
|
|
||||||
|
var status: RecordingStatus = RecordingStatus(RecordingState.IDLE)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var statusListener: ((RecordingStatus) -> Unit)? = null
|
||||||
|
|
||||||
|
private var recordingStartedAt: Long = 0L
|
||||||
|
private var latestOutputPath: String? = null
|
||||||
|
private var pendingStopCallback: ((String?) -> Unit)? = null
|
||||||
|
|
||||||
|
fun bindPreview(
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
previewView: PreviewView,
|
||||||
|
onReady: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
val future = ProcessCameraProvider.getInstance(appContext)
|
||||||
|
future.addListener(
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
val provider = future.get()
|
||||||
|
cameraProvider = provider
|
||||||
|
boundLifecycleOwner = lifecycleOwner
|
||||||
|
|
||||||
|
preview =
|
||||||
|
Preview.Builder().build().also {
|
||||||
|
it.surfaceProvider = previewView.surfaceProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
val recorder =
|
||||||
|
Recorder.Builder()
|
||||||
|
.setQualitySelector(QualitySelector.from(Quality.HD))
|
||||||
|
.build()
|
||||||
|
videoCapture = VideoCapture.withOutput(recorder)
|
||||||
|
|
||||||
|
provider.unbindAll()
|
||||||
|
provider.bindToLifecycle(
|
||||||
|
lifecycleOwner,
|
||||||
|
CameraSelector.DEFAULT_BACK_CAMERA,
|
||||||
|
preview,
|
||||||
|
videoCapture,
|
||||||
|
)
|
||||||
|
|
||||||
|
updateStatus(RecordingStatus(RecordingState.PREVIEWING))
|
||||||
|
onReady(true)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "bindPreview failed", error)
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.ERROR,
|
||||||
|
message = error.message,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
onReady(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mainExecutor,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun rebindForRecording(
|
||||||
|
lifecycleOwner: LifecycleOwner,
|
||||||
|
previewView: PreviewView,
|
||||||
|
onReady: (Boolean) -> Unit,
|
||||||
|
) {
|
||||||
|
val provider = cameraProvider
|
||||||
|
if (provider == null) {
|
||||||
|
bindPreview(lifecycleOwner, previewView, onReady)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
boundLifecycleOwner === lifecycleOwner &&
|
||||||
|
preview != null &&
|
||||||
|
videoCapture != null
|
||||||
|
) {
|
||||||
|
onReady(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
boundLifecycleOwner = lifecycleOwner
|
||||||
|
provider.unbindAll()
|
||||||
|
provider.bindToLifecycle(
|
||||||
|
lifecycleOwner,
|
||||||
|
CameraSelector.DEFAULT_BACK_CAMERA,
|
||||||
|
preview,
|
||||||
|
videoCapture,
|
||||||
|
)
|
||||||
|
onReady(true)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
Log.e(TAG, "rebindForRecording failed", error)
|
||||||
|
onReady(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startRecording(
|
||||||
|
withAudio: Boolean,
|
||||||
|
displayName: String?,
|
||||||
|
onStarted: (Boolean, String?) -> Unit,
|
||||||
|
) {
|
||||||
|
val capture = videoCapture
|
||||||
|
if (capture == null || boundLifecycleOwner == null) {
|
||||||
|
onStarted(false, "Camera not ready")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeRecording != null) {
|
||||||
|
onStarted(false, "Already recording")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val outputOptions =
|
||||||
|
RecordingOutputFactory.buildMediaStoreOutputOptions(
|
||||||
|
appContext,
|
||||||
|
displayName,
|
||||||
|
)
|
||||||
|
latestOutputPath = null
|
||||||
|
|
||||||
|
val pending =
|
||||||
|
capture.output.prepareRecording(appContext, outputOptions).apply {
|
||||||
|
if (withAudio) {
|
||||||
|
val granted =
|
||||||
|
ContextCompat.checkSelfPermission(
|
||||||
|
appContext,
|
||||||
|
android.Manifest.permission.RECORD_AUDIO,
|
||||||
|
) == android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||||
|
if (granted) {
|
||||||
|
withAudioEnabled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recordingStartedAt = System.currentTimeMillis()
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.RECORDING,
|
||||||
|
outputPath = latestOutputPath,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
activeRecording =
|
||||||
|
pending.start(mainExecutor) { event ->
|
||||||
|
when (event) {
|
||||||
|
is VideoRecordEvent.Start -> Unit
|
||||||
|
is VideoRecordEvent.Finalize -> {
|
||||||
|
activeRecording = null
|
||||||
|
if (event.hasError()) {
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.ERROR,
|
||||||
|
message = event.cause?.message
|
||||||
|
?: "Recording failed",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
latestOutputPath = event.outputResults.outputUri.toString()
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.PREVIEWING,
|
||||||
|
outputPath = latestOutputPath,
|
||||||
|
elapsedMillis =
|
||||||
|
System.currentTimeMillis() -
|
||||||
|
recordingStartedAt,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val stopCallback = pendingStopCallback
|
||||||
|
pendingStopCallback = null
|
||||||
|
stopCallback?.invoke(latestOutputPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onStarted(true, latestOutputPath ?: "recording")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopRecording(onStopped: (String?) -> Unit) {
|
||||||
|
val recording = activeRecording
|
||||||
|
if (recording == null) {
|
||||||
|
onStopped(latestOutputPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingStopCallback = onStopped
|
||||||
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
RecordingState.STOPPING,
|
||||||
|
outputPath = latestOutputPath,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
recording.stop()
|
||||||
|
activeRecording = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unbind() {
|
||||||
|
activeRecording?.stop()
|
||||||
|
activeRecording = null
|
||||||
|
cameraProvider?.unbindAll()
|
||||||
|
cameraProvider = null
|
||||||
|
preview = null
|
||||||
|
videoCapture = null
|
||||||
|
boundLifecycleOwner = null
|
||||||
|
updateStatus(RecordingStatus(RecordingState.IDLE))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun elapsedMillis(): Long {
|
||||||
|
if (status.state != RecordingState.RECORDING) return 0L
|
||||||
|
return System.currentTimeMillis() - recordingStartedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateStatus(next: RecordingStatus) {
|
||||||
|
status = next
|
||||||
|
statusListener?.invoke(next)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "RecordingCamera"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,21 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.app.Service
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.ServiceInfo
|
import android.content.pm.ServiceInfo
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
import com.gdfw.fxjk.AppConstants
|
import com.qxy.dronex.AppConstants
|
||||||
import com.gdfw.fxjk.MainActivity
|
import com.qxy.dronex.MainActivity
|
||||||
|
|
||||||
class RecordingForegroundService : LifecycleService() {
|
class RecordingForegroundService : LifecycleService() {
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
@@ -94,7 +93,8 @@ class RecordingForegroundService : LifecycleService() {
|
|||||||
CHANNEL_ID,
|
CHANNEL_ID,
|
||||||
"录制服务",
|
"录制服务",
|
||||||
NotificationManager.IMPORTANCE_LOW,
|
NotificationManager.IMPORTANCE_LOW,
|
||||||
).apply {
|
)
|
||||||
|
.apply {
|
||||||
description = "保持相机录制在后台与息屏时继续运行"
|
description = "保持相机录制在后台与息屏时继续运行"
|
||||||
setShowBadge(false)
|
setShowBadge(false)
|
||||||
}
|
}
|
||||||
@@ -146,11 +146,9 @@ class RecordingForegroundService : LifecycleService() {
|
|||||||
const val NOTIFICATION_ID = 1001
|
const val NOTIFICATION_ID = 1001
|
||||||
private const val WAKE_LOCK_TAG = "record_tool:recording_wake_lock"
|
private const val WAKE_LOCK_TAG = "record_tool:recording_wake_lock"
|
||||||
|
|
||||||
@Volatile
|
@Volatile var isRunning: Boolean = false
|
||||||
var isRunning: Boolean = false
|
|
||||||
|
|
||||||
@Volatile
|
@Volatile var instance: RecordingForegroundService? = null
|
||||||
var instance: RecordingForegroundService? = null
|
|
||||||
|
|
||||||
fun start(context: Context) {
|
fun start(context: Context) {
|
||||||
val intent =
|
val intent =
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -10,7 +10,7 @@ import java.util.Date
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
object RecordingOutputFactory {
|
object RecordingOutputFactory {
|
||||||
private const val RELATIVE_PATH = "Movies/飞行极控"
|
private const val RELATIVE_PATH = "Movies/飞行极控录像工作台"
|
||||||
private const val MIME_TYPE = "video/mp4"
|
private const val MIME_TYPE = "video/mp4"
|
||||||
|
|
||||||
fun buildMediaStoreOutputOptions(
|
fun buildMediaStoreOutputOptions(
|
||||||
@@ -44,8 +44,7 @@ object RecordingOutputFactory {
|
|||||||
"$trimmed.mp4"
|
"$trimmed.mp4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val timestamp =
|
val timestamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
|
||||||
SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
|
|
||||||
return "REC_$timestamp.mp4"
|
return "REC_$timestamp.mp4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.WindowInsetsControllerCompat
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
import com.gdfw.fxjk.AppConstants
|
import com.qxy.dronex.AppConstants
|
||||||
import com.gdfw.fxjk.MainActivity
|
import com.qxy.dronex.MainActivity
|
||||||
import io.flutter.plugin.common.BinaryMessenger
|
import io.flutter.plugin.common.BinaryMessenger
|
||||||
import io.flutter.plugin.common.EventChannel
|
import io.flutter.plugin.common.EventChannel
|
||||||
import io.flutter.plugin.common.MethodCall
|
import io.flutter.plugin.common.MethodCall
|
||||||
@@ -18,10 +16,8 @@ class RecordingPlatformHandler(
|
|||||||
private val activity: MainActivity,
|
private val activity: MainActivity,
|
||||||
messenger: BinaryMessenger,
|
messenger: BinaryMessenger,
|
||||||
) : MethodChannel.MethodCallHandler, EventChannel.StreamHandler {
|
) : MethodChannel.MethodCallHandler, EventChannel.StreamHandler {
|
||||||
private val methodChannel =
|
private val methodChannel = MethodChannel(messenger, AppConstants.RECORDING_METHOD_CHANNEL)
|
||||||
MethodChannel(messenger, AppConstants.RECORDING_METHOD_CHANNEL)
|
private val eventChannel = EventChannel(messenger, AppConstants.RECORDING_EVENT_CHANNEL)
|
||||||
private val eventChannel =
|
|
||||||
EventChannel(messenger, AppConstants.RECORDING_EVENT_CHANNEL)
|
|
||||||
|
|
||||||
private val mainHandler = Handler(Looper.getMainLooper())
|
private val mainHandler = Handler(Looper.getMainLooper())
|
||||||
private var eventSink: EventChannel.EventSink? = null
|
private var eventSink: EventChannel.EventSink? = null
|
||||||
@@ -33,9 +29,7 @@ class RecordingPlatformHandler(
|
|||||||
methodChannel.setMethodCallHandler(this)
|
methodChannel.setMethodCallHandler(this)
|
||||||
eventChannel.setStreamHandler(this)
|
eventChannel.setStreamHandler(this)
|
||||||
controller.statusListener = { status ->
|
controller.statusListener = { status ->
|
||||||
mainHandler.post {
|
mainHandler.post { eventSink?.success(status.toMap()) }
|
||||||
eventSink?.success(status.toMap())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,14 +54,12 @@ class RecordingPlatformHandler(
|
|||||||
controller.unbind()
|
controller.unbind()
|
||||||
result.success(null)
|
result.success(null)
|
||||||
}
|
}
|
||||||
"hasNotificationPolicyAccess" ->
|
"hasNotificationPolicyAccess" -> result.success(DoNotDisturbHelper.hasAccess(activity))
|
||||||
result.success(DoNotDisturbHelper.hasAccess(activity))
|
|
||||||
"openNotificationPolicySettings" -> {
|
"openNotificationPolicySettings" -> {
|
||||||
DoNotDisturbHelper.openAccessSettings(activity)
|
DoNotDisturbHelper.openAccessSettings(activity)
|
||||||
result.success(null)
|
result.success(null)
|
||||||
}
|
}
|
||||||
"enableDoNotDisturb" ->
|
"enableDoNotDisturb" -> result.success(DoNotDisturbHelper.enable(activity))
|
||||||
result.success(DoNotDisturbHelper.enable(activity))
|
|
||||||
"disableDoNotDisturb" -> {
|
"disableDoNotDisturb" -> {
|
||||||
DoNotDisturbHelper.disable(activity)
|
DoNotDisturbHelper.disable(activity)
|
||||||
result.success(null)
|
result.success(null)
|
||||||
@@ -84,8 +76,7 @@ class RecordingPlatformHandler(
|
|||||||
result.success(null)
|
result.success(null)
|
||||||
}
|
}
|
||||||
"getStatus" -> result.success(controller.status.toMap())
|
"getStatus" -> result.success(controller.status.toMap())
|
||||||
"isForegroundServiceRunning" ->
|
"isForegroundServiceRunning" -> result.success(RecordingForegroundService.isRunning)
|
||||||
result.success(RecordingForegroundService.isRunning)
|
|
||||||
else -> result.notImplemented()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,8 +138,7 @@ class RecordingPlatformHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun rebindAndCapture() {
|
fun rebindAndCapture() {
|
||||||
val lifecycleOwner =
|
val lifecycleOwner = RecordingForegroundService.instance ?: activity
|
||||||
RecordingForegroundService.instance ?: activity
|
|
||||||
controller.rebindForRecording(lifecycleOwner, previewView) { ready ->
|
controller.rebindForRecording(lifecycleOwner, previewView) { ready ->
|
||||||
if (ready) {
|
if (ready) {
|
||||||
beginCapture()
|
beginCapture()
|
||||||
@@ -171,23 +161,30 @@ class RecordingPlatformHandler(
|
|||||||
controller.stopRecording { path ->
|
controller.stopRecording { path ->
|
||||||
RecordingSession.stopForeground(activity)
|
RecordingSession.stopForeground(activity)
|
||||||
DoNotDisturbHelper.disable(activity)
|
DoNotDisturbHelper.disable(activity)
|
||||||
mainHandler.post {
|
val previewView = activity.recordingPreviewView
|
||||||
val gallerySaved =
|
if (previewView == null) {
|
||||||
path != null &&
|
mainHandler.post { deliverStopResult(result, path) }
|
||||||
controller.status.state != RecordingState.ERROR
|
return@stopRecording
|
||||||
val payload = mutableMapOf<String, Any?>(
|
}
|
||||||
|
controller.rebindForRecording(activity, previewView) { _ ->
|
||||||
|
mainHandler.post { deliverStopResult(result, path) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deliverStopResult(result: MethodChannel.Result, path: String?) {
|
||||||
|
val gallerySaved = path != null && controller.status.state != RecordingState.ERROR
|
||||||
|
val payload =
|
||||||
|
mutableMapOf<String, Any?>(
|
||||||
"outputPath" to path,
|
"outputPath" to path,
|
||||||
"status" to controller.status.toMap(),
|
"status" to controller.status.toMap(),
|
||||||
"gallerySaved" to gallerySaved,
|
"gallerySaved" to gallerySaved,
|
||||||
)
|
)
|
||||||
if (!gallerySaved) {
|
if (!gallerySaved) {
|
||||||
payload["galleryErrorMessage"] =
|
payload["galleryErrorMessage"] = controller.status.message ?: "保存到相册失败"
|
||||||
controller.status.message ?: "保存到相册失败"
|
|
||||||
}
|
}
|
||||||
result.success(payload)
|
result.success(payload)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setImmersiveMode(enabled: Boolean) {
|
private fun setImmersiveMode(enabled: Boolean) {
|
||||||
val window = activity.window
|
val window = activity.window
|
||||||
@@ -209,16 +206,19 @@ class RecordingPlatformHandler(
|
|||||||
override fun run() {
|
override fun run() {
|
||||||
if (controller.status.state == RecordingState.RECORDING) {
|
if (controller.status.state == RecordingState.RECORDING) {
|
||||||
eventSink?.success(
|
eventSink?.success(
|
||||||
controller.status.copy(
|
controller
|
||||||
elapsedMillis = controller.elapsedMillis(),
|
.status
|
||||||
).toMap(),
|
.copy(
|
||||||
|
elapsedMillis =
|
||||||
|
controller.elapsedMillis(),
|
||||||
|
)
|
||||||
|
.toMap(),
|
||||||
)
|
)
|
||||||
mainHandler.postDelayed(this, 1000L)
|
mainHandler.postDelayed(this, 1000L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.also {
|
|
||||||
mainHandler.post(it)
|
|
||||||
}
|
}
|
||||||
|
.also { mainHandler.post(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopElapsedTicker() {
|
private fun stopElapsedTicker() {
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.camera.view.PreviewView
|
import androidx.camera.view.PreviewView
|
||||||
import com.gdfw.fxjk.MainActivity
|
import com.qxy.dronex.MainActivity
|
||||||
import io.flutter.plugin.common.StandardMessageCodec
|
import io.flutter.plugin.common.StandardMessageCodec
|
||||||
import io.flutter.plugin.platform.PlatformView
|
import io.flutter.plugin.platform.PlatformView
|
||||||
import io.flutter.plugin.platform.PlatformViewFactory
|
import io.flutter.plugin.platform.PlatformViewFactory
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.gdfw.fxjk.recording
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.lifecycle.LifecycleService
|
import androidx.lifecycle.LifecycleService
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.qxy.dronex.recording
|
||||||
|
|
||||||
|
enum class RecordingState {
|
||||||
|
IDLE,
|
||||||
|
PREVIEWING,
|
||||||
|
RECORDING,
|
||||||
|
STOPPING,
|
||||||
|
ERROR,
|
||||||
|
}
|
||||||
|
|
||||||
|
data class RecordingStatus(
|
||||||
|
val state: RecordingState,
|
||||||
|
val outputPath: String? = null,
|
||||||
|
val elapsedMillis: Long = 0L,
|
||||||
|
val message: String? = null,
|
||||||
|
) {
|
||||||
|
fun toMap(): Map<String, Any?> =
|
||||||
|
mapOf(
|
||||||
|
"state" to state.name.lowercase(),
|
||||||
|
"outputPath" to outputPath,
|
||||||
|
"elapsedMillis" to elapsedMillis,
|
||||||
|
"message" to message,
|
||||||
|
)
|
||||||
|
}
|
||||||
BIN
android/app/src/main/res/drawable-nodpi/startup_background.png
Normal file
|
After Width: | Height: | Size: 262 KiB |
@@ -1,12 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Modify this file to customize your launch splash screen -->
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="?android:colorBackground" />
|
<item>
|
||||||
|
|
||||||
<!-- You can insert your own image assets here -->
|
|
||||||
<!-- <item>
|
|
||||||
<bitmap
|
<bitmap
|
||||||
android:gravity="center"
|
android:gravity="fill"
|
||||||
android:src="@mipmap/launch_image" />
|
android:src="@drawable/startup_background" />
|
||||||
</item> -->
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Modify this file to customize your launch splash screen -->
|
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:drawable="@android:color/white" />
|
<item>
|
||||||
|
|
||||||
<!-- You can insert your own image assets here -->
|
|
||||||
<!-- <item>
|
|
||||||
<bitmap
|
<bitmap
|
||||||
android:gravity="center"
|
android:gravity="fill"
|
||||||
android:src="@mipmap/launch_image" />
|
android:src="@drawable/startup_background" />
|
||||||
</item> -->
|
</item>
|
||||||
</layer-list>
|
</layer-list>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 24 KiB |
@@ -1,7 +0,0 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<!-- The INTERNET permission is required for development. Specifically,
|
|
||||||
the Flutter tool needs it to communicate with the running application
|
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
|
||||||
-->
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
|
||||||
</manifest>
|
|
||||||
BIN
assets/images/image_copy.png
Normal file
|
After Width: | Height: | Size: 795 B |
BIN
assets/images/image_delete.png
Normal file
|
After Width: | Height: | Size: 1011 B |
BIN
assets/images/image_dialog_bg.png
Normal file
|
After Width: | Height: | Size: 119 KiB |
BIN
assets/images/image_logo.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
assets/images/image_vs.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
1
build-apk-split.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
flutter build apk --release --split-per-abi
|
||||||
1
build-apk.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
flutter build apk --release
|
||||||
3
devtools_options.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
||||||
@@ -1,22 +1,55 @@
|
|||||||
PODS:
|
PODS:
|
||||||
|
- connectivity_plus (0.0.1):
|
||||||
|
- Flutter
|
||||||
- Flutter (1.0.0)
|
- Flutter (1.0.0)
|
||||||
- permission_handler_apple (9.3.0):
|
- path_provider_foundation (0.0.1):
|
||||||
|
- Flutter
|
||||||
|
- FlutterMacOS
|
||||||
|
- permission_handler_apple (9.4.8):
|
||||||
|
- Flutter
|
||||||
|
- shared_preferences_foundation (0.0.1):
|
||||||
|
- Flutter
|
||||||
|
- FlutterMacOS
|
||||||
|
- sqflite_darwin (0.0.4):
|
||||||
|
- Flutter
|
||||||
|
- FlutterMacOS
|
||||||
|
- url_launcher_ios (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
|
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
|
||||||
- Flutter (from `Flutter`)
|
- Flutter (from `Flutter`)
|
||||||
|
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
|
||||||
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
||||||
|
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
|
||||||
|
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
|
||||||
|
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
|
connectivity_plus:
|
||||||
|
:path: ".symlinks/plugins/connectivity_plus/ios"
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: Flutter
|
:path: Flutter
|
||||||
|
path_provider_foundation:
|
||||||
|
:path: ".symlinks/plugins/path_provider_foundation/darwin"
|
||||||
permission_handler_apple:
|
permission_handler_apple:
|
||||||
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
||||||
|
shared_preferences_foundation:
|
||||||
|
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
|
||||||
|
sqflite_darwin:
|
||||||
|
:path: ".symlinks/plugins/sqflite_darwin/darwin"
|
||||||
|
url_launcher_ios:
|
||||||
|
:path: ".symlinks/plugins/url_launcher_ios/ios"
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
|
connectivity_plus: cb623214f4e1f6ef8fe7403d580fdad517d2f7dd
|
||||||
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
|
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
|
||||||
permission_handler_apple: 4ed2196e43d0651e8ff7ca3483a069d469701f2d
|
path_provider_foundation: bb55f6dbba17d0dccd6737fe6f7f34fbd0376880
|
||||||
|
permission_handler_apple: 92d754bbaa7361d436db2d6c3c1c2a0fdcec462e
|
||||||
|
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
|
||||||
|
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
|
||||||
|
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
|
||||||
|
|
||||||
PODFILE CHECKSUM: 6f58d96c1fb09d1d57dbcbf38a5d856d7302054a
|
PODFILE CHECKSUM: 5a82b772179df87e6518bddc6f9bb8b4053ce48b
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||||
64BC3B3C75FABAA128C4FE7A /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D84231833EC084C45F76D9A0 /* Pods_RunnerTests.framework */; };
|
64BC3B3C75FABAA128C4FE7A /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D84231833EC084C45F76D9A0 /* Pods_RunnerTests.framework */; };
|
||||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
||||||
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
|
|
||||||
8D5D9D9E2C69000100F10001 /* RecordingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */; };
|
|
||||||
87DA76CA5231F693C9392B80 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6AA1C86CE710449CC3E8FCD /* Pods_Runner.framework */; };
|
87DA76CA5231F693C9392B80 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6AA1C86CE710449CC3E8FCD /* Pods_Runner.framework */; };
|
||||||
|
8D5D9D9E2C69000100F10001 /* RecordingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */; };
|
||||||
|
8E5D9D9E2C69000100F10002 /* PlatformInfoPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E5D9D9D2C69000100F10002 /* PlatformInfoPlugin.swift */; };
|
||||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
||||||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
||||||
@@ -53,9 +53,9 @@
|
|||||||
69561E7442E8CC939DB2B482 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
|
69561E7442E8CC939DB2B482 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; };
|
|
||||||
8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordingPlugin.swift; sourceTree = "<group>"; };
|
|
||||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||||
|
8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordingPlugin.swift; sourceTree = "<group>"; };
|
||||||
|
8E5D9D9D2C69000100F10002 /* PlatformInfoPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlatformInfoPlugin.swift; sourceTree = "<group>"; };
|
||||||
95C6AC1536EA3DBA2D369C55 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
|
95C6AC1536EA3DBA2D369C55 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
|
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
|
||||||
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
|
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
|
||||||
@@ -84,7 +84,6 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */,
|
|
||||||
87DA76CA5231F693C9392B80 /* Pods_Runner.framework in Frameworks */,
|
87DA76CA5231F693C9392B80 /* Pods_Runner.framework in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@@ -102,7 +101,6 @@
|
|||||||
DFA822DC4965C5AFAFF6BB41 /* Pods-RunnerTests.release.xcconfig */,
|
DFA822DC4965C5AFAFF6BB41 /* Pods-RunnerTests.release.xcconfig */,
|
||||||
99DBE6263F70650B13C33EAC /* Pods-RunnerTests.profile.xcconfig */,
|
99DBE6263F70650B13C33EAC /* Pods-RunnerTests.profile.xcconfig */,
|
||||||
);
|
);
|
||||||
name = Pods;
|
|
||||||
path = Pods;
|
path = Pods;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
@@ -126,7 +124,6 @@
|
|||||||
9740EEB11CF90186004384FC /* Flutter */ = {
|
9740EEB11CF90186004384FC /* Flutter */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */,
|
|
||||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
|
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
|
||||||
9740EEB21CF90195004384FC /* Debug.xcconfig */,
|
9740EEB21CF90195004384FC /* Debug.xcconfig */,
|
||||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
|
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
|
||||||
@@ -167,6 +164,7 @@
|
|||||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
||||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
||||||
8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */,
|
8D5D9D9D2C69000100F10001 /* RecordingPlugin.swift */,
|
||||||
|
8E5D9D9D2C69000100F10002 /* PlatformInfoPlugin.swift */,
|
||||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
||||||
);
|
);
|
||||||
path = Runner;
|
path = Runner;
|
||||||
@@ -205,16 +203,14 @@
|
|||||||
97C146EC1CF9000F007C117D /* Resources */,
|
97C146EC1CF9000F007C117D /* Resources */,
|
||||||
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
9705A1C41CF9048500538489 /* Embed Frameworks */,
|
||||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
|
||||||
62D3774184B6C76B8E34C8C2 /* [CP] Copy Pods Resources */,
|
7858230D5ADC7A99F778CB03 /* [CP] Embed Pods Frameworks */,
|
||||||
|
99E9790F23C2D0C0B51A6C19 /* [CP] Copy Pods Resources */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
dependencies = (
|
dependencies = (
|
||||||
);
|
);
|
||||||
name = Runner;
|
name = Runner;
|
||||||
packageProductDependencies = (
|
|
||||||
78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */,
|
|
||||||
);
|
|
||||||
productName = Runner;
|
productName = Runner;
|
||||||
productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
|
productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
|
||||||
productType = "com.apple.product-type.application";
|
productType = "com.apple.product-type.application";
|
||||||
@@ -248,9 +244,6 @@
|
|||||||
Base,
|
Base,
|
||||||
);
|
);
|
||||||
mainGroup = 97C146E51CF9000F007C117D;
|
mainGroup = 97C146E51CF9000F007C117D;
|
||||||
packageReferences = (
|
|
||||||
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */,
|
|
||||||
);
|
|
||||||
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
|
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
projectRoot = "";
|
projectRoot = "";
|
||||||
@@ -343,21 +336,21 @@
|
|||||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
62D3774184B6C76B8E34C8C2 /* [CP] Copy Pods Resources */ = {
|
7858230D5ADC7A99F778CB03 /* [CP] Embed Pods Frameworks */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
);
|
);
|
||||||
inputFileListPaths = (
|
inputFileListPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||||
);
|
);
|
||||||
name = "[CP] Copy Pods Resources";
|
name = "[CP] Embed Pods Frameworks";
|
||||||
outputFileListPaths = (
|
outputFileListPaths = (
|
||||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
|
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
|
||||||
showEnvVarsInLog = 0;
|
showEnvVarsInLog = 0;
|
||||||
};
|
};
|
||||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||||
@@ -375,6 +368,23 @@
|
|||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
|
||||||
};
|
};
|
||||||
|
99E9790F23C2D0C0B51A6C19 /* [CP] Copy Pods Resources */ = {
|
||||||
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
inputFileListPaths = (
|
||||||
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
|
||||||
|
);
|
||||||
|
name = "[CP] Copy Pods Resources";
|
||||||
|
outputFileListPaths = (
|
||||||
|
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
shellPath = /bin/sh;
|
||||||
|
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
|
||||||
|
showEnvVarsInLog = 0;
|
||||||
|
};
|
||||||
/* End PBXShellScriptBuildPhase section */
|
/* End PBXShellScriptBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
@@ -392,6 +402,7 @@
|
|||||||
files = (
|
files = (
|
||||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
||||||
8D5D9D9E2C69000100F10001 /* RecordingPlugin.swift in Sources */,
|
8D5D9D9E2C69000100F10001 /* RecordingPlugin.swift in Sources */,
|
||||||
|
8E5D9D9E2C69000100F10002 /* PlatformInfoPlugin.swift in Sources */,
|
||||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@@ -492,7 +503,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -509,7 +520,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -527,7 +538,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||||
@@ -543,7 +554,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||||
@@ -675,7 +686,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -698,7 +709,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.flutterTemplate;
|
PRODUCT_BUNDLE_IDENTIFIER = com.qxy.dronex;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -740,20 +751,6 @@
|
|||||||
defaultConfigurationName = Release;
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
/* Begin XCLocalSwiftPackageReference section */
|
|
||||||
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */ = {
|
|
||||||
isa = XCLocalSwiftPackageReference;
|
|
||||||
relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;
|
|
||||||
};
|
|
||||||
/* End XCLocalSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
|
||||||
78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
productName = FlutterGeneratedPluginSwiftPackage;
|
|
||||||
};
|
|
||||||
/* End XCSwiftPackageProductDependency section */
|
|
||||||
};
|
};
|
||||||
rootObject = 97C146E61CF9000F007C117D /* Project object */;
|
rootObject = 97C146E61CF9000F007C117D /* Project object */;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1510"
|
LastUpgradeVersion = "1510"
|
||||||
version = "1.3">
|
version = "1.7">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
buildImplicitDependencies = "YES">
|
buildImplicitDependencies = "YES">
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
</Testables>
|
</Testables>
|
||||||
</TestAction>
|
</TestAction>
|
||||||
<LaunchAction
|
<LaunchAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Release"
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
|
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 184 KiB |
|
Before Width: | Height: | Size: 622 B After Width: | Height: | Size: 976 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 945 B After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 20 KiB |
@@ -7,7 +7,7 @@
|
|||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>飞行极控</string>
|
<string>飞行极控录像工作台</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>飞行极控</string>
|
<string>飞行极控录像工作台</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import UIKit
|
|||||||
final class PlatformInfoPlugin: NSObject, FlutterPlugin {
|
final class PlatformInfoPlugin: NSObject, FlutterPlugin {
|
||||||
static func register(with registrar: FlutterPluginRegistrar) {
|
static func register(with registrar: FlutterPluginRegistrar) {
|
||||||
let channel = FlutterMethodChannel(
|
let channel = FlutterMethodChannel(
|
||||||
name: "com.gdfw.fxjk/platform_info",
|
name: "com.qxy.dronex/platform_info",
|
||||||
binaryMessenger: registrar.messenger()
|
binaryMessenger: registrar.messenger()
|
||||||
)
|
)
|
||||||
let plugin = PlatformInfoPlugin()
|
let plugin = PlatformInfoPlugin()
|
||||||
@@ -17,6 +17,8 @@ final class PlatformInfoPlugin: NSObject, FlutterPlugin {
|
|||||||
result(packageInfoMap())
|
result(packageInfoMap())
|
||||||
case "deviceInfo":
|
case "deviceInfo":
|
||||||
result(deviceInfoMap())
|
result(deviceInfoMap())
|
||||||
|
case "deviceHealth":
|
||||||
|
result(deviceHealthMap())
|
||||||
default:
|
default:
|
||||||
result(FlutterMethodNotImplemented)
|
result(FlutterMethodNotImplemented)
|
||||||
}
|
}
|
||||||
@@ -32,6 +34,30 @@ final class PlatformInfoPlugin: NSObject, FlutterPlugin {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func deviceHealthMap() -> [String: Any?] {
|
||||||
|
let device = UIDevice.current
|
||||||
|
device.isBatteryMonitoringEnabled = true
|
||||||
|
|
||||||
|
var batteryLevelPercent: Int?
|
||||||
|
let batteryLevel = device.batteryLevel
|
||||||
|
if batteryLevel >= 0 {
|
||||||
|
batteryLevelPercent = Int((batteryLevel * 100).rounded())
|
||||||
|
}
|
||||||
|
|
||||||
|
var storageAvailablePercent = 100.0
|
||||||
|
if let attrs = try? FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory()),
|
||||||
|
let free = attrs[.systemFreeSize] as? NSNumber,
|
||||||
|
let total = attrs[.systemSize] as? NSNumber,
|
||||||
|
total.doubleValue > 0 {
|
||||||
|
storageAvailablePercent = free.doubleValue / total.doubleValue * 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
"batteryLevelPercent": batteryLevelPercent,
|
||||||
|
"storageAvailablePercent": storageAvailablePercent,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
private func deviceInfoMap() -> [String: Any] {
|
private func deviceInfoMap() -> [String: Any] {
|
||||||
let device = UIDevice.current
|
let device = UIDevice.current
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -129,20 +129,37 @@ private final class RecordingCameraController: NSObject, AVCaptureFileOutputReco
|
|||||||
var statusListener: (([String: Any]) -> Void)?
|
var statusListener: (([String: Any]) -> Void)?
|
||||||
|
|
||||||
func attach(previewView: RecordingPreviewView) {
|
func attach(previewView: RecordingPreviewView) {
|
||||||
|
let bindPreview = { [weak self, weak previewView] in
|
||||||
|
guard let self, let previewView else { return }
|
||||||
self.previewView = previewView
|
self.previewView = previewView
|
||||||
previewView.previewLayer.session = session
|
previewView.previewLayer.session = self.session
|
||||||
|
}
|
||||||
|
if Thread.isMainThread {
|
||||||
|
bindPreview()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async(execute: bindPreview)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func detach(previewView: RecordingPreviewView) {
|
func detach(previewView: RecordingPreviewView) {
|
||||||
|
let unbindPreview = { [weak self, weak previewView] in
|
||||||
|
guard let self, let previewView else { return }
|
||||||
if self.previewView === previewView {
|
if self.previewView === previewView {
|
||||||
self.previewView?.previewLayer.session = nil
|
previewView.previewLayer.session = nil
|
||||||
self.previewView = nil
|
self.previewView = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if Thread.isMainThread {
|
||||||
|
unbindPreview()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async(execute: unbindPreview)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func initializePreview(result: @escaping FlutterResult) {
|
func initializePreview(result: @escaping FlutterResult) {
|
||||||
guard let previewView else {
|
guard let previewView else {
|
||||||
result(FlutterError(code: "NO_PREVIEW", message: "Camera preview is not attached", details: nil))
|
result(
|
||||||
|
FlutterError(code: "NO_PREVIEW", message: "Camera preview is not attached", details: nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +193,8 @@ private final class RecordingCameraController: NSObject, AVCaptureFileOutputReco
|
|||||||
|
|
||||||
func startRecording(withAudio: Bool, displayName: String?, result: @escaping FlutterResult) {
|
func startRecording(withAudio: Bool, displayName: String?, result: @escaping FlutterResult) {
|
||||||
guard previewView != nil else {
|
guard previewView != nil else {
|
||||||
result(FlutterError(code: "NO_PREVIEW", message: "Camera preview is not attached", details: nil))
|
result(
|
||||||
|
FlutterError(code: "NO_PREVIEW", message: "Camera preview is not attached", details: nil))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +324,9 @@ private final class RecordingCameraController: NSObject, AVCaptureFileOutputReco
|
|||||||
if let error {
|
if let error {
|
||||||
latestGallerySaved = false
|
latestGallerySaved = false
|
||||||
latestGalleryErrorMessage = error.localizedDescription
|
latestGalleryErrorMessage = error.localizedDescription
|
||||||
updateStatus(RecordingStatus(state: .error, outputPath: latestOutputPath, message: error.localizedDescription))
|
updateStatus(
|
||||||
|
RecordingStatus(
|
||||||
|
state: .error, outputPath: latestOutputPath, message: error.localizedDescription))
|
||||||
finishStopRecording(stopResult: stopResult)
|
finishStopRecording(stopResult: stopResult)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -411,10 +431,14 @@ private final class RecordingCameraController: NSObject, AVCaptureFileOutputReco
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
|
guard
|
||||||
|
let videoDevice = AVCaptureDevice.default(
|
||||||
|
.builtInWideAngleCamera, for: .video, position: .back)
|
||||||
?? AVCaptureDevice.default(for: .video)
|
?? AVCaptureDevice.default(for: .video)
|
||||||
else {
|
else {
|
||||||
throw NSError(domain: "RecordingCamera", code: 1, userInfo: [NSLocalizedDescriptionKey: "No camera device available"])
|
throw NSError(
|
||||||
|
domain: "RecordingCamera", code: 1,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "No camera device available"])
|
||||||
}
|
}
|
||||||
|
|
||||||
let nextVideoInput = try AVCaptureDeviceInput(device: videoDevice)
|
let nextVideoInput = try AVCaptureDeviceInput(device: videoDevice)
|
||||||
@@ -424,14 +448,18 @@ private final class RecordingCameraController: NSObject, AVCaptureFileOutputReco
|
|||||||
|
|
||||||
guard session.canAddInput(nextVideoInput) else {
|
guard session.canAddInput(nextVideoInput) else {
|
||||||
session.commitConfiguration()
|
session.commitConfiguration()
|
||||||
throw NSError(domain: "RecordingCamera", code: 2, userInfo: [NSLocalizedDescriptionKey: "Cannot add camera input"])
|
throw NSError(
|
||||||
|
domain: "RecordingCamera", code: 2,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "Cannot add camera input"])
|
||||||
}
|
}
|
||||||
session.addInput(nextVideoInput)
|
session.addInput(nextVideoInput)
|
||||||
videoInput = nextVideoInput
|
videoInput = nextVideoInput
|
||||||
|
|
||||||
guard session.canAddOutput(movieOutput) else {
|
guard session.canAddOutput(movieOutput) else {
|
||||||
session.commitConfiguration()
|
session.commitConfiguration()
|
||||||
throw NSError(domain: "RecordingCamera", code: 3, userInfo: [NSLocalizedDescriptionKey: "Cannot add movie output"])
|
throw NSError(
|
||||||
|
domain: "RecordingCamera", code: 3,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "Cannot add movie output"])
|
||||||
}
|
}
|
||||||
session.addOutput(movieOutput)
|
session.addOutput(movieOutput)
|
||||||
session.commitConfiguration()
|
session.commitConfiguration()
|
||||||
@@ -516,7 +544,7 @@ private final class RecordingCameraController: NSObject, AVCaptureFileOutputReco
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enum RecordingChannelNames {
|
private enum RecordingChannelNames {
|
||||||
static let packageName = "com.gdfw.fxjk"
|
static let packageName = "com.qxy.dronex"
|
||||||
static let method = "\(packageName)/recording"
|
static let method = "\(packageName)/recording"
|
||||||
static let events = "\(packageName)/recording_events"
|
static let events = "\(packageName)/recording_events"
|
||||||
}
|
}
|
||||||
@@ -584,7 +612,9 @@ final class RecordingPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
|
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink)
|
||||||
|
-> FlutterError?
|
||||||
|
{
|
||||||
eventSink = events
|
eventSink = events
|
||||||
events(controller.currentStatusMap())
|
events(controller.currentStatusMap())
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
||||||
import 'package:recording_tool/app/config/app_config.dart';
|
import 'package:recording_tool/app/config/app_config.dart';
|
||||||
import 'package:recording_tool/app/router/app_navigator.dart';
|
import 'package:recording_tool/app/router/app_navigator.dart';
|
||||||
import 'package:recording_tool/app/theme/app_theme.dart';
|
import 'package:recording_tool/app/theme/app_theme.dart';
|
||||||
import 'package:recording_tool/features/recording/recording_page.dart';
|
import 'package:recording_tool/features/recording/pages/page_record.dart';
|
||||||
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||||
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
||||||
|
|
||||||
class FlutterTemplateApp extends ConsumerStatefulWidget {
|
class FlutterTemplateApp extends ConsumerStatefulWidget {
|
||||||
const FlutterTemplateApp({super.key});
|
const FlutterTemplateApp({super.key});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
@@ -18,12 +20,31 @@ class AppBootstrapper {
|
|||||||
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||||
|
|
||||||
await AppStorage.init();
|
await AppStorage.init();
|
||||||
final packageInfo = await AppPlatformInfo.packageInfo();
|
|
||||||
|
|
||||||
AppConfig.configure(environment: environment, packageInfo: packageInfo);
|
AppConfig.configure(environment: environment);
|
||||||
|
|
||||||
AppLogger.debug('App started in ${AppConfig.current.environment.name}');
|
AppLogger.debug('App started in ${AppConfig.current.environment.name}');
|
||||||
|
|
||||||
runApp(const ProviderScope(child: FlutterTemplateApp()));
|
runApp(const ProviderScope(child: FlutterTemplateApp()));
|
||||||
|
|
||||||
|
// Load native package metadata after the first frame can render.
|
||||||
|
// Awaiting MethodChannel calls before runApp() can stall the Android
|
||||||
|
// splash screen on some devices.
|
||||||
|
unawaited(_loadPackageInfo(environment));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _loadPackageInfo(AppEnvironment environment) async {
|
||||||
|
try {
|
||||||
|
final packageInfo = await AppPlatformInfo.packageInfo().timeout(
|
||||||
|
const Duration(seconds: 8),
|
||||||
|
);
|
||||||
|
AppConfig.configure(environment: environment, packageInfo: packageInfo);
|
||||||
|
} catch (error, stackTrace) {
|
||||||
|
AppLogger.debug(
|
||||||
|
'Native packageInfo unavailable',
|
||||||
|
error: error,
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class AppConfig {
|
|||||||
static late EnvironmentValues current;
|
static late EnvironmentValues current;
|
||||||
static AppPackageInfo? packageInfo;
|
static AppPackageInfo? packageInfo;
|
||||||
|
|
||||||
static const appName = '飞行极控';
|
static const appName = '飞行极控录像工作台';
|
||||||
static const designSize = Size(375, 812);
|
static const designSize = Size(375, 812);
|
||||||
|
|
||||||
static void configure({
|
static void configure({
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
|
||||||
|
|
||||||
class AppPackageInfo {
|
class AppPackageInfo {
|
||||||
const AppPackageInfo({
|
const AppPackageInfo({
|
||||||
@@ -59,7 +60,7 @@ class AppPlatformInfo {
|
|||||||
AppPlatformInfo._();
|
AppPlatformInfo._();
|
||||||
|
|
||||||
static const MethodChannel _channel = MethodChannel(
|
static const MethodChannel _channel = MethodChannel(
|
||||||
'com.gdfw.fxjk/platform_info',
|
'com.qxy.dronex/platform_info',
|
||||||
);
|
);
|
||||||
|
|
||||||
static Future<AppPackageInfo> packageInfo() async {
|
static Future<AppPackageInfo> packageInfo() async {
|
||||||
@@ -75,4 +76,11 @@ class AppPlatformInfo {
|
|||||||
);
|
);
|
||||||
return AppDeviceInfo.fromMap(result ?? const <Object?, Object?>{});
|
return AppDeviceInfo.fromMap(result ?? const <Object?, Object?>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<DeviceHealthSnapshot> deviceHealth() async {
|
||||||
|
final result = await _channel.invokeMapMethod<Object?, Object?>(
|
||||||
|
'deviceHealth',
|
||||||
|
);
|
||||||
|
return DeviceHealthSnapshot.fromMap(result ?? const <Object?, Object?>{});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
lib/core/platform/device_health_checker.dart
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
|
||||||
|
|
||||||
|
class DeviceHealthChecker {
|
||||||
|
DeviceHealthChecker._();
|
||||||
|
|
||||||
|
static const int thresholdPercent = 10;
|
||||||
|
|
||||||
|
static const String lowBatteryMessage = '电量低于10%,请充电';
|
||||||
|
static const String lowStorageMessage = '内存低于10%,请清理内存';
|
||||||
|
|
||||||
|
static List<String> warningLines(DeviceHealthSnapshot snapshot) {
|
||||||
|
final lines = <String>[];
|
||||||
|
|
||||||
|
final battery = snapshot.batteryLevelPercent;
|
||||||
|
if (battery != null && battery < thresholdPercent) {
|
||||||
|
lines.add(lowBatteryMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (snapshot.storageAvailablePercent < thresholdPercent) {
|
||||||
|
lines.add(lowStorageMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
lib/core/platform/device_health_snapshot.dart
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
class DeviceHealthSnapshot {
|
||||||
|
const DeviceHealthSnapshot({
|
||||||
|
this.batteryLevelPercent,
|
||||||
|
required this.storageAvailablePercent,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory DeviceHealthSnapshot.fromMap(Map<Object?, Object?> map) {
|
||||||
|
final batteryRaw = map['batteryLevelPercent'];
|
||||||
|
int? batteryLevelPercent;
|
||||||
|
if (batteryRaw is int) {
|
||||||
|
batteryLevelPercent = batteryRaw;
|
||||||
|
} else if (batteryRaw is num) {
|
||||||
|
batteryLevelPercent = batteryRaw.round();
|
||||||
|
}
|
||||||
|
|
||||||
|
final storageRaw = map['storageAvailablePercent'];
|
||||||
|
final storageAvailablePercent = switch (storageRaw) {
|
||||||
|
final num value => value.toDouble(),
|
||||||
|
_ => 100.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
return DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: batteryLevelPercent,
|
||||||
|
storageAvailablePercent: storageAvailablePercent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final int? batteryLevelPercent;
|
||||||
|
final double storageAvailablePercent;
|
||||||
|
}
|
||||||
281
lib/features/dialog/dialog-record.dart
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
// ignore_for_file: file_names
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:recording_tool/gen/assets.gen.dart';
|
||||||
|
|
||||||
|
/// 录制页统一弹窗,支持单按钮和双按钮。
|
||||||
|
class RecordDialog extends StatelessWidget {
|
||||||
|
const RecordDialog({super.key, required this.title, required this.actions});
|
||||||
|
|
||||||
|
static const _transitionDuration = Duration(milliseconds: 280);
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final List<RecordDialogAction> actions;
|
||||||
|
|
||||||
|
static Future<void> showSingle(
|
||||||
|
BuildContext context, {
|
||||||
|
required String title,
|
||||||
|
required String buttonText,
|
||||||
|
VoidCallback? onPressed,
|
||||||
|
bool barrierDismissible = true,
|
||||||
|
}) {
|
||||||
|
return _present(
|
||||||
|
context,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return RecordDialog(
|
||||||
|
title: title,
|
||||||
|
actions: [
|
||||||
|
RecordDialogAction.primary(
|
||||||
|
text: buttonText,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
onPressed?.call();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> showDouble(
|
||||||
|
BuildContext context, {
|
||||||
|
required String title,
|
||||||
|
required String leftText,
|
||||||
|
required String rightText,
|
||||||
|
VoidCallback? onLeftPressed,
|
||||||
|
VoidCallback? onRightPressed,
|
||||||
|
bool barrierDismissible = false,
|
||||||
|
}) {
|
||||||
|
return _present(
|
||||||
|
context,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return RecordDialog(
|
||||||
|
title: title,
|
||||||
|
actions: [
|
||||||
|
RecordDialogAction.secondary(
|
||||||
|
text: leftText,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
onLeftPressed?.call();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
RecordDialogAction.primary(
|
||||||
|
text: rightText,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
onRightPressed?.call();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> _present(
|
||||||
|
BuildContext context, {
|
||||||
|
required Widget Function(BuildContext dialogContext) builder,
|
||||||
|
required bool barrierDismissible,
|
||||||
|
}) {
|
||||||
|
return showGeneralDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: barrierDismissible,
|
||||||
|
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
|
||||||
|
barrierColor: Colors.black54,
|
||||||
|
transitionDuration: _transitionDuration,
|
||||||
|
pageBuilder: (dialogContext, animation, secondaryAnimation) {
|
||||||
|
return builder(dialogContext);
|
||||||
|
},
|
||||||
|
transitionBuilder: _buildTransition,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildTransition(
|
||||||
|
BuildContext context,
|
||||||
|
Animation<double> animation,
|
||||||
|
Animation<double> secondaryAnimation,
|
||||||
|
Widget child,
|
||||||
|
) {
|
||||||
|
final curved = CurvedAnimation(
|
||||||
|
parent: animation,
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
reverseCurve: Curves.easeInCubic,
|
||||||
|
);
|
||||||
|
|
||||||
|
return FadeTransition(
|
||||||
|
opacity: curved,
|
||||||
|
child: SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 0.08),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(curved),
|
||||||
|
child: ScaleTransition(
|
||||||
|
scale: Tween<double>(begin: 0.92, end: 1).animate(curved),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final actionWidgets = actions
|
||||||
|
.map((action) => Expanded(child: _RecordDialogButton(action: action)))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return Dialog(
|
||||||
|
elevation: 0,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
insetPadding: EdgeInsets.symmetric(horizontal: 37.w),
|
||||||
|
child: ClipRRect(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
|
||||||
|
borderRadius: BorderRadius.circular(18.r),
|
||||||
|
child: Container(
|
||||||
|
width: 315.w,
|
||||||
|
// height: 188.r,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
|
||||||
|
borderRadius: BorderRadius.circular(18.r),
|
||||||
|
),
|
||||||
|
child: Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
top: -88.r,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Image.asset(
|
||||||
|
Assets.images.imageDialogBg.path,
|
||||||
|
width: double.maxFinite,
|
||||||
|
height: 155.h,
|
||||||
|
fit: BoxFit.fitWidth,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(24.w, 44.h, 24.w, 26.h),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
title,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: const Color(0xFF333333),
|
||||||
|
fontSize: 19.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
height: 1.35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 22.h),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
for (
|
||||||
|
var index = 0;
|
||||||
|
index < actionWidgets.length;
|
||||||
|
index++
|
||||||
|
) ...[
|
||||||
|
if (index > 0) SizedBox(width: 16.w),
|
||||||
|
actionWidgets[index],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordDialogAction {
|
||||||
|
const RecordDialogAction._({
|
||||||
|
required this.text,
|
||||||
|
required this.onPressed,
|
||||||
|
required this.isPrimary,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory RecordDialogAction.primary({
|
||||||
|
required String text,
|
||||||
|
required VoidCallback onPressed,
|
||||||
|
}) {
|
||||||
|
return RecordDialogAction._(
|
||||||
|
text: text,
|
||||||
|
onPressed: onPressed,
|
||||||
|
isPrimary: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
factory RecordDialogAction.secondary({
|
||||||
|
required String text,
|
||||||
|
required VoidCallback onPressed,
|
||||||
|
}) {
|
||||||
|
return RecordDialogAction._(
|
||||||
|
text: text,
|
||||||
|
onPressed: onPressed,
|
||||||
|
isPrimary: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final String text;
|
||||||
|
final VoidCallback onPressed;
|
||||||
|
final bool isPrimary;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordDialogButton extends StatelessWidget {
|
||||||
|
const _RecordDialogButton({required this.action});
|
||||||
|
|
||||||
|
final RecordDialogAction action;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final child = Center(
|
||||||
|
child: Text(
|
||||||
|
action.text,
|
||||||
|
style: TextStyle(
|
||||||
|
color: action.isPrimary ? Colors.white : const Color(0xFF333333),
|
||||||
|
fontSize: 18.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
height: 48.h,
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: action.onPressed,
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(24.r),
|
||||||
|
),
|
||||||
|
backgroundColor: action.isPrimary ? null : const Color(0xFFF2F2F2),
|
||||||
|
),
|
||||||
|
child: action.isPrimary
|
||||||
|
? DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
gradient: const LinearGradient(
|
||||||
|
colors: [Color(0xFF2F85FF), Color(0xFF5DCCF4)],
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(24.r),
|
||||||
|
),
|
||||||
|
child: SizedBox.expand(child: child),
|
||||||
|
)
|
||||||
|
: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
/// 小程序复制到剪切板的录制信息。
|
/// 小程序复制到剪切板的录制信息。
|
||||||
class ClipboardRecordingModel {
|
class ClipboardRecordingModel {
|
||||||
final String title;
|
final String title;
|
||||||
final int startTimestamp;
|
int? startTimestamp;
|
||||||
final int endTimestamp;
|
int? endTimestamp;
|
||||||
final String address;
|
final String address;
|
||||||
|
|
||||||
/// 录制文件名模板,如「选手名称_选手ID_赛事名称_赛项」。
|
/// 录制文件名模板,如「选手名称_选手ID_赛事名称_赛项」。
|
||||||
@@ -10,8 +10,8 @@ class ClipboardRecordingModel {
|
|||||||
|
|
||||||
ClipboardRecordingModel({
|
ClipboardRecordingModel({
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.startTimestamp,
|
this.startTimestamp,
|
||||||
required this.endTimestamp,
|
this.endTimestamp,
|
||||||
required this.address,
|
required this.address,
|
||||||
this.filename,
|
this.filename,
|
||||||
});
|
});
|
||||||
@@ -19,8 +19,8 @@ class ClipboardRecordingModel {
|
|||||||
factory ClipboardRecordingModel.fromJson(Map<String, dynamic> json) {
|
factory ClipboardRecordingModel.fromJson(Map<String, dynamic> json) {
|
||||||
return ClipboardRecordingModel(
|
return ClipboardRecordingModel(
|
||||||
title: _readString(json, 'title'),
|
title: _readString(json, 'title'),
|
||||||
startTimestamp: _readInt(json, 'startTimestamp'),
|
startTimestamp: _readOptionalInt(json, 'startTimestamp'),
|
||||||
endTimestamp: _readInt(json, 'endTimestamp'),
|
endTimestamp: _readOptionalInt(json, 'endTimestamp'),
|
||||||
address: _readString(json, 'address'),
|
address: _readString(json, 'address'),
|
||||||
filename: _readOptionalString(json, 'filename'),
|
filename: _readOptionalString(json, 'filename'),
|
||||||
);
|
);
|
||||||
@@ -52,8 +52,9 @@ class ClipboardRecordingModel {
|
|||||||
throw FormatException('Clipboard field "$key" must be a String.');
|
throw FormatException('Clipboard field "$key" must be a String.');
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _readInt(Map<String, dynamic> json, String key) {
|
static int? _readOptionalInt(Map<String, dynamic> json, String key) {
|
||||||
final value = json[key];
|
final value = json[key];
|
||||||
|
if (value == null) return null;
|
||||||
if (value is int) return value;
|
if (value is int) return value;
|
||||||
throw FormatException('Clipboard field "$key" must be an int.');
|
throw FormatException('Clipboard field "$key" must be an int.');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:recording_tool/features/recording/model/model_clipboard.dart';
|
import 'package:recording_tool/features/recording/model/model_clipboard.dart';
|
||||||
|
import 'package:recording_tool/features/recording/model/model_recording_session.dart';
|
||||||
|
|
||||||
class RecordingModel {
|
class RecordingModel {
|
||||||
/// 剪切板内容
|
/// 剪切板内容
|
||||||
@@ -7,11 +8,17 @@ class RecordingModel {
|
|||||||
/// 剪切板是否包含有效的小程序录制信息
|
/// 剪切板是否包含有效的小程序录制信息
|
||||||
final bool hasValidClipboardInfo;
|
final bool hasValidClipboardInfo;
|
||||||
|
|
||||||
|
/// 录制会话状态
|
||||||
|
final RecordingSessionState session;
|
||||||
|
|
||||||
RecordingModel({
|
RecordingModel({
|
||||||
required this.clipboardRecordingModel,
|
required this.clipboardRecordingModel,
|
||||||
this.hasValidClipboardInfo = false,
|
this.hasValidClipboardInfo = false,
|
||||||
|
this.session = const RecordingSessionState(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bool get isRecording => session.isRecording;
|
||||||
|
|
||||||
factory RecordingModel.fromJson(Map<String, dynamic> json) {
|
factory RecordingModel.fromJson(Map<String, dynamic> json) {
|
||||||
return RecordingModel(
|
return RecordingModel(
|
||||||
clipboardRecordingModel: ClipboardRecordingModel.fromJson(
|
clipboardRecordingModel: ClipboardRecordingModel.fromJson(
|
||||||
@@ -23,15 +30,23 @@ class RecordingModel {
|
|||||||
return {'clipboardRecordingModel': clipboardRecordingModel.toJson()};
|
return {'clipboardRecordingModel': clipboardRecordingModel.toJson()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 剪切板是否包含可用于命名的 [ClipboardRecordingModel.filename]。
|
||||||
|
bool get hasClipboardFilename {
|
||||||
|
final name = clipboardRecordingModel.filename?.trim();
|
||||||
|
return hasValidClipboardInfo && name != null && name.isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
RecordingModel copyWith({
|
RecordingModel copyWith({
|
||||||
ClipboardRecordingModel? clipboardRecordingModel,
|
ClipboardRecordingModel? clipboardRecordingModel,
|
||||||
bool? hasValidClipboardInfo,
|
bool? hasValidClipboardInfo,
|
||||||
|
RecordingSessionState? session,
|
||||||
}) {
|
}) {
|
||||||
return RecordingModel(
|
return RecordingModel(
|
||||||
clipboardRecordingModel:
|
clipboardRecordingModel:
|
||||||
clipboardRecordingModel ?? this.clipboardRecordingModel,
|
clipboardRecordingModel ?? this.clipboardRecordingModel,
|
||||||
hasValidClipboardInfo:
|
hasValidClipboardInfo:
|
||||||
hasValidClipboardInfo ?? this.hasValidClipboardInfo,
|
hasValidClipboardInfo ?? this.hasValidClipboardInfo,
|
||||||
|
session: session ?? this.session,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
83
lib/features/recording/model/model_recording_session.dart
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||||
|
|
||||||
|
/// 录制会话状态(相机预览、权限、录制进度等)。
|
||||||
|
class RecordingSessionState {
|
||||||
|
const RecordingSessionState({
|
||||||
|
this.status = const RecordingStatus(state: RecordingState.idle),
|
||||||
|
this.isTouchLocked = true,
|
||||||
|
this.isPreviewReady = false,
|
||||||
|
this.isStartingRecording = false,
|
||||||
|
this.hasDndAccess = false,
|
||||||
|
this.isBatteryOptimizedIgnored = true,
|
||||||
|
this.notificationsGranted = true,
|
||||||
|
this.isMicrophoneGranted = false,
|
||||||
|
this.lastOutputPath,
|
||||||
|
this.lastSavedDisplayName,
|
||||||
|
this.errorMessage,
|
||||||
|
this.permissionWarning,
|
||||||
|
this.gallerySaveFailed = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final RecordingStatus status;
|
||||||
|
final bool isTouchLocked;
|
||||||
|
final bool isPreviewReady;
|
||||||
|
final bool isStartingRecording;
|
||||||
|
final bool hasDndAccess;
|
||||||
|
final bool isBatteryOptimizedIgnored;
|
||||||
|
final bool notificationsGranted;
|
||||||
|
final bool isMicrophoneGranted;
|
||||||
|
final String? lastOutputPath;
|
||||||
|
final String? lastSavedDisplayName;
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? permissionWarning;
|
||||||
|
final bool gallerySaveFailed;
|
||||||
|
|
||||||
|
bool get isRecording => status.isRecording;
|
||||||
|
|
||||||
|
String get elapsedLabel {
|
||||||
|
final totalSeconds = status.elapsedMillis ~/ 1000;
|
||||||
|
final hours = (totalSeconds ~/ 3600).toString().padLeft(2, '0');
|
||||||
|
final minutes = ((totalSeconds % 3600) ~/ 60).toString().padLeft(2, '0');
|
||||||
|
final seconds = (totalSeconds % 60).toString().padLeft(2, '0');
|
||||||
|
return '$hours:$minutes:$seconds';
|
||||||
|
}
|
||||||
|
|
||||||
|
RecordingSessionState copyWith({
|
||||||
|
RecordingStatus? status,
|
||||||
|
bool? isTouchLocked,
|
||||||
|
bool? isPreviewReady,
|
||||||
|
bool? isStartingRecording,
|
||||||
|
bool? hasDndAccess,
|
||||||
|
bool? isBatteryOptimizedIgnored,
|
||||||
|
bool? notificationsGranted,
|
||||||
|
bool? isMicrophoneGranted,
|
||||||
|
String? lastOutputPath,
|
||||||
|
String? lastSavedDisplayName,
|
||||||
|
String? errorMessage,
|
||||||
|
String? permissionWarning,
|
||||||
|
bool? gallerySaveFailed,
|
||||||
|
bool clearPermissionWarning = false,
|
||||||
|
bool clearLastSaved = false,
|
||||||
|
}) {
|
||||||
|
return RecordingSessionState(
|
||||||
|
status: status ?? this.status,
|
||||||
|
isTouchLocked: isTouchLocked ?? this.isTouchLocked,
|
||||||
|
isPreviewReady: isPreviewReady ?? this.isPreviewReady,
|
||||||
|
isStartingRecording: isStartingRecording ?? this.isStartingRecording,
|
||||||
|
hasDndAccess: hasDndAccess ?? this.hasDndAccess,
|
||||||
|
isBatteryOptimizedIgnored:
|
||||||
|
isBatteryOptimizedIgnored ?? this.isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted: notificationsGranted ?? this.notificationsGranted,
|
||||||
|
isMicrophoneGranted: isMicrophoneGranted ?? this.isMicrophoneGranted,
|
||||||
|
lastOutputPath: lastOutputPath ?? this.lastOutputPath,
|
||||||
|
lastSavedDisplayName: clearLastSaved
|
||||||
|
? null
|
||||||
|
: (lastSavedDisplayName ?? this.lastSavedDisplayName),
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
permissionWarning: clearPermissionWarning
|
||||||
|
? null
|
||||||
|
: (permissionWarning ?? this.permissionWarning),
|
||||||
|
gallerySaveFailed: gallerySaveFailed ?? this.gallerySaveFailed,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
479
lib/features/recording/pages/page_record.dart
Normal file
@@ -0,0 +1,479 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:recording_tool/core/platform/app_platform_info.dart';
|
||||||
|
import 'package:recording_tool/core/platform/device_health_checker.dart';
|
||||||
|
import 'package:recording_tool/features/dialog/dialog-record.dart';
|
||||||
|
import 'package:recording_tool/features/recording/model/model_recording.dart';
|
||||||
|
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||||
|
import 'package:recording_tool/features/recording/utils/recording_display_name.dart';
|
||||||
|
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_camera_preview.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_footer.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_header.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_timer.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_hud.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_loading_overlay.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_saved_dialog.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_touch_lock_overlay.dart';
|
||||||
|
import 'package:recording_tool/shared/widgets/widgets.dart';
|
||||||
|
|
||||||
|
/// 录制页入口
|
||||||
|
class RecordingPage extends ConsumerStatefulWidget {
|
||||||
|
const RecordingPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 创建页面状态
|
||||||
|
ConsumerState<RecordingPage> createState() => _RecordingPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingPageState extends ConsumerState<RecordingPage> {
|
||||||
|
var _immersiveApplied = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 首帧后初始化录制流程
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => _bootstrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 检查设备健康状态并弹窗提示
|
||||||
|
Future<void> _checkAndShowDeviceHealthAlerts() async {
|
||||||
|
final snapshot = await AppPlatformInfo.deviceHealth();
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
final lines = DeviceHealthChecker.warningLines(snapshot);
|
||||||
|
if (lines.isEmpty) return;
|
||||||
|
|
||||||
|
await RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: lines.join('\n'),
|
||||||
|
buttonText: '确定',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 页面启动:健康检查、读剪贴板、进入录制模式、准备相机会话
|
||||||
|
Future<void> _bootstrap() async {
|
||||||
|
await _checkAndShowDeviceHealthAlerts();
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
|
final clipboardResult = await ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.getClipboardContent();
|
||||||
|
if (!mounted) return;
|
||||||
|
if (clipboardResult == ClipboardReadResult.invalid) {
|
||||||
|
AppToast.show('无选手信息');
|
||||||
|
}
|
||||||
|
await _enterRecordingMode();
|
||||||
|
// Allow PlatformView to attach before binding CameraX preview.
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 400));
|
||||||
|
if (!mounted) return;
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).prepareSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Android 进入沉浸式全屏
|
||||||
|
Future<void> _enterRecordingMode() async {
|
||||||
|
if (!Platform.isAndroid) return;
|
||||||
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||||
|
await RecordingPlatform.setImmersiveMode(enabled: true);
|
||||||
|
_immersiveApplied = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 解析保存成功弹窗的标题文案
|
||||||
|
String _savedDialogSessionTitle(
|
||||||
|
RecordingModel recordingInfo,
|
||||||
|
String? savedName,
|
||||||
|
) {
|
||||||
|
final clipboard = recordingInfo.clipboardRecordingModel;
|
||||||
|
if (recordingInfo.hasValidClipboardInfo &&
|
||||||
|
clipboard.title.trim().isNotEmpty) {
|
||||||
|
return clipboard.title.trim();
|
||||||
|
}
|
||||||
|
if (savedName != null && savedName.isNotEmpty) {
|
||||||
|
return resolveRecordingDisplayName(savedName);
|
||||||
|
}
|
||||||
|
return '录制完成';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 从剪贴板粘贴赛事信息(与 header「粘贴选手信息」一致)。
|
||||||
|
Future<void> _pasteEventInfo() async {
|
||||||
|
final result = await ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.getClipboardContent();
|
||||||
|
if (!mounted) return;
|
||||||
|
if (result != ClipboardReadResult.success) {
|
||||||
|
AppToast.show('无选手信息');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 无选手信息时弹窗提示
|
||||||
|
Future<void> _showNoPlayerInfoDialog() {
|
||||||
|
return RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: '无选手信息!',
|
||||||
|
buttonText: '粘贴',
|
||||||
|
onPressed: _pasteEventInfo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 根据缺失权限生成弹窗文案。
|
||||||
|
String _recordingPermissionDialogTitle(RecordingRequiredPermissions result) {
|
||||||
|
if (!result.cameraGranted && !result.microphoneGranted) {
|
||||||
|
return '录制需要开启相机和录音权限,请在系统设置中授权后重试';
|
||||||
|
}
|
||||||
|
if (!result.cameraGranted) {
|
||||||
|
return '录制需要开启相机权限,请在系统设置中授权后重试';
|
||||||
|
}
|
||||||
|
return '录制需要开启录音权限,请在系统设置中授权后重试';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 开始录制前检测相机、录音权限,未授予则弹窗并跳转系统设置。
|
||||||
|
Future<bool> _ensureRecordingPermissions() async {
|
||||||
|
final result = await ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.ensureCameraAndMicrophonePermissions();
|
||||||
|
if (result.allGranted) {
|
||||||
|
final ready = ref.read(recordingViewModelProvider).session.isPreviewReady;
|
||||||
|
if (ready) return true;
|
||||||
|
if (!mounted) return false;
|
||||||
|
AppToast.show('相机预览启动失败,请重试');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!mounted) return false;
|
||||||
|
|
||||||
|
await RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: _recordingPermissionDialogTitle(result),
|
||||||
|
buttonText: '确定',
|
||||||
|
onPressed: openAppSettings,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 点击开始录制:校验剪贴板、权限与健康状态
|
||||||
|
Future<void> _onStartRecording() async {
|
||||||
|
final recordingInfo = ref.read(recordingViewModelProvider);
|
||||||
|
if (!recordingInfo.hasClipboardFilename) {
|
||||||
|
await _showNoPlayerInfoDialog();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!await _ensureRecordingPermissions()) return;
|
||||||
|
if (!mounted) return;
|
||||||
|
await _checkAndShowDeviceHealthAlerts();
|
||||||
|
if (!mounted) return;
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).startRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止录制并按结果显示保存提示。
|
||||||
|
Future<void> _stopRecordingAndShowResult() async {
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).stopRecording();
|
||||||
|
if (!mounted) return;
|
||||||
|
final latest = ref.read(recordingViewModelProvider).session;
|
||||||
|
if (latest.gallerySaveFailed) {
|
||||||
|
AppToast.show(latest.errorMessage ?? '保存到相册失败,请开启相册权限');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await _showRecordingSavedDialogIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 清空剪贴板信息,准备新一轮录制
|
||||||
|
void _clearClipboardForNewRound() {
|
||||||
|
final notifier = ref.read(recordingViewModelProvider.notifier);
|
||||||
|
notifier.resetClipboardInfo();
|
||||||
|
notifier.clearSavedRecordingResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 保存成功后按需弹出完成对话框
|
||||||
|
Future<void> _showRecordingSavedDialogIfNeeded() async {
|
||||||
|
final recordingInfo = ref.read(recordingViewModelProvider);
|
||||||
|
final session = recordingInfo.session;
|
||||||
|
if (session.lastSavedDisplayName == null || session.gallerySaveFailed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final sessionTitle = _savedDialogSessionTitle(
|
||||||
|
recordingInfo,
|
||||||
|
session.lastSavedDisplayName,
|
||||||
|
);
|
||||||
|
|
||||||
|
await showRecordingSavedDialog(
|
||||||
|
context,
|
||||||
|
sessionTitle: sessionTitle,
|
||||||
|
onContinueRound: () {
|
||||||
|
ref
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.clearSavedRecordingResult();
|
||||||
|
},
|
||||||
|
onRecordNewRound: _clearClipboardForNewRound,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 退出沉浸式并释放录制会话
|
||||||
|
Future<void> _exitRecordingMode() async {
|
||||||
|
if (!_immersiveApplied) return;
|
||||||
|
await ref.read(recordingViewModelProvider.notifier).teardown();
|
||||||
|
await SystemChrome.setEnabledSystemUIMode(
|
||||||
|
SystemUiMode.manual,
|
||||||
|
overlays: SystemUiOverlay.values,
|
||||||
|
);
|
||||||
|
await RecordingPlatform.setImmersiveMode(enabled: false);
|
||||||
|
_immersiveApplied = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 页面销毁时恢复系统 UI
|
||||||
|
void dispose() {
|
||||||
|
if (_immersiveApplied) {
|
||||||
|
SystemChrome.setEnabledSystemUIMode(
|
||||||
|
SystemUiMode.manual,
|
||||||
|
overlays: SystemUiOverlay.values,
|
||||||
|
);
|
||||||
|
RecordingPlatform.setImmersiveMode(enabled: false);
|
||||||
|
}
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 构建录制页 UI
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return _RecordingPopScope(
|
||||||
|
onExitRecordingMode: _exitRecordingMode,
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
_RecordHeaderSection(
|
||||||
|
onPasteEventInfo: _pasteEventInfo,
|
||||||
|
onClearEventInfo: _clearClipboardForNewRound,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
const CameraPreviewWidget(),
|
||||||
|
const _PreviewLoadingLayer(),
|
||||||
|
const RecordTimerWidget(),
|
||||||
|
_RecordingHudLayer(
|
||||||
|
onStart: _onStartRecording,
|
||||||
|
onStop: _stopRecordingAndShowResult,
|
||||||
|
),
|
||||||
|
_TouchLockOverlayLayer(
|
||||||
|
onStopRecording: _stopRecordingAndShowResult,
|
||||||
|
),
|
||||||
|
const _StartingRecordingOverlay(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const RecordFooter(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingPopScope extends ConsumerWidget {
|
||||||
|
const _RecordingPopScope({
|
||||||
|
required this.onExitRecordingMode,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Future<void> Function() onExitRecordingMode;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final isRecording = ref.watch(
|
||||||
|
recordingViewModelProvider.select((m) => m.session.isRecording),
|
||||||
|
);
|
||||||
|
|
||||||
|
return PopScope(
|
||||||
|
canPop: !isRecording,
|
||||||
|
onPopInvokedWithResult: (didPop, result) async {
|
||||||
|
if (didPop) {
|
||||||
|
await onExitRecordingMode();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isRecording) {
|
||||||
|
AppToast.show('录制中无法返回,请先停止录制');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordHeaderSection extends ConsumerWidget {
|
||||||
|
const _RecordHeaderSection({
|
||||||
|
required this.onPasteEventInfo,
|
||||||
|
required this.onClearEventInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Future<void> Function() onPasteEventInfo;
|
||||||
|
final VoidCallback onClearEventInfo;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final headerState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (
|
||||||
|
m.hasValidClipboardInfo,
|
||||||
|
m.hasValidClipboardInfo ? m.clipboardRecordingModel.title : null,
|
||||||
|
m.session.isRecording,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (hasValidClipboardInfo, eventTitle, isRecording) = headerState;
|
||||||
|
|
||||||
|
return RecordHeaderWidget(
|
||||||
|
hasValidClipboardInfo: hasValidClipboardInfo,
|
||||||
|
eventTitle: eventTitle,
|
||||||
|
isRecording: isRecording,
|
||||||
|
onPasteEventInfo: onPasteEventInfo,
|
||||||
|
onClearEventInfo: onClearEventInfo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PreviewLoadingLayer extends ConsumerWidget {
|
||||||
|
const _PreviewLoadingLayer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final showLoading = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => !m.session.isPreviewReady && m.session.errorMessage == null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!showLoading) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return const RecordingLoadingOverlayWidget(message: '正在启动相机…');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingHudLayer extends ConsumerWidget {
|
||||||
|
const _RecordingHudLayer({
|
||||||
|
required this.onStart,
|
||||||
|
required this.onStop,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Future<void> Function() onStart;
|
||||||
|
final Future<void> Function() onStop;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final hudState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (
|
||||||
|
m.session.errorMessage,
|
||||||
|
m.session.permissionWarning,
|
||||||
|
m.session.hasDndAccess,
|
||||||
|
m.session.isBatteryOptimizedIgnored,
|
||||||
|
m.session.notificationsGranted,
|
||||||
|
m.session.isRecording,
|
||||||
|
m.session.isStartingRecording,
|
||||||
|
m.session.isTouchLocked,
|
||||||
|
m.hasValidClipboardInfo,
|
||||||
|
m.clipboardRecordingModel.address.trim(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (
|
||||||
|
errorMessage,
|
||||||
|
permissionWarning,
|
||||||
|
hasDndAccess,
|
||||||
|
isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted,
|
||||||
|
isRecording,
|
||||||
|
isStartingRecording,
|
||||||
|
isTouchLocked,
|
||||||
|
showClipboardHint,
|
||||||
|
clipboardAddress,
|
||||||
|
) = hudState;
|
||||||
|
final viewModel = ref.read(recordingViewModelProvider.notifier);
|
||||||
|
|
||||||
|
return RecordingHudWidget(
|
||||||
|
errorMessage: errorMessage,
|
||||||
|
permissionWarning: permissionWarning,
|
||||||
|
hasDndAccess: hasDndAccess,
|
||||||
|
isBatteryOptimizedIgnored: isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted: notificationsGranted,
|
||||||
|
isRecording: isRecording,
|
||||||
|
isStartingRecording: isStartingRecording,
|
||||||
|
isTouchLocked: isTouchLocked,
|
||||||
|
showClipboardHint: showClipboardHint,
|
||||||
|
clipboardAddress: clipboardAddress,
|
||||||
|
onStart: onStart,
|
||||||
|
onStop: onStop,
|
||||||
|
onOpenDnd: () async {
|
||||||
|
await viewModel.openDndSettings();
|
||||||
|
await viewModel.refreshDndAccess();
|
||||||
|
},
|
||||||
|
onOpenBattery: () async {
|
||||||
|
await viewModel.openBatterySettings();
|
||||||
|
await viewModel.refreshBatteryOptimization();
|
||||||
|
},
|
||||||
|
onToggleTouchLock: () {
|
||||||
|
final locked = ref.read(recordingViewModelProvider).session.isTouchLocked;
|
||||||
|
viewModel.setTouchLocked(!locked);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TouchLockOverlayLayer extends ConsumerWidget {
|
||||||
|
const _TouchLockOverlayLayer({required this.onStopRecording});
|
||||||
|
|
||||||
|
final Future<void> Function() onStopRecording;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final overlayState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (m.session.isTouchLocked, m.session.isRecording),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (isTouchLocked, isRecording) = overlayState;
|
||||||
|
|
||||||
|
if (!isTouchLocked || !isRecording) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
final viewModel = ref.read(recordingViewModelProvider.notifier);
|
||||||
|
|
||||||
|
return RecordingTouchLockOverlayWidget(
|
||||||
|
enabled: true,
|
||||||
|
onUnlocked: (intent) async {
|
||||||
|
viewModel.setTouchLocked(false);
|
||||||
|
if (intent == RecordingTouchLockUnlockIntent.stopRecording) {
|
||||||
|
await onStopRecording();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StartingRecordingOverlay extends ConsumerWidget {
|
||||||
|
const _StartingRecordingOverlay();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final isStartingRecording = ref.watch(
|
||||||
|
recordingViewModelProvider.select((m) => m.session.isStartingRecording),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isStartingRecording) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return RecordingLoadingOverlayWidget(
|
||||||
|
message: '正在开始录制…',
|
||||||
|
backgroundColor: Colors.black.withValues(alpha: 0.24),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
abstract final class RecordingChannelNames {
|
abstract final class RecordingChannelNames {
|
||||||
static const packageName = 'com.gdfw.fxjk';
|
static const packageName = 'com.qxy.dronex';
|
||||||
static const method = '$packageName/recording';
|
static const method = '$packageName/recording';
|
||||||
static const events = '$packageName/recording_events';
|
static const events = '$packageName/recording_events';
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import 'dart:async';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:recording_tool/features/recording/recording_channel_names.dart';
|
import 'package:recording_tool/features/recording/platform/recording_channel_names.dart';
|
||||||
|
|
||||||
enum RecordingState {
|
enum RecordingState {
|
||||||
idle,
|
idle,
|
||||||
@@ -1,463 +0,0 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
|
||||||
import 'package:recording_tool/features/recording/recording_platform.dart';
|
|
||||||
import 'package:recording_tool/features/recording/recording_session_controller.dart';
|
|
||||||
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
|
||||||
import 'package:recording_tool/features/recording/widgets/camera_preview_widget.dart';
|
|
||||||
import 'package:recording_tool/features/recording/widgets/recording_touch_lock_overlay.dart';
|
|
||||||
import 'package:recording_tool/shared/widgets/widgets.dart';
|
|
||||||
|
|
||||||
class RecordingPage extends ConsumerStatefulWidget {
|
|
||||||
const RecordingPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
ConsumerState<RecordingPage> createState() => _RecordingPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _RecordingPageState extends ConsumerState<RecordingPage> {
|
|
||||||
var _immersiveApplied = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _bootstrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _bootstrap() async {
|
|
||||||
final clipboardResult = await ref
|
|
||||||
.read(recordingViewModelProvider.notifier)
|
|
||||||
.getClipboardContent();
|
|
||||||
if (!mounted) return;
|
|
||||||
if (clipboardResult == ClipboardReadResult.invalid) {
|
|
||||||
AppToast.show('无选手信息');
|
|
||||||
}
|
|
||||||
await _enterRecordingMode();
|
|
||||||
// Allow PlatformView to attach before binding CameraX preview.
|
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 400));
|
|
||||||
if (!mounted) return;
|
|
||||||
await ref
|
|
||||||
.read(recordingSessionControllerProvider.notifier)
|
|
||||||
.prepareSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _enterRecordingMode() async {
|
|
||||||
if (!Platform.isAndroid) return;
|
|
||||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
|
||||||
await RecordingPlatform.setImmersiveMode(enabled: true);
|
|
||||||
_immersiveApplied = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _exitRecordingMode() async {
|
|
||||||
if (!_immersiveApplied) return;
|
|
||||||
await ref.read(recordingSessionControllerProvider.notifier).teardown();
|
|
||||||
await SystemChrome.setEnabledSystemUIMode(
|
|
||||||
SystemUiMode.manual,
|
|
||||||
overlays: SystemUiOverlay.values,
|
|
||||||
);
|
|
||||||
await RecordingPlatform.setImmersiveMode(enabled: false);
|
|
||||||
_immersiveApplied = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
if (_immersiveApplied) {
|
|
||||||
SystemChrome.setEnabledSystemUIMode(
|
|
||||||
SystemUiMode.manual,
|
|
||||||
overlays: SystemUiOverlay.values,
|
|
||||||
);
|
|
||||||
RecordingPlatform.setImmersiveMode(enabled: false);
|
|
||||||
}
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final state = ref.watch(recordingSessionControllerProvider);
|
|
||||||
final recordingInfo = ref.watch(recordingViewModelProvider);
|
|
||||||
final controller = ref.read(recordingSessionControllerProvider.notifier);
|
|
||||||
final clipboard = recordingInfo.clipboardRecordingModel;
|
|
||||||
final showClipboardInfo = recordingInfo.hasValidClipboardInfo;
|
|
||||||
|
|
||||||
return PopScope(
|
|
||||||
canPop: !state.isRecording,
|
|
||||||
onPopInvokedWithResult: (didPop, result) async {
|
|
||||||
if (didPop) {
|
|
||||||
await _exitRecordingMode();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (state.isRecording) {
|
|
||||||
AppToast.show('录制中无法返回,请先停止录制');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
|
||||||
backgroundColor: Colors.black,
|
|
||||||
body: Stack(
|
|
||||||
fit: StackFit.expand,
|
|
||||||
children: [
|
|
||||||
const CameraPreviewWidget(),
|
|
||||||
if (state.isTouchLocked && state.isRecording)
|
|
||||||
RecordingTouchLockOverlay(
|
|
||||||
enabled: true,
|
|
||||||
onUnlocked: () => controller.setTouchLocked(false),
|
|
||||||
),
|
|
||||||
_RecordingHud(
|
|
||||||
state: state,
|
|
||||||
eventTitle: showClipboardInfo ? clipboard.title : null,
|
|
||||||
eventAddress: showClipboardInfo ? clipboard.address : null,
|
|
||||||
onPasteEventInfo: () async {
|
|
||||||
final result = await ref
|
|
||||||
.read(recordingViewModelProvider.notifier)
|
|
||||||
.getClipboardContent();
|
|
||||||
if (!context.mounted) return;
|
|
||||||
if (result != ClipboardReadResult.success) {
|
|
||||||
AppToast.show('无赛事信息');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onStart: () => controller.startRecording(),
|
|
||||||
onStop: () async {
|
|
||||||
await controller.stopRecording();
|
|
||||||
if (!context.mounted) return;
|
|
||||||
final latest = ref.read(recordingSessionControllerProvider);
|
|
||||||
if (latest.gallerySaveFailed) {
|
|
||||||
AppToast.show(latest.errorMessage ?? '保存到相册失败,请开启相册权限');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onOpenDnd: () async {
|
|
||||||
await controller.openDndSettings();
|
|
||||||
await controller.refreshDndAccess();
|
|
||||||
},
|
|
||||||
onOpenBattery: () async {
|
|
||||||
await controller.openBatterySettings();
|
|
||||||
await controller.refreshBatteryOptimization();
|
|
||||||
},
|
|
||||||
onToggleTouchLock: () {
|
|
||||||
controller.setTouchLocked(!state.isTouchLocked);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _RecordingHud extends StatelessWidget {
|
|
||||||
const _RecordingHud({
|
|
||||||
required this.state,
|
|
||||||
this.eventTitle,
|
|
||||||
this.eventAddress,
|
|
||||||
required this.onPasteEventInfo,
|
|
||||||
required this.onStart,
|
|
||||||
required this.onStop,
|
|
||||||
required this.onOpenDnd,
|
|
||||||
required this.onOpenBattery,
|
|
||||||
required this.onToggleTouchLock,
|
|
||||||
});
|
|
||||||
|
|
||||||
final RecordingSessionState state;
|
|
||||||
final String? eventTitle;
|
|
||||||
final String? eventAddress;
|
|
||||||
final Future<void> Function() onPasteEventInfo;
|
|
||||||
final VoidCallback onStart;
|
|
||||||
final VoidCallback onStop;
|
|
||||||
final VoidCallback onOpenDnd;
|
|
||||||
final VoidCallback onOpenBattery;
|
|
||||||
final VoidCallback onToggleTouchLock;
|
|
||||||
|
|
||||||
static TextStyle get _overlayTextStyle => TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
shadows: [Shadow(color: Colors.black54, blurRadius: 6.r)],
|
|
||||||
);
|
|
||||||
|
|
||||||
static double get _controlSlotWidth => 48.r;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final showPasteEventInfo = eventTitle == null && !state.isRecording;
|
|
||||||
|
|
||||||
return SafeArea(
|
|
||||||
child: Stack(
|
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
height:
|
|
||||||
eventTitle != null ||
|
|
||||||
state.isRecording ||
|
|
||||||
showPasteEventInfo
|
|
||||||
? 56.h
|
|
||||||
: 8.h,
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
if (state.errorMessage != null)
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.all(12.r),
|
|
||||||
child: Text(
|
|
||||||
state.errorMessage!,
|
|
||||||
style: const TextStyle(color: Colors.amber),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (state.permissionWarning != null)
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.symmetric(
|
|
||||||
horizontal: 16.r,
|
|
||||||
vertical: 8.r,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
state.permissionWarning!,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.orangeAccent,
|
|
||||||
fontSize: 12.sp,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
_SetupHints(
|
|
||||||
hasDndAccess: state.hasDndAccess,
|
|
||||||
isBatteryIgnored: state.isBatteryOptimizedIgnored,
|
|
||||||
notificationsGranted: state.notificationsGranted,
|
|
||||||
onOpenDnd: onOpenDnd,
|
|
||||||
onOpenBattery: onOpenBattery,
|
|
||||||
onOpenNotificationSettings: openAppSettings,
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.fromLTRB(24.r, 8.r, 24.r, 24.r),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: _controlSlotWidth,
|
|
||||||
height: _controlSlotWidth,
|
|
||||||
child: state.isRecording
|
|
||||||
? IconButton(
|
|
||||||
onPressed: onToggleTouchLock,
|
|
||||||
icon: Icon(
|
|
||||||
state.isTouchLocked
|
|
||||||
? Icons.lock
|
|
||||||
: Icons.lock_open,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 28.r,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: GestureDetector(
|
|
||||||
onTap: state.isRecording ? onStop : onStart,
|
|
||||||
child: Container(
|
|
||||||
width: 76.w,
|
|
||||||
height: 76.h,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
border: Border.all(color: Colors.white, width: 4.r),
|
|
||||||
color: state.isRecording
|
|
||||||
? Colors.white
|
|
||||||
: Colors.red,
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
state.isRecording
|
|
||||||
? Icons.stop
|
|
||||||
: Icons.fiber_manual_record,
|
|
||||||
color: state.isRecording
|
|
||||||
? Colors.red
|
|
||||||
: Colors.white,
|
|
||||||
size: 36.r,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: _controlSlotWidth,
|
|
||||||
height: _controlSlotWidth,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (state.lastSavedDisplayName != null &&
|
|
||||||
!state.isRecording &&
|
|
||||||
!state.gallerySaveFailed)
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.only(bottom: 16.r),
|
|
||||||
child: Text(
|
|
||||||
'已保存到相册:${state.lastSavedDisplayName}',
|
|
||||||
style: TextStyle(color: Colors.white70, fontSize: 12.sp),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (showPasteEventInfo)
|
|
||||||
Positioned(
|
|
||||||
top: 8.r,
|
|
||||||
left: 12.w,
|
|
||||||
right: 12.w,
|
|
||||||
child: Center(
|
|
||||||
child: TextButton.icon(
|
|
||||||
onPressed: onPasteEventInfo,
|
|
||||||
icon: Icon(Icons.content_paste, size: 18.r),
|
|
||||||
label: const Text('粘贴赛事信息'),
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
foregroundColor: Colors.white,
|
|
||||||
backgroundColor: Colors.black.withValues(alpha: 0.5),
|
|
||||||
padding: EdgeInsets.symmetric(
|
|
||||||
horizontal: 14.r,
|
|
||||||
vertical: 8.r,
|
|
||||||
),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(20.r),
|
|
||||||
side: const BorderSide(color: Colors.white30),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (eventTitle != null)
|
|
||||||
Positioned(
|
|
||||||
top: 8.r,
|
|
||||||
left: 12.w,
|
|
||||||
right: 12.w,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
right: state.isRecording ? 96.w : 0,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
eventTitle!,
|
|
||||||
style: _overlayTextStyle.copyWith(
|
|
||||||
fontSize: 16.sp,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (state.isRecording)
|
|
||||||
Positioned(
|
|
||||||
top: 8.r,
|
|
||||||
right: 12.w,
|
|
||||||
child: Container(
|
|
||||||
padding: EdgeInsets.symmetric(
|
|
||||||
horizontal: 12.r,
|
|
||||||
vertical: 6.r,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.red,
|
|
||||||
borderRadius: BorderRadius.circular(20.r),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
'REC ${state.elapsedLabel}',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (eventAddress != null && eventAddress!.isNotEmpty)
|
|
||||||
Positioned(
|
|
||||||
left: 16.w,
|
|
||||||
bottom: 108.r,
|
|
||||||
right: 120.w,
|
|
||||||
child: Text(
|
|
||||||
eventAddress!,
|
|
||||||
style: _overlayTextStyle.copyWith(
|
|
||||||
fontSize: 13.sp,
|
|
||||||
color: Colors.white70,
|
|
||||||
),
|
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SetupHints extends StatelessWidget {
|
|
||||||
const _SetupHints({
|
|
||||||
required this.hasDndAccess,
|
|
||||||
required this.isBatteryIgnored,
|
|
||||||
required this.notificationsGranted,
|
|
||||||
required this.onOpenDnd,
|
|
||||||
required this.onOpenBattery,
|
|
||||||
required this.onOpenNotificationSettings,
|
|
||||||
});
|
|
||||||
|
|
||||||
final bool hasDndAccess;
|
|
||||||
final bool isBatteryIgnored;
|
|
||||||
final bool notificationsGranted;
|
|
||||||
final VoidCallback onOpenDnd;
|
|
||||||
final VoidCallback onOpenBattery;
|
|
||||||
final VoidCallback onOpenNotificationSettings;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if (hasDndAccess && isBatteryIgnored && notificationsGranted) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16.r, vertical: 8.r),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
if (!notificationsGranted) ...[
|
|
||||||
_HintChip(
|
|
||||||
label: '开启通知权限以显示录制前台服务',
|
|
||||||
onTap: onOpenNotificationSettings,
|
|
||||||
),
|
|
||||||
SizedBox(height: 8.h),
|
|
||||||
],
|
|
||||||
if (!hasDndAccess)
|
|
||||||
_HintChip(label: '开启勿扰权限可减少录制中断', onTap: onOpenDnd),
|
|
||||||
if (!isBatteryIgnored) ...[
|
|
||||||
SizedBox(height: 8.h),
|
|
||||||
_HintChip(label: '关闭电池优化可提升息屏续录稳定性', onTap: onOpenBattery),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _HintChip extends StatelessWidget {
|
|
||||||
const _HintChip({required this.label, required this.onTap});
|
|
||||||
|
|
||||||
final String label;
|
|
||||||
final VoidCallback onTap;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: DecoratedBox(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white12,
|
|
||||||
borderRadius: BorderRadius.circular(8.r),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 12.r, vertical: 8.r),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: TextStyle(color: Colors.white70, fontSize: 12.sp),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Icon(Icons.chevron_right, color: Colors.white54, size: 18.r),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,292 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:recording_tool/core/permission/permission_service.dart';
|
|
||||||
import 'package:recording_tool/features/recording/recording_display_name.dart';
|
|
||||||
import 'package:recording_tool/features/recording/recording_platform.dart';
|
|
||||||
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
|
||||||
|
|
||||||
class RecordingSessionState {
|
|
||||||
const RecordingSessionState({
|
|
||||||
this.status = const RecordingStatus(state: RecordingState.idle),
|
|
||||||
this.isTouchLocked = true,
|
|
||||||
this.isPreviewReady = false,
|
|
||||||
this.hasDndAccess = false,
|
|
||||||
this.isBatteryOptimizedIgnored = true,
|
|
||||||
this.notificationsGranted = true,
|
|
||||||
this.isMicrophoneGranted = false,
|
|
||||||
this.lastOutputPath,
|
|
||||||
this.lastSavedDisplayName,
|
|
||||||
this.errorMessage,
|
|
||||||
this.permissionWarning,
|
|
||||||
this.gallerySaveFailed = false,
|
|
||||||
});
|
|
||||||
|
|
||||||
final RecordingStatus status;
|
|
||||||
final bool isTouchLocked;
|
|
||||||
final bool isPreviewReady;
|
|
||||||
final bool hasDndAccess;
|
|
||||||
final bool isBatteryOptimizedIgnored;
|
|
||||||
final bool notificationsGranted;
|
|
||||||
final bool isMicrophoneGranted;
|
|
||||||
final String? lastOutputPath;
|
|
||||||
final String? lastSavedDisplayName;
|
|
||||||
final String? errorMessage;
|
|
||||||
final String? permissionWarning;
|
|
||||||
final bool gallerySaveFailed;
|
|
||||||
|
|
||||||
bool get isRecording => status.isRecording;
|
|
||||||
|
|
||||||
String get elapsedLabel {
|
|
||||||
final totalSeconds = status.elapsedMillis ~/ 1000;
|
|
||||||
final minutes = (totalSeconds ~/ 60).toString().padLeft(2, '0');
|
|
||||||
final seconds = (totalSeconds % 60).toString().padLeft(2, '0');
|
|
||||||
return '$minutes:$seconds';
|
|
||||||
}
|
|
||||||
|
|
||||||
RecordingSessionState copyWith({
|
|
||||||
RecordingStatus? status,
|
|
||||||
bool? isTouchLocked,
|
|
||||||
bool? isPreviewReady,
|
|
||||||
bool? hasDndAccess,
|
|
||||||
bool? isBatteryOptimizedIgnored,
|
|
||||||
bool? notificationsGranted,
|
|
||||||
bool? isMicrophoneGranted,
|
|
||||||
String? lastOutputPath,
|
|
||||||
String? lastSavedDisplayName,
|
|
||||||
String? errorMessage,
|
|
||||||
String? permissionWarning,
|
|
||||||
bool? gallerySaveFailed,
|
|
||||||
bool clearPermissionWarning = false,
|
|
||||||
bool clearLastSaved = false,
|
|
||||||
}) {
|
|
||||||
return RecordingSessionState(
|
|
||||||
status: status ?? this.status,
|
|
||||||
isTouchLocked: isTouchLocked ?? this.isTouchLocked,
|
|
||||||
isPreviewReady: isPreviewReady ?? this.isPreviewReady,
|
|
||||||
hasDndAccess: hasDndAccess ?? this.hasDndAccess,
|
|
||||||
isBatteryOptimizedIgnored:
|
|
||||||
isBatteryOptimizedIgnored ?? this.isBatteryOptimizedIgnored,
|
|
||||||
notificationsGranted: notificationsGranted ?? this.notificationsGranted,
|
|
||||||
isMicrophoneGranted: isMicrophoneGranted ?? this.isMicrophoneGranted,
|
|
||||||
lastOutputPath: lastOutputPath ?? this.lastOutputPath,
|
|
||||||
lastSavedDisplayName: clearLastSaved
|
|
||||||
? null
|
|
||||||
: (lastSavedDisplayName ?? this.lastSavedDisplayName),
|
|
||||||
errorMessage: errorMessage,
|
|
||||||
permissionWarning: clearPermissionWarning
|
|
||||||
? null
|
|
||||||
: (permissionWarning ?? this.permissionWarning),
|
|
||||||
gallerySaveFailed: gallerySaveFailed ?? this.gallerySaveFailed,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final recordingSessionControllerProvider =
|
|
||||||
NotifierProvider<RecordingSessionController, RecordingSessionState>(
|
|
||||||
RecordingSessionController.new,
|
|
||||||
);
|
|
||||||
|
|
||||||
class RecordingSessionController extends Notifier<RecordingSessionState> {
|
|
||||||
StreamSubscription<RecordingStatus>? _statusSubscription;
|
|
||||||
|
|
||||||
@override
|
|
||||||
RecordingSessionState build() {
|
|
||||||
ref.onDispose(_dispose);
|
|
||||||
return const RecordingSessionState();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> prepareSession() async {
|
|
||||||
if (!RecordingPlatform.isSupported) {
|
|
||||||
state = state.copyWith(errorMessage: '当前设备不支持录制');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final permissions = await PermissionService.requestMissing([
|
|
||||||
Permission.camera,
|
|
||||||
Permission.microphone,
|
|
||||||
if (Platform.isAndroid) Permission.notification,
|
|
||||||
..._galleryPermissions(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
final cameraGranted = permissions[Permission.camera]?.isGranted ?? false;
|
|
||||||
if (!cameraGranted) {
|
|
||||||
state = state.copyWith(errorMessage: '需要相机权限才能录制');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final microphoneGranted =
|
|
||||||
permissions[Permission.microphone]?.isGranted ?? false;
|
|
||||||
final notificationsGranted = Platform.isAndroid
|
|
||||||
? (permissions[Permission.notification]?.isGranted ?? false)
|
|
||||||
: true;
|
|
||||||
|
|
||||||
final warnings = <String>[];
|
|
||||||
if (Platform.isAndroid && !notificationsGranted) {
|
|
||||||
warnings.add('未授予通知权限,录制时可能看不到前台服务通知,系统更容易结束后台录制');
|
|
||||||
}
|
|
||||||
if (!microphoneGranted) {
|
|
||||||
warnings.add('未授予麦克风权限,当前将以静音模式录制');
|
|
||||||
}
|
|
||||||
if (!_isGalleryPermissionGranted(permissions)) {
|
|
||||||
warnings.add('未授予相册权限,录制结束后可能无法保存到相册');
|
|
||||||
}
|
|
||||||
|
|
||||||
final hasDnd = await RecordingPlatform.hasNotificationPolicyAccess();
|
|
||||||
final batteryIgnored =
|
|
||||||
await RecordingPlatform.isIgnoringBatteryOptimizations();
|
|
||||||
|
|
||||||
state = state.copyWith(
|
|
||||||
hasDndAccess: hasDnd,
|
|
||||||
isBatteryOptimizedIgnored: batteryIgnored,
|
|
||||||
isMicrophoneGranted: microphoneGranted,
|
|
||||||
notificationsGranted: notificationsGranted,
|
|
||||||
permissionWarning: warnings.isEmpty ? null : warnings.join('\n'),
|
|
||||||
errorMessage: null,
|
|
||||||
clearPermissionWarning: warnings.isEmpty,
|
|
||||||
);
|
|
||||||
|
|
||||||
await _listenStatus();
|
|
||||||
try {
|
|
||||||
final status = await _initializePreviewWithRetry();
|
|
||||||
state = state.copyWith(
|
|
||||||
status: status,
|
|
||||||
isPreviewReady: status.state == RecordingState.previewing,
|
|
||||||
errorMessage: status.state == RecordingState.previewing
|
|
||||||
? null
|
|
||||||
: (status.message ?? '相机预览初始化失败'),
|
|
||||||
);
|
|
||||||
} on PlatformException catch (error) {
|
|
||||||
state = state.copyWith(
|
|
||||||
isPreviewReady: false,
|
|
||||||
errorMessage: error.message ?? '相机预览初始化失败',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<RecordingStatus> _initializePreviewWithRetry() async {
|
|
||||||
const maxAttempts = 8;
|
|
||||||
for (var attempt = 0; attempt < maxAttempts; attempt++) {
|
|
||||||
try {
|
|
||||||
return await RecordingPlatform.initializePreview();
|
|
||||||
} on PlatformException catch (error) {
|
|
||||||
final shouldRetry =
|
|
||||||
error.code == 'NO_PREVIEW' && attempt < maxAttempts - 1;
|
|
||||||
if (!shouldRetry) {
|
|
||||||
rethrow;
|
|
||||||
}
|
|
||||||
await Future<void>.delayed(Duration(milliseconds: 150 * (attempt + 1)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw StateError('initializePreview retry exhausted');
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Permission> _galleryPermissions() {
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
return [Permission.photosAddOnly, Permission.photos];
|
|
||||||
}
|
|
||||||
if (Platform.isAndroid) {
|
|
||||||
return [Permission.videos, Permission.storage];
|
|
||||||
}
|
|
||||||
return const [];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _isGalleryPermissionGranted(Map<Permission, PermissionStatus> permissions) {
|
|
||||||
for (final permission in _galleryPermissions()) {
|
|
||||||
if (permissions[permission]?.isGranted ?? false) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _galleryPermissions().isEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> startRecording({bool enableDoNotDisturb = true}) async {
|
|
||||||
if (!state.isPreviewReady || state.isRecording) return;
|
|
||||||
|
|
||||||
final clipboard = ref.read(recordingViewModelProvider).clipboardRecordingModel;
|
|
||||||
final displayName = recordingFileNameForPlatform(clipboard.filename);
|
|
||||||
|
|
||||||
try {
|
|
||||||
final result = await RecordingPlatform.startRecording(
|
|
||||||
enableDoNotDisturb: enableDoNotDisturb && state.hasDndAccess,
|
|
||||||
displayName: displayName,
|
|
||||||
);
|
|
||||||
state = state.copyWith(
|
|
||||||
status: result.status,
|
|
||||||
lastOutputPath: result.outputPath,
|
|
||||||
isTouchLocked: true,
|
|
||||||
errorMessage: null,
|
|
||||||
gallerySaveFailed: false,
|
|
||||||
clearLastSaved: true,
|
|
||||||
);
|
|
||||||
} on PlatformException catch (error) {
|
|
||||||
state = state.copyWith(errorMessage: error.message ?? '开始录制失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> stopRecording() async {
|
|
||||||
if (!state.isRecording) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
final result = await RecordingPlatform.stopRecording();
|
|
||||||
final galleryFailed = !result.gallerySaved;
|
|
||||||
final savedName = recordingFileNameForPlatform(
|
|
||||||
ref.read(recordingViewModelProvider).clipboardRecordingModel.filename,
|
|
||||||
);
|
|
||||||
state = state.copyWith(
|
|
||||||
status: result.status,
|
|
||||||
lastOutputPath: result.outputPath ?? state.lastOutputPath,
|
|
||||||
lastSavedDisplayName: galleryFailed ? null : savedName,
|
|
||||||
errorMessage: galleryFailed
|
|
||||||
? (result.galleryErrorMessage ?? '保存到相册失败,请开启相册权限')
|
|
||||||
: null,
|
|
||||||
gallerySaveFailed: galleryFailed,
|
|
||||||
);
|
|
||||||
} on PlatformException catch (error) {
|
|
||||||
state = state.copyWith(errorMessage: error.message ?? '停止录制失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTouchLocked(bool locked) {
|
|
||||||
state = state.copyWith(isTouchLocked: locked);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> openDndSettings() =>
|
|
||||||
RecordingPlatform.openNotificationPolicySettings();
|
|
||||||
|
|
||||||
Future<void> refreshDndAccess() async {
|
|
||||||
final hasDnd = await RecordingPlatform.hasNotificationPolicyAccess();
|
|
||||||
state = state.copyWith(hasDndAccess: hasDnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> openBatterySettings() =>
|
|
||||||
RecordingPlatform.openBatteryOptimizationSettings();
|
|
||||||
|
|
||||||
Future<void> refreshBatteryOptimization() async {
|
|
||||||
final ignored = await RecordingPlatform.isIgnoringBatteryOptimizations();
|
|
||||||
state = state.copyWith(isBatteryOptimizedIgnored: ignored);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> teardown() async {
|
|
||||||
await RecordingPlatform.setImmersiveMode(enabled: false);
|
|
||||||
await RecordingPlatform.disableDoNotDisturb();
|
|
||||||
await RecordingPlatform.disposePreview();
|
|
||||||
await _statusSubscription?.cancel();
|
|
||||||
_statusSubscription = null;
|
|
||||||
state = const RecordingSessionState();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _listenStatus() async {
|
|
||||||
await _statusSubscription?.cancel();
|
|
||||||
_statusSubscription = RecordingPlatform.statusStream().listen((status) {
|
|
||||||
state = state.copyWith(status: status);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _dispose() async {
|
|
||||||
await _statusSubscription?.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,23 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_riverpod/legacy.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:recording_tool/core/logging/app_logger.dart';
|
import 'package:recording_tool/core/logging/app_logger.dart';
|
||||||
|
import 'package:recording_tool/core/permission/permission_service.dart';
|
||||||
import 'package:recording_tool/features/recording/model/model_clipboard.dart';
|
import 'package:recording_tool/features/recording/model/model_clipboard.dart';
|
||||||
import 'package:recording_tool/features/recording/model/model_recording.dart';
|
import 'package:recording_tool/features/recording/model/model_recording.dart';
|
||||||
|
import 'package:recording_tool/features/recording/model/model_recording_session.dart';
|
||||||
|
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||||
|
import 'package:recording_tool/features/recording/utils/recording_display_name.dart';
|
||||||
|
|
||||||
|
/// 录制页状态 Provider。
|
||||||
final recordingViewModelProvider =
|
final recordingViewModelProvider =
|
||||||
StateNotifierProvider<RecordingViewModel, RecordingModel>((ref) {
|
NotifierProvider<RecordingViewModel, RecordingModel>(
|
||||||
return RecordingViewModel(ref);
|
RecordingViewModel.new,
|
||||||
});
|
);
|
||||||
|
|
||||||
/// 剪切板读取结果,供 UI 决定是否提示用户。
|
/// 剪切板读取结果,供 UI 决定是否提示用户。
|
||||||
enum ClipboardReadResult {
|
enum ClipboardReadResult {
|
||||||
@@ -24,28 +31,56 @@ enum ClipboardReadResult {
|
|||||||
invalid,
|
invalid,
|
||||||
}
|
}
|
||||||
|
|
||||||
class RecordingViewModel extends StateNotifier<RecordingModel> {
|
List<Permission> recordingGalleryPermissionsForHost({
|
||||||
RecordingViewModel(this.ref)
|
required bool isIOS,
|
||||||
: super(
|
required bool isAndroid,
|
||||||
RecordingModel(
|
}) {
|
||||||
clipboardRecordingModel: ClipboardRecordingModel(
|
if (isIOS) {
|
||||||
title: '',
|
return [Permission.photosAddOnly];
|
||||||
startTimestamp: 0,
|
}
|
||||||
endTimestamp: 0,
|
if (isAndroid) {
|
||||||
address: '',
|
return [Permission.videos, Permission.storage];
|
||||||
),
|
}
|
||||||
),
|
return const [];
|
||||||
);
|
}
|
||||||
final Ref ref;
|
|
||||||
|
|
||||||
|
/// 开始录制所需的相机/麦克风权限检测结果。
|
||||||
|
class RecordingRequiredPermissions {
|
||||||
|
const RecordingRequiredPermissions({
|
||||||
|
required this.cameraGranted,
|
||||||
|
required this.microphoneGranted,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool cameraGranted;
|
||||||
|
final bool microphoneGranted;
|
||||||
|
|
||||||
|
bool get allGranted => cameraGranted && microphoneGranted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 录制页 ViewModel:剪贴板、权限、相机预览与录制流程。
|
||||||
|
class RecordingViewModel extends Notifier<RecordingModel> {
|
||||||
static final _defaultClipboard = ClipboardRecordingModel(
|
static final _defaultClipboard = ClipboardRecordingModel(
|
||||||
title: '',
|
title: '',
|
||||||
startTimestamp: 0,
|
|
||||||
endTimestamp: 0,
|
|
||||||
address: '',
|
address: '',
|
||||||
);
|
);
|
||||||
|
|
||||||
/// 从剪切板获取小程序复制的录制信息。
|
StreamSubscription<RecordingStatus>? _statusSubscription;
|
||||||
|
|
||||||
|
/// 初始化状态并注册销毁回调。
|
||||||
|
@override
|
||||||
|
RecordingModel build() {
|
||||||
|
ref.onDispose(_dispose);
|
||||||
|
return RecordingModel(clipboardRecordingModel: _defaultClipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 局部更新 session 子状态。
|
||||||
|
void _updateSession(
|
||||||
|
RecordingSessionState Function(RecordingSessionState session) update,
|
||||||
|
) {
|
||||||
|
state = state.copyWith(session: update(state.session));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 读取并解析剪贴板中的小程序录制信息。
|
||||||
Future<ClipboardReadResult> getClipboardContent() async {
|
Future<ClipboardReadResult> getClipboardContent() async {
|
||||||
try {
|
try {
|
||||||
final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||||
@@ -89,10 +124,313 @@ class RecordingViewModel extends StateNotifier<RecordingModel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 清空剪贴板赛事信息(供 UI 调用)。
|
||||||
|
void resetClipboardInfo() {
|
||||||
|
_resetClipboardInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 重置剪贴板赛事信息为默认空值。
|
||||||
void _resetClipboardInfo() {
|
void _resetClipboardInfo() {
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
clipboardRecordingModel: _defaultClipboard,
|
clipboardRecordingModel: _defaultClipboard,
|
||||||
hasValidClipboardInfo: false,
|
hasValidClipboardInfo: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 申请权限、检查系统设置并初始化相机预览。
|
||||||
|
Future<void> prepareSession() async {
|
||||||
|
if (!RecordingPlatform.isSupported) {
|
||||||
|
_updateSession((s) => s.copyWith(errorMessage: '当前设备不支持录制'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final permissions = await PermissionService.requestMissing([
|
||||||
|
Permission.camera,
|
||||||
|
Permission.microphone,
|
||||||
|
if (Platform.isAndroid) Permission.notification,
|
||||||
|
..._galleryPermissions(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
final cameraGranted = permissions[Permission.camera]?.isGranted ?? false;
|
||||||
|
if (!cameraGranted) {
|
||||||
|
_updateSession((s) => s.copyWith(errorMessage: '需要相机权限才能录制'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final microphoneGranted =
|
||||||
|
permissions[Permission.microphone]?.isGranted ?? false;
|
||||||
|
final notificationsGranted = Platform.isAndroid
|
||||||
|
? (permissions[Permission.notification]?.isGranted ?? false)
|
||||||
|
: true;
|
||||||
|
|
||||||
|
final warnings = <String>[];
|
||||||
|
if (Platform.isAndroid && !notificationsGranted) {
|
||||||
|
warnings.add('未授予通知权限,录制时可能看不到前台服务通知,系统更容易结束后台录制');
|
||||||
|
}
|
||||||
|
if (!microphoneGranted) {
|
||||||
|
warnings.add('未授予麦克风权限,当前将以静音模式录制');
|
||||||
|
}
|
||||||
|
if (!_isGalleryPermissionGranted(permissions)) {
|
||||||
|
warnings.add('未授予相册权限,录制结束后可能无法保存到相册');
|
||||||
|
}
|
||||||
|
|
||||||
|
final hasDnd = await RecordingPlatform.hasNotificationPolicyAccess();
|
||||||
|
final batteryIgnored =
|
||||||
|
await RecordingPlatform.isIgnoringBatteryOptimizations();
|
||||||
|
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
hasDndAccess: hasDnd,
|
||||||
|
isBatteryOptimizedIgnored: batteryIgnored,
|
||||||
|
isMicrophoneGranted: microphoneGranted,
|
||||||
|
notificationsGranted: notificationsGranted,
|
||||||
|
permissionWarning: warnings.isEmpty ? null : warnings.join('\n'),
|
||||||
|
errorMessage: null,
|
||||||
|
clearPermissionWarning: warnings.isEmpty,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await _listenStatus();
|
||||||
|
try {
|
||||||
|
final status = await _initializePreviewWithRetry();
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
status: status,
|
||||||
|
isPreviewReady: status.state == RecordingState.previewing,
|
||||||
|
errorMessage: status.state == RecordingState.previewing
|
||||||
|
? null
|
||||||
|
: (status.message ?? '相机预览初始化失败'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on PlatformException catch (error) {
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
isPreviewReady: false,
|
||||||
|
errorMessage: error.message ?? '相机预览初始化失败',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 初始化相机预览,PlatformView 未就绪时自动重试。
|
||||||
|
Future<RecordingStatus> _initializePreviewWithRetry() async {
|
||||||
|
const maxAttempts = 8;
|
||||||
|
for (var attempt = 0; attempt < maxAttempts; attempt++) {
|
||||||
|
try {
|
||||||
|
return await RecordingPlatform.initializePreview();
|
||||||
|
} on PlatformException catch (error) {
|
||||||
|
final shouldRetry =
|
||||||
|
error.code == 'NO_PREVIEW' && attempt < maxAttempts - 1;
|
||||||
|
if (!shouldRetry) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
await Future<void>.delayed(Duration(milliseconds: 150 * (attempt + 1)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw StateError('initializePreview retry exhausted');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止录制后重新绑定相机预览,并显示加载遮罩。
|
||||||
|
Future<void> restorePreview() async {
|
||||||
|
if (!RecordingPlatform.isSupported) return;
|
||||||
|
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(isPreviewReady: false, errorMessage: null),
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
final status = await _initializePreviewWithRetry();
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
status: status,
|
||||||
|
isPreviewReady: status.state == RecordingState.previewing,
|
||||||
|
errorMessage: status.state == RecordingState.previewing
|
||||||
|
? null
|
||||||
|
: (status.message ?? '相机预览初始化失败'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on PlatformException catch (error) {
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
isPreviewReady: false,
|
||||||
|
errorMessage: error.message ?? '相机预览初始化失败',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 当前平台所需的相册/视频保存权限列表。
|
||||||
|
List<Permission> _galleryPermissions() {
|
||||||
|
return recordingGalleryPermissionsForHost(
|
||||||
|
isIOS: Platform.isIOS,
|
||||||
|
isAndroid: Platform.isAndroid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 判断相册相关权限是否至少有一项已授予。
|
||||||
|
bool _isGalleryPermissionGranted(
|
||||||
|
Map<Permission, PermissionStatus> permissions,
|
||||||
|
) {
|
||||||
|
for (final permission in _galleryPermissions()) {
|
||||||
|
if (permissions[permission]?.isGranted ?? false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _galleryPermissions().isEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 检测并尝试申请相机、麦克风权限,同步更新 session 中的 isMicrophoneGranted。
|
||||||
|
Future<RecordingRequiredPermissions>
|
||||||
|
ensureCameraAndMicrophonePermissions() async {
|
||||||
|
final permissions = await PermissionService.requestMissing([
|
||||||
|
Permission.camera,
|
||||||
|
Permission.microphone,
|
||||||
|
]);
|
||||||
|
|
||||||
|
final cameraGranted = _isPermissionGranted(permissions[Permission.camera]);
|
||||||
|
final microphoneGranted = _isPermissionGranted(
|
||||||
|
permissions[Permission.microphone],
|
||||||
|
);
|
||||||
|
|
||||||
|
_updateSession((s) => s.copyWith(isMicrophoneGranted: microphoneGranted));
|
||||||
|
|
||||||
|
if (cameraGranted && !state.session.isPreviewReady) {
|
||||||
|
_updateSession((s) => s.copyWith(errorMessage: null));
|
||||||
|
await _listenStatus();
|
||||||
|
await restorePreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
return RecordingRequiredPermissions(
|
||||||
|
cameraGranted: cameraGranted,
|
||||||
|
microphoneGranted: microphoneGranted,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isPermissionGranted(PermissionStatus? status) {
|
||||||
|
return status?.isGranted == true || status?.isLimited == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 开始录制,可选开启勿扰模式。
|
||||||
|
Future<void> startRecording({bool enableDoNotDisturb = true}) async {
|
||||||
|
final session = state.session;
|
||||||
|
if (session.isRecording || session.isStartingRecording) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!session.isPreviewReady) {
|
||||||
|
_updateSession((s) => s.copyWith(errorMessage: '相机预览未就绪,请稍后重试'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final displayName = recordingFileNameForPlatform(
|
||||||
|
state.clipboardRecordingModel.filename,
|
||||||
|
);
|
||||||
|
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(isStartingRecording: true, errorMessage: null),
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
final result = await RecordingPlatform.startRecording(
|
||||||
|
enableDoNotDisturb: enableDoNotDisturb && state.session.hasDndAccess,
|
||||||
|
displayName: displayName,
|
||||||
|
);
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
status: result.status,
|
||||||
|
lastOutputPath: result.outputPath,
|
||||||
|
isTouchLocked: true,
|
||||||
|
errorMessage: null,
|
||||||
|
gallerySaveFailed: false,
|
||||||
|
clearLastSaved: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on PlatformException catch (error) {
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(errorMessage: error.message ?? '开始录制失败'),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
_updateSession((s) => s.copyWith(isStartingRecording: false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 停止录制、保存到相册,并恢复相机预览。
|
||||||
|
Future<void> stopRecording() async {
|
||||||
|
if (!state.session.isRecording) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final result = await RecordingPlatform.stopRecording();
|
||||||
|
final galleryFailed = !result.gallerySaved;
|
||||||
|
final savedName = recordingFileNameForPlatform(
|
||||||
|
state.clipboardRecordingModel.filename,
|
||||||
|
);
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(
|
||||||
|
status: result.status,
|
||||||
|
lastOutputPath: result.outputPath ?? s.lastOutputPath,
|
||||||
|
lastSavedDisplayName: galleryFailed ? null : savedName,
|
||||||
|
errorMessage: galleryFailed
|
||||||
|
? (result.galleryErrorMessage ?? '保存到相册失败,请开启相册权限')
|
||||||
|
: null,
|
||||||
|
gallerySaveFailed: galleryFailed,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on PlatformException catch (error) {
|
||||||
|
_updateSession(
|
||||||
|
(s) => s.copyWith(errorMessage: error.message ?? '停止录制失败'),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await restorePreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 切换录制中触屏锁定状态。
|
||||||
|
void setTouchLocked(bool locked) {
|
||||||
|
_updateSession((s) => s.copyWith(isTouchLocked: locked));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 清除上次保存成功的录制结果标记。
|
||||||
|
void clearSavedRecordingResult() {
|
||||||
|
_updateSession((s) => s.copyWith(clearLastSaved: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 跳转系统勿扰/通知策略设置页。
|
||||||
|
Future<void> openDndSettings() =>
|
||||||
|
RecordingPlatform.openNotificationPolicySettings();
|
||||||
|
|
||||||
|
/// 重新检测勿扰模式权限并更新状态。
|
||||||
|
Future<void> refreshDndAccess() async {
|
||||||
|
final hasDnd = await RecordingPlatform.hasNotificationPolicyAccess();
|
||||||
|
_updateSession((s) => s.copyWith(hasDndAccess: hasDnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 跳转电池优化白名单设置页。
|
||||||
|
Future<void> openBatterySettings() =>
|
||||||
|
RecordingPlatform.openBatteryOptimizationSettings();
|
||||||
|
|
||||||
|
/// 重新检测是否已忽略电池优化并更新状态。
|
||||||
|
Future<void> refreshBatteryOptimization() async {
|
||||||
|
final ignored = await RecordingPlatform.isIgnoringBatteryOptimizations();
|
||||||
|
_updateSession((s) => s.copyWith(isBatteryOptimizedIgnored: ignored));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 退出录制页时释放相机、勿扰和状态订阅。
|
||||||
|
Future<void> teardown() async {
|
||||||
|
await RecordingPlatform.setImmersiveMode(enabled: false);
|
||||||
|
await RecordingPlatform.disableDoNotDisturb();
|
||||||
|
await RecordingPlatform.disposePreview();
|
||||||
|
await _statusSubscription?.cancel();
|
||||||
|
_statusSubscription = null;
|
||||||
|
state = state.copyWith(session: const RecordingSessionState());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 订阅原生层录制状态流并同步到 session。
|
||||||
|
Future<void> _listenStatus() async {
|
||||||
|
await _statusSubscription?.cancel();
|
||||||
|
_statusSubscription = RecordingPlatform.statusStream().listen((status) {
|
||||||
|
_updateSession((s) => s.copyWith(status: status));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Provider 销毁时取消状态流订阅。
|
||||||
|
Future<void> _dispose() async {
|
||||||
|
await _statusSubscription?.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// 录制页内容切换时的统一过渡动画。
|
||||||
|
class RecordContentTransition {
|
||||||
|
RecordContentTransition._();
|
||||||
|
|
||||||
|
static const duration = Duration(milliseconds: 600);
|
||||||
|
|
||||||
|
static Widget builder(Widget child, Animation<double> animation) {
|
||||||
|
final curved = CurvedAnimation(
|
||||||
|
parent: animation,
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
reverseCurve: Curves.easeInCubic,
|
||||||
|
);
|
||||||
|
|
||||||
|
return FadeTransition(
|
||||||
|
opacity: curved,
|
||||||
|
child: SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 0.12),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(curved),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget stackLayoutBuilder(
|
||||||
|
Widget? currentChild,
|
||||||
|
List<Widget> previousChildren,
|
||||||
|
) {
|
||||||
|
return Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [...previousChildren, ?currentChild],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget bottomStackLayoutBuilder(
|
||||||
|
Widget? currentChild,
|
||||||
|
List<Widget> previousChildren,
|
||||||
|
) {
|
||||||
|
return Stack(
|
||||||
|
alignment: Alignment.bottomLeft,
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [...previousChildren, ?currentChild],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
||||||
|
|
||||||
class RecordingTouchLockOverlay extends StatefulWidget {
|
|
||||||
const RecordingTouchLockOverlay({
|
|
||||||
super.key,
|
|
||||||
required this.enabled,
|
|
||||||
required this.onUnlocked,
|
|
||||||
this.unlockHoldDuration = const Duration(seconds: 2),
|
|
||||||
});
|
|
||||||
|
|
||||||
final bool enabled;
|
|
||||||
final VoidCallback onUnlocked;
|
|
||||||
final Duration unlockHoldDuration;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<RecordingTouchLockOverlay> createState() =>
|
|
||||||
_RecordingTouchLockOverlayState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _RecordingTouchLockOverlayState extends State<RecordingTouchLockOverlay> {
|
|
||||||
Timer? _holdTimer;
|
|
||||||
bool _isHolding = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(RecordingTouchLockOverlay oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (!widget.enabled) {
|
|
||||||
_cancelHold();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_cancelHold();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _cancelHold() {
|
|
||||||
_holdTimer?.cancel();
|
|
||||||
_holdTimer = null;
|
|
||||||
_isHolding = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _startHold() {
|
|
||||||
if (!widget.enabled) return;
|
|
||||||
setState(() => _isHolding = true);
|
|
||||||
_holdTimer?.cancel();
|
|
||||||
_holdTimer = Timer(widget.unlockHoldDuration, () {
|
|
||||||
if (!mounted) return;
|
|
||||||
_cancelHold();
|
|
||||||
widget.onUnlocked();
|
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
if (!widget.enabled) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Positioned.fill(
|
|
||||||
child: Listener(
|
|
||||||
behavior: HitTestBehavior.opaque,
|
|
||||||
onPointerDown: (_) => _startHold(),
|
|
||||||
onPointerUp: (_) => _cancelHold(),
|
|
||||||
onPointerCancel: (_) => _cancelHold(),
|
|
||||||
child: ColoredBox(
|
|
||||||
color: Colors.black.withValues(alpha: 0.01),
|
|
||||||
child: Align(
|
|
||||||
alignment: Alignment.topCenter,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.only(top: 48.r),
|
|
||||||
child: DecoratedBox(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.black54,
|
|
||||||
borderRadius: BorderRadius.circular(24.r),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.symmetric(
|
|
||||||
horizontal: 16.r,
|
|
||||||
vertical: 8.r,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
_isHolding
|
|
||||||
? '保持按住 ${widget.unlockHoldDuration.inSeconds}s 解锁…'
|
|
||||||
: '防误触已开启,按住 ${widget.unlockHoldDuration.inSeconds}s 解锁',
|
|
||||||
style: TextStyle(color: Colors.white, fontSize: 13.sp),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:recording_tool/core/utils/date_time_formatter.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/record_content_transition.dart';
|
||||||
|
|
||||||
|
/// 左下角实时时钟与剪贴板地址
|
||||||
|
class ClipboardAddressClockChipWidget extends StatefulWidget {
|
||||||
|
const ClipboardAddressClockChipWidget({super.key, required this.address});
|
||||||
|
|
||||||
|
final String address;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ClipboardAddressClockChipWidget> createState() =>
|
||||||
|
_ClipboardAddressClockChipWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ClipboardAddressClockChipWidgetState
|
||||||
|
extends State<ClipboardAddressClockChipWidget> {
|
||||||
|
Timer? _clockTimer;
|
||||||
|
|
||||||
|
static TextStyle get _textStyle => TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12.sp,
|
||||||
|
height: 1.4,
|
||||||
|
shadows: [Shadow(color: Colors.black54, blurRadius: 6.r)],
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_clockTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_clockTimer?.cancel();
|
||||||
|
_clockTimer = null;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
String get _nowText => DateTimeFormatter.format(
|
||||||
|
DateTime.now(),
|
||||||
|
pattern: 'yyyy-M-d-H:mm:ss',
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AnimatedSize(
|
||||||
|
duration: RecordContentTransition.duration,
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(_nowText, style: _textStyle),
|
||||||
|
AnimatedSwitcher(
|
||||||
|
duration: RecordContentTransition.duration,
|
||||||
|
switchInCurve: Curves.easeOutCubic,
|
||||||
|
switchOutCurve: Curves.easeInCubic,
|
||||||
|
layoutBuilder: RecordContentTransition.bottomStackLayoutBuilder,
|
||||||
|
transitionBuilder: RecordContentTransition.builder,
|
||||||
|
child: widget.address.isNotEmpty
|
||||||
|
? Text(
|
||||||
|
widget.address,
|
||||||
|
key: ValueKey(widget.address),
|
||||||
|
style: _textStyle,
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(key: ValueKey('clipboard-address-empty')),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
lib/features/recording/widgets/widget_record_footer.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
|
class RecordFooter extends StatefulWidget {
|
||||||
|
const RecordFooter({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RecordFooter> createState() => _RecordFooterState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordFooterState extends State<RecordFooter> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(height: 65.r, width: double.infinity);
|
||||||
|
}
|
||||||
|
}
|
||||||
221
lib/features/recording/widgets/widget_record_header.dart
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/record_content_transition.dart';
|
||||||
|
import 'package:recording_tool/gen/assets.gen.dart';
|
||||||
|
import 'package:recording_tool/shared/widgets/app_toast.dart';
|
||||||
|
|
||||||
|
/// 录制页顶部:Logo、粘贴赛事、赛事标题
|
||||||
|
class RecordHeaderWidget extends StatelessWidget {
|
||||||
|
const RecordHeaderWidget({
|
||||||
|
super.key,
|
||||||
|
required this.hasValidClipboardInfo,
|
||||||
|
this.eventTitle,
|
||||||
|
required this.isRecording,
|
||||||
|
required this.onPasteEventInfo,
|
||||||
|
required this.onClearEventInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool hasValidClipboardInfo;
|
||||||
|
final String? eventTitle;
|
||||||
|
final bool isRecording;
|
||||||
|
final Future<void> Function() onPasteEventInfo;
|
||||||
|
final VoidCallback onClearEventInfo;
|
||||||
|
|
||||||
|
bool get _showPasteButtons => !hasValidClipboardInfo && !isRecording;
|
||||||
|
|
||||||
|
bool get _showEventTitle => hasValidClipboardInfo;
|
||||||
|
|
||||||
|
Widget _buildAnimatedHeaderContent() {
|
||||||
|
if (_showEventTitle) {
|
||||||
|
return _HeaderEventTitleRow(
|
||||||
|
key: ValueKey('title-${eventTitle ?? ''}'),
|
||||||
|
title: eventTitle ?? '',
|
||||||
|
isRecording: isRecording,
|
||||||
|
onClearEventInfo: onClearEventInfo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return const SizedBox.shrink(key: ValueKey('header-empty'));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _mockCopyEventInfo() {
|
||||||
|
const strTemp =
|
||||||
|
'{"title":"蔡依婷vs夏志豪 空中格斗赛 初中组","address":"黑龙江省鹤岗市11111","filename":"蔡依婷_夏志豪_测试循环赛-7_空中格斗赛"}';
|
||||||
|
Clipboard.setData(const ClipboardData(text: strTemp));
|
||||||
|
AppToast.show('模拟复制赛事信息成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SafeArea(
|
||||||
|
bottom: false,
|
||||||
|
child: SizedBox(
|
||||||
|
height: 56.h,
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 12.w),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Image.asset(
|
||||||
|
Assets.images.imageLogo.path,
|
||||||
|
width: 24.r,
|
||||||
|
height: 24.r,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
AnimatedSwitcher(
|
||||||
|
duration: RecordContentTransition.duration,
|
||||||
|
switchInCurve: Curves.easeOutCubic,
|
||||||
|
switchOutCurve: Curves.easeInCubic,
|
||||||
|
layoutBuilder: RecordContentTransition.stackLayoutBuilder,
|
||||||
|
transitionBuilder: RecordContentTransition.builder,
|
||||||
|
child: _buildAnimatedHeaderContent(),
|
||||||
|
),
|
||||||
|
if (_showPasteButtons)
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: _HeaderPasteActions(
|
||||||
|
onMockCopy: _mockCopyEventInfo,
|
||||||
|
onPasteEventInfo: onPasteEventInfo,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HeaderEventTitleRow extends StatelessWidget {
|
||||||
|
const _HeaderEventTitleRow({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.isRecording,
|
||||||
|
required this.onClearEventInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final bool isRecording;
|
||||||
|
final VoidCallback onClearEventInfo;
|
||||||
|
|
||||||
|
static TextStyle get _overlayTextStyle => TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
shadows: [Shadow(color: Colors.black54, blurRadius: 6.r)],
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: AnimatedSwitcher(
|
||||||
|
duration: RecordContentTransition.duration,
|
||||||
|
switchInCurve: Curves.easeOutCubic,
|
||||||
|
switchOutCurve: Curves.easeInCubic,
|
||||||
|
transitionBuilder: RecordContentTransition.builder,
|
||||||
|
child: Text(
|
||||||
|
title,
|
||||||
|
key: ValueKey(title),
|
||||||
|
style: _overlayTextStyle.copyWith(
|
||||||
|
fontSize: 12.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 3,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
!isRecording
|
||||||
|
? IconButton(
|
||||||
|
key: const ValueKey('clear-event-info'),
|
||||||
|
onPressed: onClearEventInfo,
|
||||||
|
icon: Assets.images.imageDelete.image(
|
||||||
|
width: 15.r,
|
||||||
|
height: 15.r,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
excludeFromSemantics: true,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
constraints: BoxConstraints(minWidth: 40.r, minHeight: 40.r),
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
tooltip: '删除',
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(key: ValueKey('clear-event-info-hidden')),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HeaderPasteActions extends StatelessWidget {
|
||||||
|
const _HeaderPasteActions({
|
||||||
|
required this.onMockCopy,
|
||||||
|
required this.onPasteEventInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
final VoidCallback onMockCopy;
|
||||||
|
final Future<void> Function() onPasteEventInfo;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
// _HeaderActionButton(label: 'mock', onPressed: onMockCopy),
|
||||||
|
_HeaderActionButton(
|
||||||
|
label: '粘贴选手信息',
|
||||||
|
onPressed: () => onPasteEventInfo(),
|
||||||
|
icon: Assets.images.imageCopy.image(
|
||||||
|
width: 10.r,
|
||||||
|
height: 10.r,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
excludeFromSemantics: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HeaderActionButton extends StatelessWidget {
|
||||||
|
const _HeaderActionButton({
|
||||||
|
required this.label,
|
||||||
|
required this.onPressed,
|
||||||
|
this.icon,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String label;
|
||||||
|
final VoidCallback onPressed;
|
||||||
|
final Widget? icon;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TextButton.icon(
|
||||||
|
onPressed: onPressed,
|
||||||
|
icon: icon ?? Icon(Icons.content_paste, size: 10.r),
|
||||||
|
label: Text(label),
|
||||||
|
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
minimumSize: Size.zero, // 取消 40dp 最小高度
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap, // 取消额外点击热区
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
backgroundColor: Colors.black.withValues(alpha: 0.5),
|
||||||
|
textStyle: TextStyle(fontSize: 10.sp),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 7.r, vertical: 4.r),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(25.r),
|
||||||
|
side: const BorderSide(color: Colors.white30),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
lib/features/recording/widgets/widget_record_timer.dart
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||||
|
|
||||||
|
class RecordTimerWidget extends ConsumerStatefulWidget {
|
||||||
|
const RecordTimerWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<RecordTimerWidget> createState() => _RecordTimerWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordTimerWidgetState extends ConsumerState<RecordTimerWidget> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final timerState = ref.watch(
|
||||||
|
recordingViewModelProvider.select(
|
||||||
|
(m) => (m.session.isRecording, m.session.elapsedLabel),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final (isRecording, elapsedLabel) = timerState;
|
||||||
|
final displayTime = isRecording ? elapsedLabel : '00:00:00';
|
||||||
|
|
||||||
|
return Positioned(
|
||||||
|
top: 13.r,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Center(
|
||||||
|
child: AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 380),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 5.r, vertical: 0.r),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isRecording ? Colors.red : Colors.transparent,
|
||||||
|
borderRadius: BorderRadius.circular(6.r),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
displayTime,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20.sp,
|
||||||
|
shadows: [Shadow(color: Colors.black54, blurRadius: 6.r)],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
165
lib/features/recording/widgets/widget_recording_button.dart
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import 'dart:ui' show lerpDouble;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
|
/// 录制控制按钮:白圈 + 红色内芯,录制中为圆角矩形。
|
||||||
|
class RecordingControlButton extends StatefulWidget {
|
||||||
|
const RecordingControlButton({
|
||||||
|
super.key,
|
||||||
|
required this.isRecording,
|
||||||
|
required this.onTap,
|
||||||
|
this.isStartingRecording = false,
|
||||||
|
this.enabled = true,
|
||||||
|
this.size,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool isRecording;
|
||||||
|
final bool isStartingRecording;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
final bool enabled;
|
||||||
|
final double? size;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RecordingControlButton> createState() => _RecordingControlButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingControlButtonState extends State<RecordingControlButton>
|
||||||
|
with TickerProviderStateMixin {
|
||||||
|
static const _morphDuration = Duration(milliseconds: 380);
|
||||||
|
static const _pressDownDuration = Duration(milliseconds: 120);
|
||||||
|
static const _pressUpDuration = Duration(milliseconds: 180);
|
||||||
|
|
||||||
|
late final AnimationController _morphController;
|
||||||
|
late final AnimationController _pressController;
|
||||||
|
late final CurvedAnimation _morphAnimation;
|
||||||
|
late final Animation<double> _pressScale;
|
||||||
|
|
||||||
|
bool get _targetIsRecording =>
|
||||||
|
widget.isRecording || widget.isStartingRecording;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_morphController = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: _morphDuration,
|
||||||
|
value: _targetIsRecording ? 1 : 0,
|
||||||
|
);
|
||||||
|
_morphAnimation = CurvedAnimation(
|
||||||
|
parent: _morphController,
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
reverseCurve: Curves.easeInCubic,
|
||||||
|
);
|
||||||
|
_pressController = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: _pressDownDuration,
|
||||||
|
);
|
||||||
|
_pressScale = Tween<double>(begin: 1, end: 0.94).animate(
|
||||||
|
CurvedAnimation(
|
||||||
|
parent: _pressController,
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
reverseCurve: Curves.easeOutBack,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant RecordingControlButton oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
final oldTarget =
|
||||||
|
oldWidget.isRecording || oldWidget.isStartingRecording;
|
||||||
|
final newTarget = _targetIsRecording;
|
||||||
|
if (oldTarget != newTarget) {
|
||||||
|
if (newTarget) {
|
||||||
|
_morphController.forward();
|
||||||
|
} else {
|
||||||
|
_morphController.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_morphAnimation.dispose();
|
||||||
|
_morphController.dispose();
|
||||||
|
_pressController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handlePressDown() {
|
||||||
|
if (!widget.enabled) return;
|
||||||
|
_pressController.duration = _pressDownDuration;
|
||||||
|
_pressController.forward();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handlePressUp() {
|
||||||
|
if (!widget.enabled) return;
|
||||||
|
_pressController.duration = _pressUpDuration;
|
||||||
|
_pressController.reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final buttonSize = widget.size ?? 70.r;
|
||||||
|
final borderWidth = 4.r;
|
||||||
|
final idleInnerSize = 62.r;
|
||||||
|
final recordingInnerSize = 22.r;
|
||||||
|
final idleCornerRadius = idleInnerSize / 2;
|
||||||
|
final recordingCornerRadius = 6.r;
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTapDown: (_) => _handlePressDown(),
|
||||||
|
onTapUp: (_) => _handlePressUp(),
|
||||||
|
onTapCancel: _handlePressUp,
|
||||||
|
onTap: widget.enabled ? widget.onTap : null,
|
||||||
|
child: AnimatedBuilder(
|
||||||
|
animation: Listenable.merge([_morphController, _pressController]),
|
||||||
|
builder: (context, child) {
|
||||||
|
final morph = _morphAnimation.value;
|
||||||
|
|
||||||
|
final innerSize = lerpDouble(
|
||||||
|
idleInnerSize,
|
||||||
|
recordingInnerSize,
|
||||||
|
morph,
|
||||||
|
)!;
|
||||||
|
final cornerRadius = lerpDouble(
|
||||||
|
idleCornerRadius,
|
||||||
|
recordingCornerRadius,
|
||||||
|
morph,
|
||||||
|
)!;
|
||||||
|
|
||||||
|
return Transform.scale(
|
||||||
|
scale: _pressScale.value,
|
||||||
|
child: SizedBox(
|
||||||
|
width: buttonSize,
|
||||||
|
height: buttonSize,
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: buttonSize,
|
||||||
|
height: buttonSize,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(color: Colors.white, width: borderWidth),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: innerSize,
|
||||||
|
height: innerSize,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.red,
|
||||||
|
borderRadius: BorderRadius.circular(cornerRadius),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
|
/// 可点击的提示条组件
|
||||||
|
class RecordingHintChipWidget extends StatelessWidget {
|
||||||
|
const RecordingHintChipWidget({
|
||||||
|
super.key,
|
||||||
|
required this.label,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String label;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 构建提示条 UI
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white12,
|
||||||
|
borderRadius: BorderRadius.circular(8.r),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 12.r, vertical: 8.r),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(color: Colors.white70, fontSize: 12.sp),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Icon(Icons.chevron_right, color: Colors.white54, size: 18.r),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
173
lib/features/recording/widgets/widget_recording_hud.dart
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:recording_tool/core/utils/rate_limiter.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/record_content_transition.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_clipboard_address_clock_chip.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_button.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_setup_hints.dart';
|
||||||
|
|
||||||
|
/// 录制页 HUD 层(状态提示、录制控制)
|
||||||
|
class RecordingHudWidget extends StatelessWidget {
|
||||||
|
const RecordingHudWidget({
|
||||||
|
super.key,
|
||||||
|
this.errorMessage,
|
||||||
|
this.permissionWarning,
|
||||||
|
required this.hasDndAccess,
|
||||||
|
required this.isBatteryOptimizedIgnored,
|
||||||
|
required this.notificationsGranted,
|
||||||
|
required this.isRecording,
|
||||||
|
required this.isStartingRecording,
|
||||||
|
required this.isTouchLocked,
|
||||||
|
this.showClipboardHint = false,
|
||||||
|
this.clipboardAddress = '',
|
||||||
|
required this.onStart,
|
||||||
|
required this.onStop,
|
||||||
|
required this.onOpenDnd,
|
||||||
|
required this.onOpenBattery,
|
||||||
|
required this.onToggleTouchLock,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String? errorMessage;
|
||||||
|
final String? permissionWarning;
|
||||||
|
final bool hasDndAccess;
|
||||||
|
final bool isBatteryOptimizedIgnored;
|
||||||
|
final bool notificationsGranted;
|
||||||
|
final bool isRecording;
|
||||||
|
final bool isStartingRecording;
|
||||||
|
final bool isTouchLocked;
|
||||||
|
final bool showClipboardHint;
|
||||||
|
final String clipboardAddress;
|
||||||
|
final Future<void> Function() onStart;
|
||||||
|
final Future<void> Function() onStop;
|
||||||
|
final VoidCallback onOpenDnd;
|
||||||
|
final VoidCallback onOpenBattery;
|
||||||
|
final VoidCallback onToggleTouchLock;
|
||||||
|
|
||||||
|
static double get _recordButtonSize => 70.r;
|
||||||
|
static double get _recordButtonBottom => 63.r;
|
||||||
|
static double get _overlayInfoLeft => 13.r;
|
||||||
|
static double get _overlayInfoBottom => 10.r;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Stack(
|
||||||
|
fit: StackFit.expand,
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
bottom: _recordButtonBottom + _recordButtonSize + 16.h,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 8.h),
|
||||||
|
const Spacer(),
|
||||||
|
if (errorMessage != null)
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(12.r),
|
||||||
|
child: Text(
|
||||||
|
errorMessage!,
|
||||||
|
style: const TextStyle(color: Colors.amber),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (permissionWarning != null)
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 16.r,
|
||||||
|
vertical: 8.r,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
permissionWarning!,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.orangeAccent,
|
||||||
|
fontSize: 12.sp,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
RecordingSetupHintsWidget(
|
||||||
|
hasDndAccess: hasDndAccess,
|
||||||
|
isBatteryIgnored: isBatteryOptimizedIgnored,
|
||||||
|
notificationsGranted: notificationsGranted,
|
||||||
|
onOpenDnd: onOpenDnd,
|
||||||
|
onOpenBattery: onOpenBattery,
|
||||||
|
onOpenNotificationSettings: openAppSettings,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
left: _overlayInfoLeft,
|
||||||
|
bottom: _overlayInfoBottom,
|
||||||
|
child: AnimatedSwitcher(
|
||||||
|
duration: RecordContentTransition.duration,
|
||||||
|
switchInCurve: Curves.easeOutCubic,
|
||||||
|
switchOutCurve: Curves.easeInCubic,
|
||||||
|
layoutBuilder: RecordContentTransition.bottomStackLayoutBuilder,
|
||||||
|
transitionBuilder: RecordContentTransition.builder,
|
||||||
|
child: showClipboardHint
|
||||||
|
? ClipboardAddressClockChipWidget(
|
||||||
|
key: const ValueKey('clipboard-info'),
|
||||||
|
address: clipboardAddress,
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(key: ValueKey('clipboard-info-hidden')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (isRecording)
|
||||||
|
Positioned(
|
||||||
|
left: 16.r,
|
||||||
|
bottom: _recordButtonBottom,
|
||||||
|
child: SizedBox(
|
||||||
|
height: _recordButtonSize,
|
||||||
|
child: Center(
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: onToggleTouchLock,
|
||||||
|
icon: Icon(
|
||||||
|
isTouchLocked ? Icons.lock : Icons.lock_open,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 28.r,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: _recordButtonBottom,
|
||||||
|
child: Center(
|
||||||
|
child: RecordingControlButton(
|
||||||
|
isRecording: isRecording,
|
||||||
|
isStartingRecording: isStartingRecording,
|
||||||
|
enabled: !isStartingRecording,
|
||||||
|
size: _recordButtonSize,
|
||||||
|
onTap: () {
|
||||||
|
if (isRecording) {
|
||||||
|
RateLimit.instance.debounce<void>(
|
||||||
|
key: 'recording.session.stop',
|
||||||
|
value: null,
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
|
onCallback: (_) async {
|
||||||
|
await onStop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
RateLimit.instance.debounce<void>(
|
||||||
|
key: 'recording.session.start',
|
||||||
|
value: null,
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
|
onCallback: (_) async {
|
||||||
|
await onStart();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
|
/// 录制加载遮罩(相机启动/开始录制)
|
||||||
|
class RecordingLoadingOverlayWidget extends StatelessWidget {
|
||||||
|
const RecordingLoadingOverlayWidget({
|
||||||
|
super.key,
|
||||||
|
required this.message,
|
||||||
|
this.backgroundColor = Colors.black,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
final Color backgroundColor;
|
||||||
|
|
||||||
|
@override
|
||||||
|
/// 显示加载动画与提示文案
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ColoredBox(
|
||||||
|
color: backgroundColor,
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
SizedBox.square(
|
||||||
|
dimension: 32.r,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2.5.r,
|
||||||
|
color: Colors.white70,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 14.h),
|
||||||
|
Text(
|
||||||
|
message,
|
||||||
|
style: TextStyle(color: Colors.white70, fontSize: 14.sp),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:recording_tool/features/dialog/dialog-record.dart';
|
||||||
|
|
||||||
|
/// 录制结束并保存到相册后的后续操作弹窗。
|
||||||
|
Future<void> showRecordingSavedDialog(
|
||||||
|
BuildContext context, {
|
||||||
|
required String sessionTitle,
|
||||||
|
required VoidCallback onContinueRound,
|
||||||
|
required VoidCallback onRecordNewRound,
|
||||||
|
}) {
|
||||||
|
return RecordDialog.showDouble(
|
||||||
|
context,
|
||||||
|
title: '本轮比赛视频已保存到相册\n请选择后续录制信息',
|
||||||
|
leftText: '继续本轮',
|
||||||
|
rightText: '录制新轮',
|
||||||
|
onLeftPressed: onContinueRound,
|
||||||
|
onRightPressed: onRecordNewRound,
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_hint_chip.dart';
|
||||||
|
|
||||||
|
/// 权限相关设置提示条
|
||||||
|
class RecordingSetupHintsWidget extends StatelessWidget {
|
||||||
|
const RecordingSetupHintsWidget({
|
||||||
|
super.key,
|
||||||
|
required this.hasDndAccess,
|
||||||
|
required this.isBatteryIgnored,
|
||||||
|
required this.notificationsGranted,
|
||||||
|
required this.onOpenDnd,
|
||||||
|
required this.onOpenBattery,
|
||||||
|
required this.onOpenNotificationSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool hasDndAccess;
|
||||||
|
final bool isBatteryIgnored;
|
||||||
|
final bool notificationsGranted;
|
||||||
|
final VoidCallback onOpenDnd;
|
||||||
|
final VoidCallback onOpenBattery;
|
||||||
|
final VoidCallback onOpenNotificationSettings;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final showPermissionHints =
|
||||||
|
!hasDndAccess || !isBatteryIgnored || !notificationsGranted;
|
||||||
|
if (!showPermissionHints) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16.r, vertical: 8.r),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
if (!notificationsGranted) ...[
|
||||||
|
RecordingHintChipWidget(
|
||||||
|
label: '开启通知权限以显示录制前台服务',
|
||||||
|
onTap: onOpenNotificationSettings,
|
||||||
|
),
|
||||||
|
SizedBox(height: 8.h),
|
||||||
|
],
|
||||||
|
if (!hasDndAccess)
|
||||||
|
RecordingHintChipWidget(label: '开启勿扰权限可减少录制中断', onTap: onOpenDnd),
|
||||||
|
if (!isBatteryIgnored) ...[
|
||||||
|
SizedBox(height: 8.h),
|
||||||
|
RecordingHintChipWidget(
|
||||||
|
label: '关闭电池优化可提升息屏续录稳定性',
|
||||||
|
onTap: onOpenBattery,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
|
||||||
|
enum RecordingTouchLockUnlockIntent { unlockOnly, stopRecording }
|
||||||
|
|
||||||
|
RecordingTouchLockUnlockIntent resolveRecordingTouchLockUnlockIntent({
|
||||||
|
required Offset position,
|
||||||
|
required Size size,
|
||||||
|
double stopZoneFraction = 0.3,
|
||||||
|
}) {
|
||||||
|
if (size.width <= 0 || size.height <= 0 || stopZoneFraction <= 0) {
|
||||||
|
return RecordingTouchLockUnlockIntent.unlockOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
final normalizedStopZone = stopZoneFraction.clamp(0.0, 1.0);
|
||||||
|
if (size.width <= size.height) {
|
||||||
|
final stopZoneTop = size.height * (1 - normalizedStopZone);
|
||||||
|
return position.dy >= stopZoneTop
|
||||||
|
? RecordingTouchLockUnlockIntent.stopRecording
|
||||||
|
: RecordingTouchLockUnlockIntent.unlockOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
final stopZoneLeft = size.width * (1 - normalizedStopZone);
|
||||||
|
return position.dx >= stopZoneLeft
|
||||||
|
? RecordingTouchLockUnlockIntent.stopRecording
|
||||||
|
: RecordingTouchLockUnlockIntent.unlockOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecordingTouchLockOverlayWidget extends StatefulWidget {
|
||||||
|
const RecordingTouchLockOverlayWidget({
|
||||||
|
super.key,
|
||||||
|
required this.enabled,
|
||||||
|
required this.onUnlocked,
|
||||||
|
this.unlockHoldDuration = const Duration(seconds: 2),
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool enabled;
|
||||||
|
final ValueChanged<RecordingTouchLockUnlockIntent> onUnlocked;
|
||||||
|
final Duration unlockHoldDuration;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RecordingTouchLockOverlayWidget> createState() =>
|
||||||
|
_RecordingTouchLockOverlayWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RecordingTouchLockOverlayWidgetState
|
||||||
|
extends State<RecordingTouchLockOverlayWidget> {
|
||||||
|
Timer? _holdTimer;
|
||||||
|
bool _isHolding = false;
|
||||||
|
int? _remainingSeconds;
|
||||||
|
Offset? _holdStartPosition;
|
||||||
|
Size? _holdStartSize;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(RecordingTouchLockOverlayWidget oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (!widget.enabled) {
|
||||||
|
_cancelHold();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_holdTimer?.cancel();
|
||||||
|
_holdTimer = null;
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _cancelHold() {
|
||||||
|
_holdTimer?.cancel();
|
||||||
|
_holdTimer = null;
|
||||||
|
if (!_isHolding && _remainingSeconds == null) return;
|
||||||
|
setState(() {
|
||||||
|
_isHolding = false;
|
||||||
|
_remainingSeconds = null;
|
||||||
|
_holdStartPosition = null;
|
||||||
|
_holdStartSize = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startHold(Offset position, Size size) {
|
||||||
|
if (!widget.enabled) return;
|
||||||
|
final totalSeconds = widget.unlockHoldDuration.inSeconds;
|
||||||
|
_holdTimer?.cancel();
|
||||||
|
setState(() {
|
||||||
|
_isHolding = true;
|
||||||
|
_remainingSeconds = totalSeconds;
|
||||||
|
_holdStartPosition = position;
|
||||||
|
_holdStartSize = size;
|
||||||
|
});
|
||||||
|
|
||||||
|
var elapsed = 0;
|
||||||
|
_holdTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
|
elapsed += 1;
|
||||||
|
if (!mounted) {
|
||||||
|
timer.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (elapsed >= totalSeconds) {
|
||||||
|
timer.cancel();
|
||||||
|
_holdTimer = null;
|
||||||
|
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||||
|
position: _holdStartPosition ?? Offset.zero,
|
||||||
|
size: _holdStartSize ?? Size.zero,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_isHolding = false;
|
||||||
|
_remainingSeconds = null;
|
||||||
|
_holdStartPosition = null;
|
||||||
|
_holdStartSize = null;
|
||||||
|
});
|
||||||
|
widget.onUnlocked(intent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() => _remainingSeconds = totalSeconds - elapsed);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (!widget.enabled) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Positioned.fill(
|
||||||
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final overlaySize = Size(constraints.maxWidth, constraints.maxHeight);
|
||||||
|
return Listener(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onPointerDown: (event) =>
|
||||||
|
_startHold(event.localPosition, overlaySize),
|
||||||
|
onPointerUp: (_) => _cancelHold(),
|
||||||
|
onPointerCancel: (_) => _cancelHold(),
|
||||||
|
child: ColoredBox(
|
||||||
|
color: Colors.black.withValues(alpha: 0.01),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(top: 68.r),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black54,
|
||||||
|
borderRadius: BorderRadius.circular(24.r),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 16.r,
|
||||||
|
vertical: 8.r,
|
||||||
|
),
|
||||||
|
child: _isHolding && _remainingSeconds != null
|
||||||
|
? Builder(
|
||||||
|
builder: (context) {
|
||||||
|
final remainingSeconds = _remainingSeconds!;
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
AnimatedSwitcher(
|
||||||
|
duration: const Duration(
|
||||||
|
milliseconds: 280,
|
||||||
|
),
|
||||||
|
switchInCurve: Curves.easeOut,
|
||||||
|
switchOutCurve: Curves.easeIn,
|
||||||
|
transitionBuilder: (child, animation) {
|
||||||
|
return ScaleTransition(
|
||||||
|
scale: Tween<double>(
|
||||||
|
begin: 0.6,
|
||||||
|
end: 1,
|
||||||
|
).animate(animation),
|
||||||
|
child: FadeTransition(
|
||||||
|
opacity: animation,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'${remainingSeconds}s',
|
||||||
|
key: ValueKey<int>(remainingSeconds),
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 18.sp,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
height: 1.1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 2.r),
|
||||||
|
Text(
|
||||||
|
'保持按住解锁',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white70,
|
||||||
|
fontSize: 10.sp,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
'防误触已开启,按住 ${widget.unlockHoldDuration.inSeconds}s 解锁',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 10.sp,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
134
lib/gen/assets.gen.dart
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
// dart format width=80
|
||||||
|
|
||||||
|
/// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
/// *****************************************************
|
||||||
|
/// FlutterGen
|
||||||
|
/// *****************************************************
|
||||||
|
|
||||||
|
// coverage:ignore-file
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import
|
||||||
|
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
class $AssetsImagesGen {
|
||||||
|
const $AssetsImagesGen();
|
||||||
|
|
||||||
|
/// File path: assets/images/image_copy.png
|
||||||
|
AssetGenImage get imageCopy =>
|
||||||
|
const AssetGenImage('assets/images/image_copy.png');
|
||||||
|
|
||||||
|
/// File path: assets/images/image_delete.png
|
||||||
|
AssetGenImage get imageDelete =>
|
||||||
|
const AssetGenImage('assets/images/image_delete.png');
|
||||||
|
|
||||||
|
/// File path: assets/images/image_dialog_bg.png
|
||||||
|
AssetGenImage get imageDialogBg =>
|
||||||
|
const AssetGenImage('assets/images/image_dialog_bg.png');
|
||||||
|
|
||||||
|
/// File path: assets/images/image_logo.png
|
||||||
|
AssetGenImage get imageLogo =>
|
||||||
|
const AssetGenImage('assets/images/image_logo.png');
|
||||||
|
|
||||||
|
/// List of all assets
|
||||||
|
List<AssetGenImage> get values => [
|
||||||
|
imageCopy,
|
||||||
|
imageDelete,
|
||||||
|
imageDialogBg,
|
||||||
|
imageLogo,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
class Assets {
|
||||||
|
const Assets._();
|
||||||
|
|
||||||
|
static const $AssetsImagesGen images = $AssetsImagesGen();
|
||||||
|
}
|
||||||
|
|
||||||
|
class AssetGenImage {
|
||||||
|
const AssetGenImage(
|
||||||
|
this._assetName, {
|
||||||
|
this.size,
|
||||||
|
this.flavors = const {},
|
||||||
|
this.animation,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String _assetName;
|
||||||
|
|
||||||
|
final Size? size;
|
||||||
|
final Set<String> flavors;
|
||||||
|
final AssetGenImageAnimation? animation;
|
||||||
|
|
||||||
|
Image image({
|
||||||
|
Key? key,
|
||||||
|
AssetBundle? bundle,
|
||||||
|
ImageFrameBuilder? frameBuilder,
|
||||||
|
ImageErrorWidgetBuilder? errorBuilder,
|
||||||
|
String? semanticLabel,
|
||||||
|
bool excludeFromSemantics = false,
|
||||||
|
double? scale,
|
||||||
|
double? width,
|
||||||
|
double? height,
|
||||||
|
Color? color,
|
||||||
|
Animation<double>? opacity,
|
||||||
|
BlendMode? colorBlendMode,
|
||||||
|
BoxFit? fit,
|
||||||
|
AlignmentGeometry alignment = Alignment.center,
|
||||||
|
ImageRepeat repeat = ImageRepeat.noRepeat,
|
||||||
|
Rect? centerSlice,
|
||||||
|
bool matchTextDirection = false,
|
||||||
|
bool gaplessPlayback = true,
|
||||||
|
bool isAntiAlias = false,
|
||||||
|
String? package,
|
||||||
|
FilterQuality filterQuality = FilterQuality.medium,
|
||||||
|
int? cacheWidth,
|
||||||
|
int? cacheHeight,
|
||||||
|
}) {
|
||||||
|
return Image.asset(
|
||||||
|
_assetName,
|
||||||
|
key: key,
|
||||||
|
bundle: bundle,
|
||||||
|
frameBuilder: frameBuilder,
|
||||||
|
errorBuilder: errorBuilder,
|
||||||
|
semanticLabel: semanticLabel,
|
||||||
|
excludeFromSemantics: excludeFromSemantics,
|
||||||
|
scale: scale,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
color: color,
|
||||||
|
opacity: opacity,
|
||||||
|
colorBlendMode: colorBlendMode,
|
||||||
|
fit: fit,
|
||||||
|
alignment: alignment,
|
||||||
|
repeat: repeat,
|
||||||
|
centerSlice: centerSlice,
|
||||||
|
matchTextDirection: matchTextDirection,
|
||||||
|
gaplessPlayback: gaplessPlayback,
|
||||||
|
isAntiAlias: isAntiAlias,
|
||||||
|
package: package,
|
||||||
|
filterQuality: filterQuality,
|
||||||
|
cacheWidth: cacheWidth,
|
||||||
|
cacheHeight: cacheHeight,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageProvider provider({AssetBundle? bundle, String? package}) {
|
||||||
|
return AssetImage(_assetName, bundle: bundle, package: package);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get path => _assetName;
|
||||||
|
|
||||||
|
String get keyName => _assetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AssetGenImageAnimation {
|
||||||
|
const AssetGenImageAnimation({
|
||||||
|
required this.isAnimation,
|
||||||
|
required this.duration,
|
||||||
|
required this.frames,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool isAnimation;
|
||||||
|
final Duration duration;
|
||||||
|
final int frames;
|
||||||
|
}
|
||||||
@@ -30,4 +30,24 @@ class AppDialog {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> deviceHealthAlert(
|
||||||
|
BuildContext context, {
|
||||||
|
required List<String> lines,
|
||||||
|
}) {
|
||||||
|
return showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return AlertDialog(
|
||||||
|
content: Text(lines.join('\n')),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||||
|
child: const Text('确定'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1079
pubspec.lock
11
pubspec.yaml
@@ -58,6 +58,8 @@ dev_dependencies:
|
|||||||
# package. See that file for information about deactivating specific lint
|
# package. See that file for information about deactivating specific lint
|
||||||
# rules and activating additional ones.
|
# rules and activating additional ones.
|
||||||
flutter_lints: ^6.0.0
|
flutter_lints: ^6.0.0
|
||||||
|
build_runner: ^2.15.0
|
||||||
|
flutter_gen_runner: ^5.14.1
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
@@ -68,7 +70,11 @@ flutter:
|
|||||||
# included with your application, so that you can use the icons in
|
# included with your application, so that you can use the icons in
|
||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
generate: true
|
||||||
|
|
||||||
|
# To add assets to your application, add an assets section, like this:
|
||||||
|
assets:
|
||||||
|
- assets/images/
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
@@ -99,3 +105,8 @@ flutter:
|
|||||||
#
|
#
|
||||||
# For details regarding fonts from package dependencies,
|
# For details regarding fonts from package dependencies,
|
||||||
# see https://flutter.dev/to/font-from-package
|
# see https://flutter.dev/to/font-from-package
|
||||||
|
|
||||||
|
flutter_gen:
|
||||||
|
output: lib/gen/
|
||||||
|
integrations:
|
||||||
|
flutter_svg: true
|
||||||
|
|||||||
88
test/core/platform/device_health_checker_test.dart
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:recording_tool/core/platform/device_health_checker.dart';
|
||||||
|
import 'package:recording_tool/core/platform/device_health_snapshot.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('DeviceHealthChecker.warningLines', () {
|
||||||
|
test('returns empty when battery and storage are healthy', () {
|
||||||
|
const snapshot = DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: 50,
|
||||||
|
storageAvailablePercent: 50,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(DeviceHealthChecker.warningLines(snapshot), isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns low battery message only', () {
|
||||||
|
const snapshot = DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: 9,
|
||||||
|
storageAvailablePercent: 50,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
DeviceHealthChecker.warningLines(snapshot),
|
||||||
|
[DeviceHealthChecker.lowBatteryMessage],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns low storage message only', () {
|
||||||
|
const snapshot = DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: 50,
|
||||||
|
storageAvailablePercent: 9.9,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
DeviceHealthChecker.warningLines(snapshot),
|
||||||
|
[DeviceHealthChecker.lowStorageMessage],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns both messages when battery and storage are low', () {
|
||||||
|
const snapshot = DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: 5,
|
||||||
|
storageAvailablePercent: 5,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
DeviceHealthChecker.warningLines(snapshot),
|
||||||
|
[
|
||||||
|
DeviceHealthChecker.lowBatteryMessage,
|
||||||
|
DeviceHealthChecker.lowStorageMessage,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not warn at exactly threshold percent', () {
|
||||||
|
const snapshot = DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: 10,
|
||||||
|
storageAvailablePercent: 10,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(DeviceHealthChecker.warningLines(snapshot), isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('skips battery warning when level is unknown', () {
|
||||||
|
const snapshot = DeviceHealthSnapshot(
|
||||||
|
batteryLevelPercent: null,
|
||||||
|
storageAvailablePercent: 5,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
DeviceHealthChecker.warningLines(snapshot),
|
||||||
|
[DeviceHealthChecker.lowStorageMessage],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('DeviceHealthSnapshot.fromMap', () {
|
||||||
|
test('parses native map fields', () {
|
||||||
|
final snapshot = DeviceHealthSnapshot.fromMap({
|
||||||
|
'batteryLevelPercent': 42,
|
||||||
|
'storageAvailablePercent': 12.5,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(snapshot.batteryLevelPercent, 42);
|
||||||
|
expect(snapshot.storageAvailablePercent, 12.5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
130
test/features/dialog/record_dialog_test.dart
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:recording_tool/features/dialog/dialog-record.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_saved_dialog.dart';
|
||||||
|
import 'package:recording_tool/gen/assets.gen.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
Future<void> pumpDialogHost(WidgetTester tester, Widget child) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
ScreenUtilInit(
|
||||||
|
designSize: const Size(375, 812),
|
||||||
|
builder: (context, _) {
|
||||||
|
return MaterialApp(home: Scaffold(body: child));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('single button dialog shows configured content and closes', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
var tapped = false;
|
||||||
|
|
||||||
|
await pumpDialogHost(
|
||||||
|
tester,
|
||||||
|
Builder(
|
||||||
|
builder: (context) {
|
||||||
|
return TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
RecordDialog.showSingle(
|
||||||
|
context,
|
||||||
|
title: '无选手信息!',
|
||||||
|
buttonText: '粘贴',
|
||||||
|
onPressed: () => tapped = true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('show'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.text('show'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.byType(Image), findsOneWidget);
|
||||||
|
expect(find.image(AssetImage(Assets.images.imageDialogBg.path)), findsOne);
|
||||||
|
expect(find.text('无选手信息!'), findsOneWidget);
|
||||||
|
expect(find.text('粘贴'), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(find.text('粘贴'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(tapped, isTrue);
|
||||||
|
expect(find.text('无选手信息!'), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('double button dialog dispatches each action', (tester) async {
|
||||||
|
var leftTapped = false;
|
||||||
|
var rightTapped = false;
|
||||||
|
|
||||||
|
await pumpDialogHost(
|
||||||
|
tester,
|
||||||
|
Builder(
|
||||||
|
builder: (context) {
|
||||||
|
return TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
RecordDialog.showDouble(
|
||||||
|
context,
|
||||||
|
title: '本轮比赛视频已保存到相册\n请选择后续录制信息',
|
||||||
|
leftText: '继续本轮',
|
||||||
|
rightText: '录制新轮',
|
||||||
|
onLeftPressed: () => leftTapped = true,
|
||||||
|
onRightPressed: () => rightTapped = true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('show'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.text('show'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('继续本轮'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(leftTapped, isTrue);
|
||||||
|
expect(rightTapped, isFalse);
|
||||||
|
|
||||||
|
await tester.tap(find.text('show'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('录制新轮'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(rightTapped, isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('recording saved dialog follows design title only', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpDialogHost(
|
||||||
|
tester,
|
||||||
|
Builder(
|
||||||
|
builder: (context) {
|
||||||
|
return TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
showRecordingSavedDialog(
|
||||||
|
context,
|
||||||
|
sessionTitle: '王东方 丨李想 空中格斗赛',
|
||||||
|
onContinueRound: () {},
|
||||||
|
onRecordNewRound: () {},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('show'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.text('show'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('王东方 丨李想 空中格斗赛'), findsNothing);
|
||||||
|
expect(find.text('本轮比赛视频已保存到相册\n请选择后续录制信息'), findsOneWidget);
|
||||||
|
expect(find.text('继续本轮'), findsOneWidget);
|
||||||
|
expect(find.text('录制新轮'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -21,6 +21,21 @@ void main() {
|
|||||||
expect(model.toJson(), clipboardJson);
|
expect(model.toJson(), clipboardJson);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('parses JSON without optional timestamps', () {
|
||||||
|
final json = {
|
||||||
|
'title': '郑昌梦 丨黄伟依 空中格斗赛 小学组',
|
||||||
|
'address': '广东省汕头市番禺区青蓝街 111 号',
|
||||||
|
'filename': '郑昌梦_黄伟依_6月3日测试-1_空中格斗赛',
|
||||||
|
};
|
||||||
|
final model = ClipboardRecordingModel.fromJson(json);
|
||||||
|
|
||||||
|
expect(model.title, json['title']);
|
||||||
|
expect(model.address, json['address']);
|
||||||
|
expect(model.filename, json['filename']);
|
||||||
|
expect(model.startTimestamp, isNull);
|
||||||
|
expect(model.endTimestamp, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
test('parses optional filename from mini program JSON', () {
|
test('parses optional filename from mini program JSON', () {
|
||||||
final json = {
|
final json = {
|
||||||
...clipboardJson,
|
...clipboardJson,
|
||||||
@@ -41,7 +56,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws FormatException when required field has wrong type', () {
|
test('throws FormatException when optional int field has wrong type', () {
|
||||||
final json = {...clipboardJson, 'startTimestamp': '1717334400'};
|
final json = {...clipboardJson, 'startTimestamp': '1717334400'};
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -49,5 +64,14 @@ void main() {
|
|||||||
throwsA(isA<FormatException>()),
|
throwsA(isA<FormatException>()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('throws FormatException when required address is missing', () {
|
||||||
|
final json = Map<String, dynamic>.from(clipboardJson)..remove('address');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => ClipboardRecordingModel.fromJson(json),
|
||||||
|
throwsA(isA<FormatException>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:recording_tool/features/recording/recording_display_name.dart';
|
import 'package:recording_tool/features/recording/utils/recording_display_name.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('sanitizeRecordingBaseName', () {
|
group('sanitizeRecordingBaseName', () {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:recording_tool/features/recording/recording_platform.dart';
|
import 'package:recording_tool/features/recording/platform/recording_platform.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('RecordingPlatform support', () {
|
group('RecordingPlatform support', () {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
import 'package:recording_tool/features/recording/view-model/view_model_recording.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -25,6 +26,40 @@ void main() {
|
|||||||
.setMockMethodCallHandler(SystemChannels.platform, null);
|
.setMockMethodCallHandler(SystemChannels.platform, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('RecordingViewModel', () {
|
||||||
|
test('initializes with default clipboard and session state', () {
|
||||||
|
final container = ProviderContainer();
|
||||||
|
addTearDown(container.dispose);
|
||||||
|
|
||||||
|
final model = container.read(recordingViewModelProvider);
|
||||||
|
expect(model.hasValidClipboardInfo, isFalse);
|
||||||
|
expect(model.clipboardRecordingModel.title, defaultClipboardTitle);
|
||||||
|
expect(model.session.isPreviewReady, isFalse);
|
||||||
|
expect(model.session.isRecording, isFalse);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('recordingGalleryPermissionsForHost', () {
|
||||||
|
test('requests only add-only photo permission on iOS', () {
|
||||||
|
final permissions = recordingGalleryPermissionsForHost(
|
||||||
|
isIOS: true,
|
||||||
|
isAndroid: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(permissions, <Permission>[Permission.photosAddOnly]);
|
||||||
|
expect(permissions, isNot(contains(Permission.photos)));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('keeps Android gallery permissions unchanged', () {
|
||||||
|
final permissions = recordingGalleryPermissionsForHost(
|
||||||
|
isIOS: false,
|
||||||
|
isAndroid: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(permissions, <Permission>[Permission.videos, Permission.storage]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
group('RecordingViewModel.getClipboardContent', () {
|
group('RecordingViewModel.getClipboardContent', () {
|
||||||
test(
|
test(
|
||||||
'updates state when clipboard contains valid mini program JSON',
|
'updates state when clipboard contains valid mini program JSON',
|
||||||
@@ -43,14 +78,8 @@ void main() {
|
|||||||
expect(model.clipboardRecordingModel.title, '王东方 丨李想 空中格斗赛');
|
expect(model.clipboardRecordingModel.title, '王东方 丨李想 空中格斗赛');
|
||||||
expect(model.clipboardRecordingModel.startTimestamp, 1717334400);
|
expect(model.clipboardRecordingModel.startTimestamp, 1717334400);
|
||||||
expect(model.clipboardRecordingModel.endTimestamp, 1717334400);
|
expect(model.clipboardRecordingModel.endTimestamp, 1717334400);
|
||||||
expect(
|
expect(model.clipboardRecordingModel.address, '广州市番禺区·粤港澳大湾区青年人才双创小镇');
|
||||||
model.clipboardRecordingModel.address,
|
expect(model.clipboardRecordingModel.filename, '选手名称_选手ID_赛事名称_赛项');
|
||||||
'广州市番禺区·粤港澳大湾区青年人才双创小镇',
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
model.clipboardRecordingModel.filename,
|
|
||||||
'选手名称_选手ID_赛事名称_赛项',
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -80,7 +109,10 @@ void main() {
|
|||||||
|
|
||||||
expect(result, ClipboardReadResult.invalid);
|
expect(result, ClipboardReadResult.invalid);
|
||||||
expect(
|
expect(
|
||||||
container.read(recordingViewModelProvider).clipboardRecordingModel.title,
|
container
|
||||||
|
.read(recordingViewModelProvider)
|
||||||
|
.clipboardRecordingModel
|
||||||
|
.title,
|
||||||
defaultClipboardTitle,
|
defaultClipboardTitle,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
@@ -100,12 +132,17 @@ void main() {
|
|||||||
|
|
||||||
expect(result, ClipboardReadResult.invalid);
|
expect(result, ClipboardReadResult.invalid);
|
||||||
expect(
|
expect(
|
||||||
container.read(recordingViewModelProvider).clipboardRecordingModel.title,
|
container
|
||||||
|
.read(recordingViewModelProvider)
|
||||||
|
.clipboardRecordingModel
|
||||||
|
.title,
|
||||||
defaultClipboardTitle,
|
defaultClipboardTitle,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns invalid when clipboard JSON misses required fields', () async {
|
test(
|
||||||
|
'returns invalid when clipboard JSON misses required address',
|
||||||
|
() async {
|
||||||
await setClipboardText('{"title":"王东方 丨李想 空中格斗赛"}');
|
await setClipboardText('{"title":"王东方 丨李想 空中格斗赛"}');
|
||||||
final container = ProviderContainer();
|
final container = ProviderContainer();
|
||||||
addTearDown(container.dispose);
|
addTearDown(container.dispose);
|
||||||
@@ -116,9 +153,32 @@ void main() {
|
|||||||
|
|
||||||
expect(result, ClipboardReadResult.invalid);
|
expect(result, ClipboardReadResult.invalid);
|
||||||
expect(
|
expect(
|
||||||
container.read(recordingViewModelProvider).clipboardRecordingModel.title,
|
container
|
||||||
|
.read(recordingViewModelProvider)
|
||||||
|
.clipboardRecordingModel
|
||||||
|
.title,
|
||||||
defaultClipboardTitle,
|
defaultClipboardTitle,
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('updates state when clipboard omits optional timestamps', () async {
|
||||||
|
await setClipboardText(
|
||||||
|
'{"title":"郑昌梦 丨黄伟依 空中格斗赛 小学组","address":"广东省汕头市番禺区青蓝街 111 号","filename":"郑昌梦_黄伟依_6月3日测试-1_空中格斗赛"}',
|
||||||
|
);
|
||||||
|
final container = ProviderContainer();
|
||||||
|
addTearDown(container.dispose);
|
||||||
|
|
||||||
|
final result = await container
|
||||||
|
.read(recordingViewModelProvider.notifier)
|
||||||
|
.getClipboardContent();
|
||||||
|
|
||||||
|
expect(result, ClipboardReadResult.success);
|
||||||
|
final model = container.read(recordingViewModelProvider);
|
||||||
|
expect(model.hasValidClipboardInfo, isTrue);
|
||||||
|
expect(model.clipboardRecordingModel.startTimestamp, isNull);
|
||||||
|
expect(model.clipboardRecordingModel.endTimestamp, isNull);
|
||||||
|
expect(model.clipboardRecordingModel.filename, '郑昌梦_黄伟依_6月3日测试-1_空中格斗赛');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('returns invalid when clipboard JSON has wrong field type', () async {
|
test('returns invalid when clipboard JSON has wrong field type', () async {
|
||||||
@@ -134,7 +194,10 @@ void main() {
|
|||||||
|
|
||||||
expect(result, ClipboardReadResult.invalid);
|
expect(result, ClipboardReadResult.invalid);
|
||||||
expect(
|
expect(
|
||||||
container.read(recordingViewModelProvider).clipboardRecordingModel.title,
|
container
|
||||||
|
.read(recordingViewModelProvider)
|
||||||
|
.clipboardRecordingModel
|
||||||
|
.title,
|
||||||
defaultClipboardTitle,
|
defaultClipboardTitle,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
52
test/features/recording/widget_record_header_test.dart
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_record_header.dart';
|
||||||
|
import 'package:recording_tool/gen/assets.gen.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
Future<void> pumpHeader(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required bool hasValidClipboardInfo,
|
||||||
|
String? eventTitle,
|
||||||
|
}) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
ScreenUtilInit(
|
||||||
|
designSize: const Size(375, 812),
|
||||||
|
builder: (context, _) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: RecordHeaderWidget(
|
||||||
|
hasValidClipboardInfo: hasValidClipboardInfo,
|
||||||
|
eventTitle: eventTitle,
|
||||||
|
isRecording: false,
|
||||||
|
onPasteEventInfo: () async {},
|
||||||
|
onClearEventInfo: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('paste player info button uses copy image asset', (tester) async {
|
||||||
|
await pumpHeader(tester, hasValidClipboardInfo: false);
|
||||||
|
|
||||||
|
expect(find.text('粘贴选手信息'), findsOneWidget);
|
||||||
|
expect(find.image(AssetImage(Assets.images.imageCopy.path)), findsOne);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('clear player info button uses delete image asset', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpHeader(
|
||||||
|
tester,
|
||||||
|
hasValidClipboardInfo: true,
|
||||||
|
eventTitle: '王东方 丨李想 空中格斗赛',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.text('王东方 丨李想 空中格斗赛'), findsOneWidget);
|
||||||
|
expect(find.image(AssetImage(Assets.images.imageDelete.path)), findsOne);
|
||||||
|
});
|
||||||
|
}
|
||||||
138
test/features/recording/widget_recording_button_test.dart
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_button.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
const designSize = Size(375, 812);
|
||||||
|
const morphDuration = Duration(milliseconds: 380);
|
||||||
|
|
||||||
|
Future<void> pumpButton(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required bool isRecording,
|
||||||
|
bool isStartingRecording = false,
|
||||||
|
}) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
ScreenUtilInit(
|
||||||
|
designSize: designSize,
|
||||||
|
builder: (context, _) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: RecordingControlButton(
|
||||||
|
isRecording: isRecording,
|
||||||
|
isStartingRecording: isStartingRecording,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
|
|
||||||
|
Size innerCoreSize(WidgetTester tester) {
|
||||||
|
final finder = find.byWidgetPredicate(
|
||||||
|
(widget) =>
|
||||||
|
widget is Container &&
|
||||||
|
widget.decoration is BoxDecoration &&
|
||||||
|
(widget.decoration! as BoxDecoration).color == Colors.red,
|
||||||
|
);
|
||||||
|
return tester.getSize(finder);
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('idle state uses large circular inner core', (tester) async {
|
||||||
|
await pumpButton(tester, isRecording: false);
|
||||||
|
|
||||||
|
final size = innerCoreSize(tester);
|
||||||
|
expect(size.width, closeTo(62.r, 0.5));
|
||||||
|
expect(size.height, closeTo(62.r, 0.5));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('isStartingRecording morphs to stop square before isRecording', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpButton(
|
||||||
|
tester,
|
||||||
|
isRecording: false,
|
||||||
|
isStartingRecording: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pump(morphDuration);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
final size = innerCoreSize(tester);
|
||||||
|
expect(size.width, closeTo(22.r, 0.5));
|
||||||
|
expect(size.height, closeTo(22.r, 0.5));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('isRecording forward and reverse morph without errors', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await pumpButton(tester, isRecording: false);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
ScreenUtilInit(
|
||||||
|
designSize: designSize,
|
||||||
|
builder: (context, _) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: RecordingControlButton(
|
||||||
|
isRecording: true,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pump(morphDuration);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(innerCoreSize(tester).width, closeTo(22.r, 0.5));
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
ScreenUtilInit(
|
||||||
|
designSize: designSize,
|
||||||
|
builder: (context, _) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: RecordingControlButton(
|
||||||
|
isRecording: false,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pump(morphDuration);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(innerCoreSize(tester).width, closeTo(62.r, 0.5));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('failed start rolls morph back to idle circle', (tester) async {
|
||||||
|
await pumpButton(
|
||||||
|
tester,
|
||||||
|
isRecording: false,
|
||||||
|
isStartingRecording: true,
|
||||||
|
);
|
||||||
|
await tester.pump(morphDuration);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(innerCoreSize(tester).width, closeTo(22.r, 0.5));
|
||||||
|
|
||||||
|
await pumpButton(tester, isRecording: false, isStartingRecording: false);
|
||||||
|
await tester.pump(morphDuration);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(innerCoreSize(tester).width, closeTo(62.r, 0.5));
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:recording_tool/features/recording/widgets/widget_recording_touch_lock_overlay.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('resolveRecordingTouchLockUnlockIntent', () {
|
||||||
|
test('returns stopRecording for portrait bottom 30 percent', () {
|
||||||
|
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||||
|
position: const Offset(120, 466.9),
|
||||||
|
size: const Size(375, 667),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(intent, RecordingTouchLockUnlockIntent.stopRecording);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns unlockOnly for portrait area outside bottom 30 percent', () {
|
||||||
|
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||||
|
position: const Offset(120, 320),
|
||||||
|
size: const Size(375, 667),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(intent, RecordingTouchLockUnlockIntent.unlockOnly);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns stopRecording for landscape right 30 percent', () {
|
||||||
|
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||||
|
position: const Offset(466.9, 120),
|
||||||
|
size: const Size(667, 375),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(intent, RecordingTouchLockUnlockIntent.stopRecording);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns unlockOnly for landscape area outside right 30 percent', () {
|
||||||
|
final intent = resolveRecordingTouchLockUnlockIntent(
|
||||||
|
position: const Offset(320, 120),
|
||||||
|
size: const Size(667, 375),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(intent, RecordingTouchLockUnlockIntent.unlockOnly);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('RecordingTouchLockOverlayWidget', () {
|
||||||
|
Future<void> pumpOverlay(
|
||||||
|
WidgetTester tester, {
|
||||||
|
required Size surfaceSize,
|
||||||
|
required ValueChanged<RecordingTouchLockUnlockIntent> onUnlocked,
|
||||||
|
}) async {
|
||||||
|
await tester.binding.setSurfaceSize(surfaceSize);
|
||||||
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
ScreenUtilInit(
|
||||||
|
designSize: const Size(375, 812),
|
||||||
|
builder: (context, _) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
RecordingTouchLockOverlayWidget(
|
||||||
|
enabled: true,
|
||||||
|
unlockHoldDuration: const Duration(seconds: 2),
|
||||||
|
onUnlocked: onUnlocked,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
testWidgets('long press in portrait bottom 30 percent stops recording', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
RecordingTouchLockUnlockIntent? receivedIntent;
|
||||||
|
await pumpOverlay(
|
||||||
|
tester,
|
||||||
|
surfaceSize: const Size(375, 667),
|
||||||
|
onUnlocked: (intent) => receivedIntent = intent,
|
||||||
|
);
|
||||||
|
|
||||||
|
final gesture = await tester.startGesture(const Offset(120, 600));
|
||||||
|
await tester.pump(const Duration(seconds: 2));
|
||||||
|
await gesture.up();
|
||||||
|
|
||||||
|
expect(receivedIntent, RecordingTouchLockUnlockIntent.stopRecording);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('long press outside stop area only unlocks', (tester) async {
|
||||||
|
RecordingTouchLockUnlockIntent? receivedIntent;
|
||||||
|
await pumpOverlay(
|
||||||
|
tester,
|
||||||
|
surfaceSize: const Size(375, 667),
|
||||||
|
onUnlocked: (intent) => receivedIntent = intent,
|
||||||
|
);
|
||||||
|
|
||||||
|
final gesture = await tester.startGesture(const Offset(120, 320));
|
||||||
|
await tester.pump(const Duration(seconds: 2));
|
||||||
|
await gesture.up();
|
||||||
|
|
||||||
|
expect(receivedIntent, RecordingTouchLockUnlockIntent.unlockOnly);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('releasing before hold duration does not unlock', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
RecordingTouchLockUnlockIntent? receivedIntent;
|
||||||
|
await pumpOverlay(
|
||||||
|
tester,
|
||||||
|
surfaceSize: const Size(375, 667),
|
||||||
|
onUnlocked: (intent) => receivedIntent = intent,
|
||||||
|
);
|
||||||
|
|
||||||
|
final gesture = await tester.startGesture(const Offset(120, 600));
|
||||||
|
await tester.pump(const Duration(milliseconds: 1500));
|
||||||
|
await gesture.up();
|
||||||
|
await tester.pump(const Duration(seconds: 1));
|
||||||
|
|
||||||
|
expect(receivedIntent, isNull);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||