Unable to position AndroidView with video

Viewed 196

I am using flutter 3.0.0

In my application I am displaying a native video using platform view.

The video is displaying but it is always displaying on upper left corner and it covers other widgets even they are in a stack.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Stack(
        children: [
          Center(
            child: ConstrainedBox(
                constraints:
                    const BoxConstraints.expand(height: 200, width: 200),

                // Center is a layout widget. It takes a single child and positions it
                // in the middle of the parent.
                child:
                    const AndroidView(viewType: 'remote-video'),
                ),
          ),
          Row(
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: ElevatedButton(
                  onPressed: () {
                    MethodChannels.coreMethodChannel
                        .invokeMethod("load");
                  },
                  child: const Text('Invoke'),
                ),
              ),
              
            ],
          ),

        ],
      ),
    );
  }

This is how it looks when I run the code

enter image description here

As you can see it is displaying over everything.

Can you provide some advice on how to fix this?

1 Answers

As of 31/07/2022 this seems to be a bug in flutter >= 3.0.0. Following the solution in this question Flutter AndroidView Widget I downgraded to 2.10.5 and then it worked as expected. Hopefully the flutter team will resolve it shortly.

Related