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 =;

      return bloodList;

  setDropdownValue(String? dorpValue) {
    dropdownValue = dorpValue;

''' 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});

  State<Homepage> createState() => _HomepageState();

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


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