升级后,Flutter PlatformView 漂浮在所有其他小部件之上

Zen*_*nko 7 android flutter

PlatformView升级之前一切正常,然后我在稳定频道上将 Flutter 更新到了 3.0.1 版本然后,突然发生了奇怪的行为。

\n

我创建了一个 GIF 供您参考。\n奇怪的行为是:

\n
    \n
  1. PlatformView 位于所有其他小部件之上。你可以看到DropDownMenu它背后的事情。我尝试过使用Stack或其他小部件,但它不起作用。PlatformView 始终掌握一切。
  2. \n
  3. 事情变得更奇怪了。当我们使用 进入下一页时,PlatformView 会浮动在屏幕顶部Navigator.push。正如你所看到的,它后面还有另一张图片。即使没有PlatformView即使另一页上
  4. \n
\n

对于 的其余实现,我按照此处的NativeView文档进行操作

\n

再一次,它在升级之前工作得很好。\n应该发生的事情是,除非PlatformView使用指定,否则不应位于其他小部件之上。\n当我转到下一页时,它应该位于新页面的后面,并且不应漂浮。Stack

\n

我错过了什么吗?请告诉我。谢谢

\n

在此输入图像描述

\n

在此输入图像描述

\n

我在 Dart 端的代码:\nmain.dart

