I'm recently migrate my code to flutter 2.0, but I'm getting this error: error: The return type of getter 'tabbarcatinfo' is 'dynamic' which isn't a subtype of the type 'List' of its setter 'tabbarcatinfo'.

import 'package:flutter/material.dart';
List _tabbarcatinfo = [];

class TabBarCategoriesInfo with  ChangeNotifier{
  static late List<String> name;

  get tabbarcatinfo {
    return _tabbarcatinfo;
  }

  set tabbarcatinfo(List Listita) {
    _tabbarcatinfo = Listita;
    notifyListeners();
  }

  void addData(List Listita) {
    _tabbarcatinfo.add(Listita);
    //notifyListeners();
  }
}
3

There are 3 best solutions below

2
On BEST ANSWER

You have not properly defined types in your code.

Use it like this.

List<String> _tabbarcatinfo = [];

class TabBarCategoriesInfo with ChangeNotifier {
  static late List<String> name;

  List<String> get tabbarcatinfo {
    return _tabbarcatinfo;
  }

  set tabbarcatinfo(List<String> Listita) {
    _tabbarcatinfo = Listita;
    notifyListeners();
  }

  void addData(String item) {
    _tabbarcatinfo.add(item);
    //notifyListeners();
  }
}

Comment if you have any particular doubt about a line and I will elaborate by answer to explain it.

2
On

Try this

get tabbarcatinfo {
  return [..._tabbarcatinfo] as List<dynamic>;
}

Edit: Add the cast List<dynamic> in return statement.

3
On

Need set a type before get.

List get tabbarcatinfo

And anothrw question, your list doesn't have a type? If I'm not mistaken it must have any type.