How to solve: I need to change the List view when the appropriate tab menu is pressed?

Question

Asked by abdul on December 10, 2021 (source).

I need to change the page accordingly when the tab menu is pressed. Here is the code:

class HistoryListView extends StatefulWidget {
  String? empcode;

  HistoryListView({this.empcode});
  @override
  State<HistoryListView> createState() => _HistoryListViewState();
}

class _HistoryListViewState extends State<HistoryListView> {
  String _getTitle(ActivityTab selectedMenu) {
    if (selectedMenu == ActivityTab.COMMITTED_DATE) {
      return "Committed Date";
    } else if (selectedMenu == ActivityTab.CALL_NOT_ANSWERED) {
      return "Call not answered";
    } else if (selectedMenu == ActivityTab.WRONG_NUMBER) {
      return "Wrong or invalid number";
    } else if (selectedMenu == ActivityTab.MISBEHAVIOR) {
      return "Misbehaviour";
    }
    return "";
  }

  List<int> _getStatus(ActivityTab selectedMenu) {
    if (selectedMenu == ActivityTab.COMMITTED_DATE) {
      return [Constants.STATUS_COMMITTED_DATE];
    } else if (selectedMenu == ActivityTab.CALL_NOT_ANSWERED) {
      return [Constants.STATUS_CALL_NOT_ANSWERED];
    } else if (selectedMenu == ActivityTab.WRONG_NUMBER) {
      return [Constants.STATUS_WRONG_NUMBER, Constants.STATUS_INVALID_NUMBER];
    } else if (selectedMenu == ActivityTab.MISBEHAVIOR) {
      return [
        Constants.STATUS_ABUSING_LANGUAGE,
        Constants.STATUS_DID_NOT_AGREE_TO_PAY,
        Constants.STATUS_ADVISED_TO_CALL
      ];
    }
    return [0];
  }

  @override
  Widget build(BuildContext context) {
    var provider = Provider.of<ActivityTabModel>(context);
    return Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
      _getCommittedText(provider.selectedMenu),
      verticalSpace(Utils.getHeight(20)),
      Expanded(
        child: _StudentListItem(provider.selectedMenu,getEmpCode: widget.empcode,feedbackStatus: _getStatus(provider.selectedMenu),),
      ),
    ]);
  }

  Widget _getCommittedText(ActivityTab selectedMenu) => Text(
    _getTitle(selectedMenu),
    style: TextStyle(
      color: ColorUtils.PEACOCK_BLUE,
      fontSize: Utils.getFontSize(16),
      fontFamily: Constants.axiforma,
      fontWeight: FontWeight.w500
    ),
  );
}

These "Committed Date", "Call not answered", "Wrong or invalid number" and "Misbehaviour" are some of the menu on the top of the page. When I click on the specific menu, I need to get _StudentListItem corresponding to the menu I had chosen. In this code, the "Committed Date" is the default page and when I choose "Call not answered" menu, its _StudentListItem will display (always display the committed date list). Please provide me a good solution.

Answer

Question answered by abdul (source).

Widget _getMenuItem(ActivityTabModel tab) {
    if (tab.selectedMenu == ActivityTab.COMMITTED_DATE)
      return StudentListItem(tab.selectedMenu,getEmpCode: widget.empcode,feedbackStatus: getStatus(tab.selectedMenu),);
    else if (tab.selectedMenu == ActivityTab.CALL_NOT_ANSWERED)
      return CallNotAnswered(tab.selectedMenu,getEmpCode: widget.empcode,feedbackStatus: getStatus(tab.selectedMenu));
    else if (tab.selectedMenu == ActivityTab.WRONG_NUMBER)
      return InvalidNumber(tab.selectedMenu,getEmpCode: widget.empcode,feedbackStatus: getStatus(tab.selectedMenu));
    else if (tab.selectedMenu == ActivityTab.MISBEHAVIOR)
      return  Misbehave(tab.selectedMenu,getEmpCode: widget.empcode,feedbackStatus: getStatus(tab.selectedMenu));
    return Container();
  }
DART FLUTTER NAVIGATION
SHARE: