Can't display data from Node.js API

I am working on Flutter app and trying to connect it to Node.js Express.js API. Currently I am working on showing fetched data on screen. Problem is that I can’t achieve this. I was trying everything, Googling and trying everything from other people but I was not successful. I have created Model for Cases(case = something person using my app will create on construction…).

cases_model.dart code:

List<CaseModel> casesFromJson(dynamic str) =>
    List<CaseModel>.from((str).map((x) => CaseModel.fromJson(x)));

class CaseModel{
  late int? id;
  late String? caseName;
  late String? constructionSite;
  late String? createdBy;
  late String? dateOfDiscovery;
  late String? dateOfRemoval;
  late String? responsible;
  late int? howManyDiscoveries;
  late String? text;
  late int? sanction;
  late String? placeOfDiscovery;
  late String? forCompany;
  late int? priority;
  late bool? isActive;

  CaseModel({
   this.id,
   this.caseName,
   this.constructionSite,
   this.createdBy,
   this.dateOfDiscovery,
   this.dateOfRemoval,
   this.responsible,
   this.howManyDiscoveries,
   this.text,
   this.sanction,
   this.placeOfDiscovery,
   this.forCompany,
   this.priority,
   this.isActive
  });

  CaseModel.fromJson(Map<String, dynamic> json){
    id = json['id'];
    caseName = json['caseName'];
    constructionSite = json['constructionSite'];
    createdBy = json['createdBy'];
    dateOfDiscovery = json['dateOfDiscovery'];
    dateOfRemoval = json['dateOfRemoval'];
    responsible = json['responsible'];
    howManyDiscoveries = json['howManyDiscoveries'];
    text = json['text'];
    sanction = json['sanction'];
    placeOfDiscovery = json['placeOfDiscovery'];
    forCompany = json['forCompany'];
    priority = json['priority'];
    isActive = json['isActive'];
  }

  Map<String, dynamic> toJson(){
    final _data = <String, dynamic>{};

    _data["id"] = id;
    _data["caseName"] = caseName;
    _data["constructionSite"] = constructionSite;
    _data["createdBy"] = createdBy;
    _data["dateOfDiscovery"] = dateOfDiscovery;
    _data["dateOfRemoval"] = dateOfRemoval;
    _data["responsible"] = responsible;
    _data["howManyDiscoveries"] = howManyDiscoveries;
    _data["text"] = text;
    _data["sanction"] = sanction;
    _data["placeOfDiscovery"] = placeOfDiscovery;
    _data["forCompany"] = forCompany;
    _data["priority"] = priority;
    _data["isActive"] = isActive;

    return _data;
  }
}

Then I created Service for api calls.

api_service.dart code:

class APIService {
  static var client = http.Client();

  static Future<List<CaseModel>?> getCases() async {
    Map<String, String> requestHeaders = { 'ContentType': 'application/json' };
    var url = Uri.http(Config.apiURL, Config.casesAPI);

    var response = await client.get(url, headers: requestHeaders);

    if(response.statusCode == 200){
      var data = jsonDecode(response.body);

      return casesFromJson(data["data"]);
    }
    else {
      return null;
    }
  }
}

When I print data inside if block, I receive correct response from server with correct data.

Then I’m trying to show this cases on HomePage.

