Steelhacks-2023 / Lost-At-Pitt

Lost @ Pitt is a multi-platform lost-and-found tracking application, allowing users to return & reclaim lost items. Currently in development!
https://steelhacks-2023.github.io/Lost-At-Pitt/
6 stars 0 forks source link

Move database calls and StreamBuilders #40

Closed tbeidlershenk closed 7 months ago

tbeidlershenk commented 8 months ago

Database calls are made in the following files:

map_page.dart
auth.dart

And soon we will need to make calls for the messaging functionality of the app when we build that. I think it would be beneficial to move all our database access to a separate file.

Another somewhat related issue: the map page is wrapped in a StreamBuilder2 widget listening to the Lost and Found streams. Then when the user switches to the list page, the current data is passed into that page from the map page. This seems like a bad way to do it since one page is in charge of doing the updates. Why don't we wrap the current page in main.dart MaterialApp widget in the StreamBuilder widget instead? Then we can pass the data to whatever page wants it.

To illustrate my point -

child: MaterialApp(
            debugShowCheckedModeBanner: false,
            routes: {
              'loginPage': (context) => const LoginPage(),
              'mapPage': (context) => const MapPage(), // this page has a parent StreamBuilder in the build method
              '/': (context) => const Wrapper()
            },
            initialRoute: '/',
            theme: AppTheme.getTheme(),
            themeMode: themeManager.themeMode));

Instead I suggest we do this -

child: MaterialApp(
            debugShowCheckedModeBanner: false,
            routes: {
              'loginPage': (context) => StreamBuilderWrapper('loginPage'),
              'mapPage': (context) => StreamBuilderWrapper('mapPage'),
              '/': (context) => const Wrapper()
            },
            initialRoute: '/',
            theme: AppTheme.getTheme(),
            themeMode: themeManager.themeMode));

Where StreamBuilderWrapper is defined in the database operations file and we simply pass the current data into the correct page based on the parameter, 'loginPage' or 'mapPage' (and in the future chat pages)

tbeidlershenk commented 8 months ago

This has somewhat been implemented by using HomePage as the streaming page which then can switch to the map view, list view, etc with a DataService singleton class storing the lost and found collections. It will be closed with #45