How to use the same Stream on different pages in Dart?

Asked

Viewed 37 times

0

Hello! I am creating an application using Clean Architecture as a base. In the context of my problem, I have a Tabbarview that has 4 indexs. In the numbers 0 and 3, there is a component that will be repeated, which I named Usershortinfo(), defined below:

class _UserShortInfoState extends State<UserShortInfo> {
  @override
  Widget build(BuildContext context) {
  final presenter = Provider.of<TabsPresenter>(context);
  StreamBuilder<MapUserEntity?>(
                  stream: presenter.user,
                  builder: (context, snapshot) {

                  ...// code that builds a list of user information
  }

Back to Tabbarview indexes 0 and 3, they are 2 pages, Homepresenter() and Profilepresenter(), defined below.

 class _HomePageState extends State<HomePage>
    with AutomaticKeepAliveClientMixin<HomePage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      body: ...// layout code, hidden to focus on the problem
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const UserShortInfo(),
                    DogsList(),
                    EmptyDogList(),
                    OffersList(),
                    ScheduleShower(),
                  ],
                ),
              ),
            );
          },
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}


class _ProfilePageState extends State<ProfilePage>
    with AutomaticKeepAliveClientMixin<ProfilePage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(body: SafeArea(
      child: //layout code hidden to focus on the problem
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                const UserShortInfo(),
                EmptyDogList(),
                GridViewOption(),
              ],
            ),
          ),
        );
      }),
    ));
  }

  @override
  bool get wantKeepAlive => true;
}

The idea here is, in the presenter (some call controller) of Tabpage, to make the calls in the endpoints and use the same components in the tabs in which they repeat themselves. In the index tab 0, Homepage(), the information of the component Usershortinfo() are displayed correctly! But when switching to index page 3, Profilepage() the information is not displayed. I’m really confused about why this behavior. I appreciate any suggestions for the problem!

  • You can not understand exactly without the complete code that involves the problem, try to summarize and facilitate so that the problem can be easily reproduced. Based on what you said existe um componente que vai se repetir a way would be to pass this information as a parameter to the TABS.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.