Data is coming from api and I want to set it in a dropdown list. To do that when I am using provider as state managemet my dropdown is beign disable. But through the same process ( like process of fetch and set data ) when I am using setState it is working perfectly....

can someone please help me out where i am making mistake??

My provider class Code:

'''

import 'dart:convert';

import 'package:flutter/cupertino.dart';

import '../model/blood_groups.dart';
import '../util/api_url.dart';
import 'package:http/http.dart' as http;

class BloodProvider with ChangeNotifier {
  String? dropdownValue;
  var bloodList = <Data>[];

// Fetch blood Groups...
  fetchBlood() async {
    var response = await http.get(Uri.parse(bloodGroupUrl));
    var data = jsonDecode(response.body);

    if (response.statusCode == 200) {
      BloodGroup bloodGroup = BloodGroup.fromJson(data);

      bloodList = bloodGroup.data;

      return bloodList;
    }
    notifyListeners();
  }

  setDropdownValue(String? dorpValue) {
    dropdownValue = dorpValue;
    notifyListeners();
  }
}

''' which is not working perfeclty. dropdownbutton is beign disabled through this process.

Working code using setState:

import 'package:api_dropdown/provider/blood_provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class Homepage extends StatefulWidget {
  const Homepage({super.key});

  @override
  State<Homepage> createState() => _HomepageState();
}

class _HomepageState extends State<Homepage> {
  BloodProvider blood = BloodProvider();
  @override
  void initState() {
    blood.fetchBlood();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final provider = Provider.of<BloodProvider>(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text("Api Dropdown"),
      ),
      body: Column(
        children: [
          DropdownButtonHideUnderline(
            child: DropdownButton(
              icon: const Icon(Icons.keyboard_arrow_down),
              underline: const SizedBox(),
              value: provider.dropdownValue,
              onChanged: (String? newValue) {
                provider.setDropdownValue(newValue);
              },
              items: provider.bloodList.map((items) {
                return DropdownMenuItem(
                    value: items.id.toString(),
                    child: Text(
                      items.name.toString(),
                      style: const TextStyle(
                          fontSize: 14, color: Colors.red),
                    ));
              }).toList(),
            ),
          ),
          TextFormField(
            enabled: false,
            decoration: const InputDecoration(
                contentPadding: EdgeInsets.only(top: 4, left: 8),
                hintText: "ex: A+",
                border: OutlineInputBorder()),
          ),
        ],
      ),
    );
  }
}