'Dart Flutter HttpServer not serving websites when using InternetAddress.anyIPv4 /6

The code below runs successfully on an android device when I use the InternetAddress.loopbackIPv4 or InternetAddress.loopbackIPv6 and navigate to localhost:8080 but when I bind the server to InternetAddress.anyIPv4 or InternetAddress.anyIPv6 and then use another android phone to connect to HTTP://{IP}:8080 it doesn't load

Any help is greatly appreciated!

import 'dart:io';
import 'package:dart_ipify/dart_ipify.dart';
import 'package:flutter/material.dart';

Future<void> main() async {
  //Retrieve android IP to connect to
  var ipv4 = await Ipify.ipv4();
  print(ipv4); // 98.207.254.136
  String ipv6 = await Ipify.ipv64();
  print(ipv6); // 98.207.254.136 or 2a00:1450:400f:80d::200e

  var server = await HttpServer.bind(InternetAddress.anyIPv4, 8080);
  await server.forEach((HttpRequest request) {
    request.response.write('From Server!');
    request.response.close();
  });
  runApp(MaterialApp(
    home: Home(),
  ));
}

Thank you for looking!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source