flutter / website

Flutter documentation web site
https://docs.flutter.dev
Other
2.84k stars 3.24k forks source link

Missing note: The file should be recompiled using `Visual Studio` for the changes to take effect. #11390

Open AbdeMohlbi opened 2 weeks ago

AbdeMohlbi commented 2 weeks ago

Page URL

https://docs.flutter.dev/platform-integration/platform-channels/

Page source

https://github.com/flutter/website/tree/main/src/content/platform-integration/platform-channels.md

Describe the problem

After completing Step 5 in the Flutter documentation, replace the code with the following:

channel.SetMethodCallHandler(
    [](const flutter::MethodCall<>& call,
       std::unique_ptr<flutter::MethodResult<>> result) {
      if (call.method_name() == "getBatteryLevel") {
        int battery_level = GetBatteryLevel();
        if (battery_level != -1) {
          result->Success(battery_level);
        } else {
          result->Error("UNAVAILABLE", "Battery level not available.");
        }
      } else {
        result->NotImplemented();
      }
    });

You should now be able to run the application on Windows. If your device doesn't have a battery, it will display 'Battery level not available'.

Expected fix

i suggest adding at the end : Note: To ensure the changes take effect, the project should be recompiled with Visual Studio. Otherwise, you may encounter an error saying: Failed to get battery level: Memory leak. it's not mention that the exe should be recompiled using Visual studio again. also the error message of the leaking is very confusing.

Additional context

No response

I would like to fix this problem.

stuartmorgan commented 1 week ago

To ensure the changes take effect, the project should be recompiled with Visual Studio.

There is no such requirement given the way Flutter builds are structured; flutter run/flutter build will rebuild native code.

If you have a case where flutter run does not pick up changes to native code in your project, please file an issue in flutter/flutter with detailed reproduction steps.