Я создаю приложение, в котором есть видеоплеер и предварительный просмотр передней камеры в правом нижнем углу, который можно перетаскивать, когда я поворачиваю экран, камера исчезает

#android #flutter #dart #animation #flutter-layout

Вопрос:

Я создаю приложение , в котором есть видеоплеер и предварительный просмотр передней камеры в правом нижнем углу, который можно перетаскивать, когда я поворачиваю виджет предварительного просмотра камеры на экране, он не виден. и я поворачиваюсь в исходную ориентацию [ по умолчанию — портрет ] предварительный просмотр камеры становится видимым до последнего перетаскиваемого положения.

главная.дротик

     void main() {
      WidgetsFlutterBinding.ensureInitialized();
      SystemChrome.setPreferredOrientations([
        DeviceOrientation.landscapeLeft,
        DeviceOrientation.landscapeRight,
        DeviceOrientation.portraitDown,
        DeviceOrientation.portraitUp,
      ]).then((_) {
        runApp(MyApp());
      });
    }
 

Главный экран

         Stack(
          children: [
            Stack(
              children: [
                Align(
                  alignment: Alignment.center,
                  child: AspectRatio(
                    aspectRatio: _videoController.value.aspectRatio,
                    child: VideoPlayer(_videoController),
                  ),
                  if (showControls) Container(color: Colors.black45),
                ),
              ],
            ),
            CameraLivePreviewScreen(
              top: MediaQuery.of(context).size.height - 150,
              left: MediaQuery.of(context).size.width - 100 - 10,
            ),
          ],
        )
 

Экран просмотра моей камеры

       class CameraLivePreviewScreen extends StatefulWidget {
        final double? top;
        final double? left;

        const CameraLivePreviewScreen(
            {Key? key, @required this.top, @required this.left})
            : super(key: key);
        @override
        CameraLivePreviewScreenState createState() => CameraLivePreviewScreenState();
      }

      class CameraLivePreviewScreenState extends State<CameraLivePreviewScreen> {
        final GlobalKey cameraKey = GlobalKey(debugLabel: 'LiveCamera');
        late QRViewController _captureController;

        GlobalKey _key = GlobalKey();
        late double? top, left;
        late double? xOff, yOff;

        @override
        void initState() {
          top = widget.top;
          left = widget.left;
          print("top - $top, left - $left");
          xOff = 0;
          yOff = 0;
          super.initState();
        }

        void _onQRViewCreated(QRViewController controller) async {
          this._captureController = controller;
          await controller.flipCamera();
        }

        @override
        void dispose() {
          super.dispose();
        }

        @override
        Widget build(BuildContext context) {
          return AnimatedPositioned(
            duration: Duration(milliseconds: 200),
            key: _key,
            top: top,
            left: left,
            child: SizedBox(
              height: 150,
              width: 100,
              child: Draggable(
                child: QRView(
                  key: cameraKey,
                  onQRViewCreated: _onQRViewCreated,
                ),
                feedback: Container(), //remains behind
                childWhenDragging: QRView(
                  key: cameraKey,
                  onQRViewCreated: _onQRViewCreated,
                ),
                onDragUpdate: (drag) {
                  setState(() {
                    top = drag.globalPosition.dy;
                    left = drag.globalPosition.dx;
                  });
                },
              ),
            ),
          );
        }
      }