Working off a video from Flutter Zone on YouTube adn ran across a problem with running a localhost though Flutter. The error I got was "SocketException: Failed to create server socket (OS Error: Only one usage of each socket address (protocol/network address/port) is normally permitted. , errno = 10048), address = 127.0.0.1, port = 9109". It should be calling an API for the locahost but comes up with this error. The API is working correctly as I can call it from a website. I have tried looking for example for the problem based on flutter but not sure if this page is actually the page I need to have the solution in.
any help is appreciated.
import 'dart:convert';
import '../models/food_model.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:http/http.dart' as https;
class FoodModel extends Model {
  List<Food> _foods = [];
  List<Food> get foods {
    return List.from(_foods);
  }
  void addFood(Food food) {
    _foods.add(food);
  }
  void fetchFoods() {
    
    https
        .get("https://[IPAdress]/mics_app/api/foods/getFoods.php")
        .then((https.Response response) {
      //print("Fetching data: ${response.body}");
      final List fetchedData = json.decode(response.body);
      final List<Food> fetchedFoodItems = [];
      // print(fetchedData);
      fetchedData.forEach((data) {
        
        Food food = Food(
          id: data["id"],
          category: data["category"],
          imagePath: data["imagePath"],
          name: data["name"],
        );
        fetchedFoodItems.add(food);
      });
      _foods = fetchedFoodItems;
      print(_foods);
    });
  }
}
Debug Console
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
lib\main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Unhandled exception:
SocketException: Failed to create server socket (OS Error: Only one usage of each socket address (protocol/network address/port) is normally permitted.
, errno = 10048), address = 127.0.0.1, port = 9109
#0      serveDevTools (package:devtools_server/src/server.dart:199:5)
<asynchronous suspension>
#1      serveDevToolsWithArgs (package:devtools_server/src/server.dart:72:10)
<asynchronous suspension>
Failed to launch DevTools: TimeoutException after 0:00:10.000000: Future not completed
Connecting to VM Service at ws://127.0.0.1:65493/cACJTymFD2A=/ws
fetchedFoods
import 'package:flutter/material.dart';
import 'package:madeincanadastuff/src/scoped-model/food_model.dart';
import 'package:madeincanadastuff/src/widgets/food_category.dart';
import '../widgets/search_field.dart';
import '../widgets/home_top_info.dart';
import '../widgets/bought_foods.dart';
import '../models/food_model.dart';
class HomePage extends StatefulWidget {
  final FoodModel foodModel;
  HomePage(this.foodModel);
  @override
  _HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
  // List<Food> _foods = foods;
  @override
  void initState() {
    widget.foodModel.fetchFoods();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        padding: EdgeInsets.only(top: 30, left: 20, right: 20),
        children: <Widget>[
          HomeTopInfo(),
          FoodCategory(),
          SizedBox(
            height: 10.0,
          ),
          SearchField(),
          SizedBox(
            height: 10.0,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(
                "Frequently bought stuff",
                style: TextStyle(
                  fontSize: 18.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              GestureDetector(
                onTap: () {},
                child: Text(
                  "View All",
                  style: TextStyle(
                      fontSize: 18.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.orangeAccent),
                ),
              )
            ],
          ),
          SizedBox(height: 10),
          Column(
            children: widget.foodModel.foods.map(_buildFoodItems).toList(),
          ),
        ],
      ),
    );
  }
  Widget _buildFoodItems(Food food) {
    return Container(
      margin: EdgeInsets.only(bottom: 20.0),
      child: BoughtFoods(
        id: food.id,
        name: food.name,
        imagePath: "assets/images/breakfast.png",
        category: food.category,
      ),
    );
  }
}