I am using StreamProvider to get updates of the current location to then use it on the full_screen_map. everything seems to be working as expected and i am getting locations updates. But when the map is loading, a red error screen with error: **Error: The widget FullScreenMap tried to read Provider but the matching
provider returned null.
To fix the error, consider changing Provider to Provider<UserLocation?>.**
I tried to add the “?” to the UserLocation as suggested but the error persist and it only last about 2 seconds while the data is loading, after that everything works as expected. I did tried to have a spinkit or a Circularprogressindicator to try to make it fancy while it waits for the data, THE ERROR PESIST!
I am willing to cosnider a way to just shut up the error in the UI while it could still be shown in the terminal.
this is the main widget build
`
@override
Widget build(BuildContext context) {
return StreamProvider<UserLocation?>(
initialData: null,
create: (context) => LocationService().locationStream,
child: MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: LoadingScreen.id,
routes: {
LoginScreen.id: (context) => const LoginScreen(),
SignupScreen.id: (context) => const SignupScreen(),
LoadingScreen.id: (context) => const LoadingScreen(),
FullScreenMap.id: (context) => FullScreenMap(),
ForgotPasswordScreen.id: (context) => const ForgotPasswordScreen(),
},
theme: ThemeData.dark().copyWith(
textTheme: const TextTheme(
bodyText1: TextStyle(
color: Colors.black,
),
),
),
),
);
}
}
`
and this is the full_scree_map file where im trying to use the provider
`
Widget build(BuildContext context) {
UserLocation userLocation = Provider.of<UserLocation>(context);
Size size = MediaQuery.of(context).size;
LatLng centerLocation =
LatLng(userLocation.latitude, userLocation.longitude);
LatLng trackedLocation =
LatLng(userLocation.latitude, userLocation.longitude);
`
any help will be appreciated. again, if you know how to just stop the UI from showing that error for those 2 seconds is fine with me. I tried using some codes i found on here like this one `
import 'dart:ui' as ui;
void main() {
RenderErrorBox.backgroundColor = Colors.transparent;
RenderErrorBox.textStyle = ui.TextStyle(color: Colors.transparent);
}
`
to stop the red screen error from showing, but no luck.