Full code of HomePage is here:

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final storage = FlutterSecureStorage();
  DateTime _selectedDate = DateTime.now();
  final _caseController = Get.put(CaseController());
  String _currentContruction = 'Vybrať stavbu';
  List<String> constructionsList=[
    'Stavba PORSCHE',
    'Jaguár',
    'Kia',
    'Peugeot',
  ];
  List<CaseModel> cases = List<CaseModel>.empty(growable: true);
  @override
  void initState() {
    super.initState();
  }

  Widget casesList(cases){
    return SingleChildScrollView(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ListView.builder(
                shrinkWrap: true,
                physics: const ClampingScrollPhysics(),
                scrollDirection: Axis.vertical,
                itemCount: cases.length,
                itemBuilder: (context, index) {
                  return CaseItem(
                    model: cases[index],
                    onDelete: (CaseModel model){

                    },
                  );
                },
              )
            ],
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final arguments = ModalRoute.of(context)!.settings.arguments;
      return Scaffold(
          appBar: _appBar(),
          backgroundColor: context.theme.backgroundColor,
          body: Column(
            children: [
              Text("Vitajte, $arguments", style: subTitleStyle,),
              _addTaskBar(),
              _addDateBar(),
              SizedBox(height: 10,),
              loadCases(),
            ],
          ));
    }

    Widget loadCases(){
    return FutureBuilder(
      future: APIService.getCases(),
      builder: (BuildContext context, AsyncSnapshot<List<CaseModel>?> model,){
        if(model.hasData){
          return casesList(model.data);
        }
        print("tu");
        print(model);
        return const Center(child: CircularProgressIndicator(),);
      },
    );
    }

    _showBottomSheet(BuildContext context, CaseModel model){
    Get.bottomSheet(
      Container(
        padding: const EdgeInsets.only(top: 4),
        height: model.isActive==1?
        MediaQuery.of(context).size.height*0.40:
        MediaQuery.of(context).size.height*0.48,
        color: Get.isDarkMode?darkGreyClr:Colors.white,
        child: Column(
          children: [
            Container(
              height: 6,
              width: 120,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                color: Get.isDarkMode?Colors.grey[600]:Colors.grey[300],
              ),
            ),
            Spacer(),
            model.isActive==1?Container():_bottomSheetButton(
              label: "Ukončiť nedostatok",
              onTap: (){
                _caseController.markCompleted(model.id!);
                Get.back();
              },
              clr: Colors.green[500]!,
              context: context
            ),
            _bottomSheetButton(
                label: "Zobraziť nedostatok",
                onTap: (){
                  Get.to(() => DetailsScreen(), arguments: [
                    model.caseName,
                    model.constructionSite,
                    model.dateOfDiscovery,
                    model.placeOfDiscovery,
                    model.createdBy,
                    model.text,
                    model.sanction,
                    model.forCompany,
                    model.priority,
                  ]);
                },
                clr: primaryClr,
                context: context
            ),
            _bottomSheetButton(
                label: "Vymazať nedostatok",
                onTap: (){
                  Get.back();
                },
                clr: Colors.red[500]!,
                context: context
            ),
            SizedBox(
              height: 20,
            ),
            _bottomSheetButton(
                label: "Zavrieť",
                onTap: (){
                  Get.back();
                },
                clr: Colors.red[300]!,
                isClose: true,
                context: context
            ),
            SizedBox(
              height: 15,
            ),
          ],
        ),
      )
    );
  }

  _bottomSheetButton({
    required String label,
    required Function()? onTap,
    required Color clr,
    bool isClose = false,
    required BuildContext context,
  }){
    return GestureDetector(
      onTap: onTap,
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 4),
        height: 55,
        width: MediaQuery.of(context).size.width*0.9,
        decoration: BoxDecoration(
          border: Border.all(
            width: 2,
            color: isClose==true?Get.isDarkMode?Colors.grey[600]!:Colors.grey[300]!:clr,
          ),
          borderRadius: BorderRadius.circular(20),
          color: isClose==true?Colors.transparent:clr,
        ),

        child: Center(
          child: Text(
            label,
            style: isClose?titleStyle:titleStyle.copyWith(color:Colors.white),
          ),
        ),
      ),
    );
  }

  _addDateBar(){
    return Container(
      margin: const EdgeInsets.only(top: 20, left: 20),
      child: DatePicker(
        DateTime.now().subtract(Duration(days:1)),
        locale: Locale('sk','SK').toString(),
        height: 100,
        width: 80,
        initialSelectedDate: DateTime.now(),
        selectionColor: primaryClr,
        selectedTextColor: Colors.white,
        dateTextStyle: GoogleFonts.lato(
          textStyle: TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.w600,
              color: Colors.grey
          ),
        ),
        dayTextStyle: GoogleFonts.lato(
          textStyle: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w600,
              color: Colors.grey,
          ),
        ),
        monthTextStyle: GoogleFonts.lato(
          textStyle: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w600,
              color: Colors.grey
          ),
        ),
        onDateChange: (date){
          setState(() {
            _selectedDate = date;
          });
        },
      ),
    );
  }

  _addTaskBar(){
    return Container(
      margin: const EdgeInsets.only(left: 10, right: 10, top: 5),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            children: [
              MyInputField2(title: "Stavba", hint: _currentContruction,
                widget: DropdownButton(
                  style: subTitleStyle,
                  underline: Container(
                    height: 0,
                  ),
                  items: constructionsList.map<DropdownMenuItem<String>>((String value) {
                    return DropdownMenuItem<String>(
                      value: value,
                      child: Text(value),
                    );
                  }
                  ).toList(),
                  onChanged: (String? newValue) {
                    setState(() {
                      _currentContruction = newValue!;
                    });
                  },
                ),
              )
            ],
          ),
          Container(
            padding: EdgeInsets.only(top: 20),
            child: MyButton(
              label: "+", onTap: () async {
              await Get.to(() => AddNewCase(), arguments: [
                ModalRoute.of(context)!.settings.arguments,
                _currentContruction
              ]);
              _caseController.getCases();
            }
            ),
          )
        ],
      ),
    );
  }

  _appBar() {
    return AppBar(
      elevation: 0,
      backgroundColor: context.theme.appBarTheme.backgroundColor,
      leading: GestureDetector(
        onTap: () {
          ThemeService().switchTheme();
        },
        child: Icon(Get.isDarkMode ? Icons.wb_sunny_outlined : Icons.nightlight_round,
          size: 20,
          color: Get.isDarkMode ? Colors.white : Colors.black,
        ),
      ),
      title: Text("ŠKOLBOZ", style: appBarTextStyle,),
      centerTitle: true,
      actions: [
        GestureDetector(
          onTap: () {
            Get.to(() => Settings());
          },
          child: Icon(Get.isDarkMode ? Icons.settings_outlined : Icons.settings,
            size: 20,
            color: Get.isDarkMode ? Colors.white : Colors.black,
          ),
        ),
        SizedBox(
          width: 20,
        ),
      ],
    );
  }
}

Here, inside loadCases() function when I print(model) I get this error:

I/flutter (10996): AsyncSnapshot<List<CaseModel>?>(ConnectionState.done, null, type 'String' is not a subtype of type 'int' of 'index', #0      APIService.getCases (package:skolboz/Services/api_service.dart:22:32)

So model has no data, but why? how?..

To be honest, I really don’t know what can be wrong, I tried everything, googled everything but nothing helped me.

Hope someone will be able to help me. Thank you!