[Flutter] PIP, Picture in Picture Mode

2024. 1. 15. 16:04dev/flutter

728x90
반응형

use package pip_view

path : https://pub.dev/packages/pip_view

 

pip_view | Flutter Package

Widget to allow the presentation of a widget below a floating one.

pub.dev

 

this package is not I want.

I want pip mode below information. It is floating package.


 

 

but this package can only use aos...:(

and you setting android.

path : android/app/src/main/AndroidManifest.xml

 

add this in activity tag

android:supportsPictureInPicture="true">

 

 

and add package is floating

flutter pub add floating

 

 

State에 WidgetsBindingObserver Mixin을 연결한다.

이유는 위젯에서 벗어나는 Home버튼을 누른 상황에서 PIP모드가 동작되도록 하기 위해

class _MyAppState extends State<MyApp> with WidgetsBindingObserver

 

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
  // super.didChangeAppLifecycleState(state);
  if (state == AppLifecycleState.inactive) {
    floating.enable(aspectRatio: const Rational.square());
  }
}

 

final bool? enabledSuccessfully = await _channel.invokeMethod(
  'enablePip',
  {
    ...aspectRatio.toMap(),
    if (sourceRectHint != null)
      'sourceRectHintLTRB': [
        sourceRectHint.left,
        sourceRectHint.top,
        sourceRectHint.right,
        sourceRectHint.bottom,
      ],
  },
);


android plugin

@RequiresApi(Build.VERSION_CODES.N)
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
  if (call.method == "enablePip") {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      val builder = PictureInPictureParams.Builder()
        .setAspectRatio(
          Rational(
            call.argument("numerator") ?: 16,
            call.argument("denominator") ?: 9
          )
        )
      val sourceRectHintLTRB = call.argument<List<Int>>("sourceRectHintLTRB")
      if (sourceRectHintLTRB?.size == 4) {
        val bounds = Rect(
          sourceRectHintLTRB[0],
          sourceRectHintLTRB[1],
          sourceRectHintLTRB[2],
          sourceRectHintLTRB[3]
        )
        builder.setSourceRectHint(bounds)
      }
      result.success(
          activity.enterPictureInPictureMode(builder.build())
      )
    } else {
      result.success(activity.enterPictureInPictureMode())
    }
  }
728x90
반응형

'dev > flutter' 카테고리의 다른 글

[Flutter] sqflite SQLite Database #DB  (0) 2024.01.16
[Flutter] MainAxisAlignment (Row, Column)  (0) 2024.01.16
[Flutter] Timer, custom delay point  (0) 2024.01.15
[Flutter] Video Player  (0) 2024.01.15
[Flutter] Google API MAP, Geolocator  (0) 2024.01.14