Bloc Events not being executed sequentially

I have a piece of code where i need to call two bloc events sequentially the issue is that the first event is fired and api is called but the second is not being called , i tried to debug my code and i came to the conclusion that if i call both events from different blocs , they both get fired but if from the same bloc .. only the first gets fired , any help would be appreciate guys . Thank you

  • This is my code ( check initState , calling two events from same bloc )

 class _FurniturePageState extends State<FurniturePage> {
  String userImage = "";
  final List<String> _titles = ["Lamp","Chair","Table","Sofa","Bed"];
  final List<String> _images = [
    "assets/images/lamp.png",
    "assets/images/chair.png",
    "assets/images/table.png",
    "assets/images/sofa.png",
    "assets/images/bed.png"
  ];
  late int selectedCategory = 0;

  @override
  void initState() {
    super.initState();
    BlocProvider.of<ShopBloc>(context).add(GetUserDataEvent());
    BlocProvider.of<ShopBloc>(context).add(GetFurnitureEvent("Lamp"));
  }
  
  @override
  Widget build(BuildContext context) {
    return BlocListener<ShopBloc,ShopBlocState>(
        listener: (context,state){
           if(state is GetUserDataState){
              setState(() {
                 userImage =  state.userModel.userImage!;
              });
              StorageHelper.saveInfo(state.userModel.name!, state.userModel.email!, state.userModel.phone!);
           }
        },
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.all(20),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Expanded(child:  Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(_setDayTime(),style: getArimoBold().copyWith(fontSize: 34),),
                        Text("Welcome back",style: getArimoRegular().copyWith(fontSize: 20),)
                      ],
                    )),
                    GestureDetector(
                      onTap: (){
                        Get.toNamed(Utils.cartRoute);
                      },
                      child : Container(
                        width: 45,
                        height: 45,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(60),
                            color: Colors.grey.shade200
                        ),
                        child: const Center(child: Icon(Icons.add_shopping_cart,size: 20,),),
                      ),
                    ),
                    const Gap(10),
                    Center(
                      child: CircleAvatar(
                        radius: 20,
                        foregroundImage: NetworkImage(userImage),
                      ),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(15),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(8),
                  child: Image.asset("assets/images/banner.png",fit: BoxFit.cover,
                    height: 200,width: double.maxFinite,),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 25,right: 20,top: 20),
                child: Row(
                  children: [
                    Expanded(flex: 2,child: Text("Choose Category",style: getArimoBold().copyWith(fontSize: 25),),),
                    Expanded(child: GestureDetector(
                      onTap: (){
                        Get.toNamed(Utils.viewAllRoute);
                      },
                      child: Text("View All",style: getArimoRegular().copyWith(fontSize: 18),
                        textAlign: TextAlign.end,),
                    ))
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(15),
                child: SizedBox(
                  height: 130,
                  child: ListView.builder(
                    shrinkWrap: true,
                    itemCount: _titles.length,
                    scrollDirection: Axis.horizontal,
                    itemBuilder: (context,index){
                      return Padding(
                        padding: const EdgeInsets.all(10),
                        child: GestureDetector(
                          onTap: (){
                            setState(() {
                              selectedCategory = index;
                            });
                            BlocProvider.of<FurnitureBloc>(context).add(GetFurnitureEvent(_titles[index]));
                          },
                          child: Column(
                            children: [
                              Container(
                                width: 70,
                                height: 70,
                                decoration:  BoxDecoration(
                                  borderRadius: BorderRadius.circular(60),
                                  color: selectedCategory == index ? Colors.black : Colors.grey.shade200,
                                ),
                                child: Center(child: Image.asset(_images[index],filterQuality: FilterQuality.high,
                                  width: 40,height: 40,color: Colors.grey.shade500,),),
                              ),
                              const SizedBox(height: 5,),
                              Center(child: Text(_titles[index],style: getArimoRegular().copyWith(fontSize: 16),),)
                            ],
                          ),
                        ),
                      );
                    },
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 15,right: 15),
                child: BlocBuilder<FurnitureBloc,ShopBlocState>(
                  builder: (context,state){
                    if(state is LOADING){
                      return const Center(child: CircularProgressIndicator(),);
                    }
                    else if (state is ERROR){
                      return SizedBox(
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.height / 3,
                        child: Center(
                          child: Text(state.e.toString(),style: getArimoBold().copyWith(fontSize: 20),),
                        ),
                      );
                    }
                    else if(state is GetFurnitureState){
                      var data = state.furniture;
                      if(data.isNotEmpty){
                        return GridView.builder(
                          physics: const NeverScrollableScrollPhysics(),
                          shrinkWrap: true,
                          itemCount: data.length,
                          scrollDirection: Axis.vertical,
                          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 2,
                            mainAxisSpacing: 10,
                            crossAxisSpacing: 10,
                            childAspectRatio: 0.8, // Adjust the aspect ratio to ensure cards are not too tall
                          ),
                          itemBuilder: (context, index) {
                            return Card(
                              margin: const EdgeInsets.all(10),
                              color: Colors.grey.shade200,
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Flexible(
                                    child:  ClipRRect(
                                      borderRadius: BorderRadius.circular(16),
                                      child: CachedNetworkImage(
                                        imageUrl : data[index]!.image!,
                                        placeholder: (context, url) => Image.asset("assets/images/no_image.png"),
                                        width : double.maxFinite,
                                        height: 180,
                                        fit: BoxFit.cover,
                                        filterQuality: FilterQuality.high,
                                        fadeInDuration: const Duration(milliseconds: 500),
                                      ),
                                    ),
                                  ),
                                  Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Row(
                                      crossAxisAlignment: CrossAxisAlignment.start,
                                      children: [
                                        Expanded(
                                            child:  Column(
                                              crossAxisAlignment: CrossAxisAlignment.start,
                                              children: [
                                                Text(
                                                  data[index]!.title!,
                                                  style: getArimoBold().copyWith(fontSize: 15),
                                                  maxLines: 1,
                                                  overflow: TextOverflow.ellipsis,
                                                ),
                                                Text(
                                                  "${data[index]!.price}$",
                                                  style: getArimoRegular().copyWith(fontSize: 15),
                                                ),
                                              ],
                                            )),
                                        Align(
                                          alignment: Alignment.centerRight,
                                          child: SizedBox(
                                            width: 40,
                                            height: 40,
                                            child: GestureDetector(
                                              onTap: () {
                                                StorageHelper.setPosition(0);
                                                Get.toNamed(Utils.detailsRoute,arguments:data[index]?.id!);
                                              },
                                              child: Card(
                                                shape: RoundedRectangleBorder(
                                                  borderRadius: BorderRadius.circular(16),
                                                ),
                                                child: Center(
                                                  child: Image.asset(
                                                    "assets/images/arrow.png",
                                                    width: 15,
                                                    height: 15,
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                        );
                      }
                      else {
                        return SizedBox(
                          width: MediaQuery.of(context).size.width,
                          height: MediaQuery.of(context).size.height / 3,
                          child: Center(
                            child: Text("No Furniture Found",style: getArimoBold().copyWith(fontSize: 20),),
                          ),
                        );
                      }
                    }
                    else {
                      return SizedBox(
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.height / 3,
                        child: Center(
                          child: Text("No Furniture Found",style: getArimoBold().copyWith(fontSize: 20),),
                        ),
                      );
                    }
                  },
                ),
              )
            ],
          ),
        ),);
  }
  String _setDayTime(){
    DateFormat dateFormat = DateFormat("hh a");
    DateTime dateTime = DateTime.now();
    String formattedString = dateFormat.format(dateTime);
    if(formattedString.contains("AM")){
      return "Good Morning";
    } else {
      return "Good Evening";
    }
  }

}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật