'Couldn't dynamically add widgets to list view flutter using provider

I am getting input from user using textfield and displaying it in a list using ListView.builder() using provider flutter state management. But couldn't achieve that result.

After onPressed, I am providing the textediting controller as input to ChangeNotifier class and adding the card widget with text(will contain input text), in the list. and display the list in new screen using ListView.builder(). But it doesn't work, couldn't display the list in some other screen. Could you please mention the mistake that I made with this code.

onPressed: () {
setState(() {
Provider.of<BorrowersListData>(context,listen: false).addBorrower(borrowerNameController.text);
});
Navigator.pop(context);
},

ChangeNotifier class, borrowercard is a like card widget with name on it.

class BorrowersListData extends ChangeNotifier {
  List<Widget> borrowerList = [];
  
  addBorrower(String newBorrowerName) {
    BorrowersListData().borrowerList.insert(0, borrowerCard(newBorrowerName));
    notifyListeners();
  }
}

ListView builder

ListView.builder(
itemCount: BorrowersListData.borrowerList.length,
itemBuilder: ((context, index) {
return BorrowersListData.borrowerList[index];
})),


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source