0

I have a StreamBuilder in my Widget body

body: RefreshIndicator(
        onRefresh: () => _sheetDetailBloc.fetchSheetDetail(
            widget.selectedSheet, widget.selectedSheetTitle),
        child: StreamBuilder<ApiResponse<Sheet>>(
          stream: _sheetDetailBloc.sheetDetailStream,
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              switch (snapshot.data.status) {
                case Status.LOADING:
                  return Loading(loadingMessage: snapshot.data.message);
                  break;
                case Status.COMPLETED:
                  return ShowSheetDetail(displaySheet: snapshot.data.data);
                  break;
                case Status.ERROR:
                  return Error(
                    errorMessage: snapshot.data.message,
                    onRetryPressed: () => _sheetDetailBloc.fetchSheetDetail(
                        widget.selectedSheet, widget.selectedSheetTitle),
                  );
                  break;
              }

I have a drawer in my appbar where i want to display the contactNoToDisp and emailIDToDisp which will arrive after asyc call as snapshot.data.data.contactNo and snapshot.data.data.emailID

drawer code is below:

endDrawer: Drawer(
          child: ListView(
        children: <Widget>[
          ListTile(
            title: Text("First Item"),
          ),
          ListTile(title: Text(contactNoForDisp)),
          ListTile(title: Text(emailIDForDisp)),
        ],
      )),

I am not sure how to update the two class variables contactNoToDisp and emailIDToDisp after the future/asyc has returned so that the same can be dispalyed in the drawer

vikasm
  • 69
  • 5
  • Keep a separate variable for `contactNoForDisp` & `emailIDForDisp`, use them in the Drawer initially with some default or blank text. When the stream returns a valid info, use `setState()` to update the values of contactNoForDisp` & `emailIDForDisp` to the one's received. – Darshan May 27 '21 at 08:23
  • Tried this and found out cannot call setState from inside the builder. It throws "setState() or markNeedsBuild() called during build" – vikasm May 27 '21 at 15:13
  • Use a ValueNotifier & ValueListenableBuilder in drawer then. – Darshan May 27 '21 at 15:21

0 Answers0