FlutterでWeb通信(http通信)するためのパッケージである「chopper」あるいは「http」を使って、通信を行おうとすると、
Insecure HTTP is not allowed by platform
というエラーが出て処理が中断してしまうことがあります。
なんじゃこれ!?という感じですが、これはFlutterの公式サイトで説明がありまして、
結論から言うと、アクセスしようとしたアドレスの先頭を「http」ではなく「https」にすれば解決するようです。
アドレスが「https」で始まる場合は、通信が暗号化されているため「安全(=セキュア)」である一方、「http」で始まる場合は暗号化されていないため「安全でない(=インセキュア(Insecure)」と判断されるので、そのような通信はAndroid及びiOSでは拒否されてしまうことによるものだそうです。
Starting with Android API 28 and iOS 9, these platforms disable insecure HTTP connections by default.
With this change Flutter also disables insecure connections on mobile platforms. Other platforms (desktop, web, etc) are not affected.
You can override this behavior by following the platform-specific guidelines to define a domain-specific network policy. See the migration guide below for details.
Much like the platforms, the application can still open insecure socket connections. Flutter does not enforce any policy at socket level; you would be responsible for securing the connection.
下の動画の例で言うと、アクセスに使っていたアドレスが
https://newsapi.org/v2
になっていたので、
https://newsapi.org/v2
に変えるとうまくいきました。
(詳しくは、以下の動画で解説していますので、よろしければご覧下さい)