\n
class MyHomePage extends StatefulWidget {\n  const MyHomePage({Key? key, required this.title}) : super(key: key);\n\n  final String title;\n\n  @override\n  State<MyHomePage> createState() => _MyHomePageState();\n}\n\nclass _MyHomePageState extends State<MyHomePage> {\n  late EffectController _controller;\n  Uint8List? image;\n  Uint8List? imageOutline;\n  bool noLine = false;\n  String effectValue = \'No effect\';\n  String filterValue = \'No filter\';\n  static const imagePath = \'assets/images/test_image.jpg\';\n  static const imageOutlinePath = \'assets/images/test_image_outline.png\';\n\n  void resetValues() {\n    image = null;\n    imageOutline = null;\n    noLine = false;\n    effectValue = \'No effect\';\n    filterValue = \'No filter\';\n  }\n\n @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      floatingActionButton: FloatingActionButton(\n          onPressed: () => Navigator.push(\n              context,\n              MaterialPageRoute(\n                  builder: (context) =>\n                      PreviewPage(Image.memory(imageOutline!))))),\n      appBar: AppBar(\n        title: Text(widget.title),\n      ),\n      body: Center(\n        child: Column(\n            mainAxisAlignment: MainAxisAlignment.center,\n            children: <Widget>[\n            SizedBox(\n            width: 400,\n            height: 400,\n            child: image == null\n                ? TextButton(\n                onPressed: () async {\n                  image = (await rootBundle.load(imagePath))\n                      .buffer\n                      .asUint8List();\n                  imageOutline =\n                      (await rootBundle.load(imageOutlinePath))\n                          .buffer\n                          .asUint8List();\n                  setState(() {});\n                },\n                child: const Text("Apply Image"))\n                : NativeView(\n              onViewCreated: (controller) {\n                _controller = controller;\n              },\n              image: image!,\n              imageOutline: imageOutline!,\n              noLine: noLine,\n              width: 400,\n              height: 400,\n              // width and height is required for ios, CGRect is always zero, its a flutter bug\n              // setting bounds manually int docs below\n              // https://docs.flutter.dev/development/platform-integration/platform-views#on-the-platform-side-1\n            )),\n        //NOTE: image should be ready when showing NativeView\n        SingleChildScrollView(\n            scrollDirection: Axis.horizontal,\n            padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),\n            child: image == null\n                ? Container()\n                : \n            DropdownButton<String>(\n            value: effectValue,\n            icon: const Icon(Icons.arrow_downward_rounded),\n            elevation: 16,\n            style: const TextStyle(color: Colors.deepPurple),\n            underline: Container(\n              height: 2,\n              color: Colors.deepPurpleAccent,\n            ),\n            onChanged: (String? newValue) {\n\n            },\n            items: <String>[\n              \'No effect\',\n              \'Item 20\',\n              \'Item 19\',\n              \'Item 18\',\n              \'Item 17\',\n              \'Item 16\',\n              \'Item 15\',\n              \'Item 14\',\n              \'Item 13\',\n              \'Item 12\',\n              \'Item 11\',\n              \'Item 10\',\n              \'Item 9\',\n              \'Item 8\',\n              \'Item 7\',\n              \'Item 6\',\n              \'Item 5\',\n              \'Item 4\',\n              \'Item 3\',\n              \'Item 2\',\n              \'Item 1\',\n              \'Item 0\',\n            ].map<DropdownMenuItem<String>>((String value) {\n              return DropdownMenuItem<String>(\n                value: value,\n                child: Text(value),\n              );\n            }).toList()),\n      ),\n      Visibility(\n        visible: image != null,\n        child: TextButton(\n            onPressed: () {\n              setState(() {\n                resetValues();\n              });\n            },\n            child: const Text("Remove Image")),\n      ),\n      ],\n    ),\n    ));\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这是我的flutter doctor -v

\n
[\xe2\x9c\x93] Flutter (Channel stable, 3.0.1, on macOS 12.1 21C52 darwin-x64, locale en-US)\n    \xe2\x80\xa2 Flutter version 3.0.1 at /Users/ME/development/flutter\n    \xe2\x80\xa2 Upstream repository https://github.com/flutter/flutter.git\n    \xe2\x80\xa2 Framework revision fb57da5f94 (4 days ago), 2022-05-19 15:50:29 -0700\n    \xe2\x80\xa2 Engine revision caaafc5604\n    \xe2\x80\xa2 Dart version 2.17.1\n    \xe2\x80\xa2 DevTools version 2.12.2\n    \xe2\x80\xa2 Pub download mirror https://pub.flutter-io.cn\n    \xe2\x80\xa2 Flutter download mirror https://storage.flutter-io.cn\n\nChecking Android licenses is taking an unexpectedly long time...[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version 32.0.0)\n    \xe2\x80\xa2 Android SDK at /Volumes/ME/Applications/Android/sdk\n    \xe2\x80\xa2 Platform android-32, build-tools 32.0.0\n    \xe2\x80\xa2 ANDROID_HOME = /Volumes/ME/Applications/Android/sdk\n    \xe2\x80\xa2 Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)\n    \xe2\x80\xa2 All Android licenses accepted.\n\n[\xe2\x9c\x93] Xcode - develop for iOS and macOS (Xcode 13.3.1)\n    \xe2\x80\xa2 Xcode at /Applications/Xcode.app/Contents/Developer\n    \xe2\x80\xa2 CocoaPods version 1.11.2\n\n[\xe2\x9c\x93] Chrome - develop for the web\n    \xe2\x80\xa2 Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome\n\n[\xe2\x9c\x93] Android Studio (version 2021.2)\n    \xe2\x80\xa2 Android Studio at /Applications/Android Studio.app/Contents\n    \xe2\x80\xa2 Flutter plugin can be installed from:\n       https://plugins.jetbrains.com/plugin/9212-flutter\n    \xe2\x80\xa2 Dart plugin can be installed from:\n       https://plugins.jetbrains.com/plugin/6351-dart\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)\n\n[\xe2\x9c\x93] VS Code (version 1.67.1)\n    \xe2\x80\xa2 VS Code at /Applications/Visual Studio Code.app/Contents\n    \xe2\x80\xa2 Flutter extension version 3.8.0\n\n[\xe2\x9c\x93] Connected device (3 available)\n    \xe2\x80\xa2 SM G960U1 (mobile) \xe2\x80\xa2 5a53414a33573398 \xe2\x80\xa2 android-arm64  \xe2\x80\xa2 Android 10 (API 29)\n    \xe2\x80\xa2 macOS (desktop)    \xe2\x80\xa2 macos            \xe2\x80\xa2 darwin-x64     \xe2\x80\xa2 macOS 12.1 21C52 darwin-x64\n    \xe2\x80\xa2 Chrome (web)       \xe2\x80\xa2 chrome           \xe2\x80\xa2 web-javascript \xe2\x80\xa2 Google Chrome 101.0.4951.64\n\n[\xe2\x9c\x93] HTTP Host Availability\n    \xe2\x80\xa2 All required HTTP hosts are available\n\n\xe2\x80\xa2 No issues found!\n\n
Run Code Online (Sandbox Code Playgroud)\n