i have the code to check version of flutter app but it contains an asynchron code which i cannot insert inside buildcontext method, so i decided to put it into the main method and insert a popup to tell to the user he has to update the app but i received this reponse: failed assertion: Line 70 pos 15: context!=null:is not true because i set context to null in my alertDialog, so id don' tknow where to place it so that each time the user launches the app the version checking is running and shows the alertDialog if the version he has is less than the one in the store. here is my code to checked it and how i implemented it: i used the NewVersion package to chek and compare the local version and stored version in google play
class PataStoreConnector extends StatefulWidget {
final bool loggedin;
PataStoreConnector({Key key, this.loggedin}) : super(key: key);
@override
_PataStoreConnectorState createState() => _PataStoreConnectorState();
}
class _PataStoreConnectorState extends State<PataStoreConnector> {
bool sleeping = true;
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
timer();
});
super.initState();
}
@override
Widget build(BuildContext context) {
if (sleeping) {
return PataSplashScreen();
}
return StoreConnector<PataState, PataViewModel>(
converter: PataViewModel.convertStateToViewModel,
builder: (BuildContext context, PataViewModel pataViewModel) {
return getPage(pataViewModel);
},
);
}
and the getPage method which contains the code for checking version:
// ignore: missing_return
Widget getPage(PataViewModel viewModel) {
//Pt.instance.version;
final newVersion = NewVersion(
androidId: 'com.snedac.empata',
context: context,
);
// setState(() async {
// VersionStatus vs = await newVersion.getVersionStatus();
// });
newVersion.getVersionStatus().then((result) {
print("store version ${result.storeVersion}");
print("local version ${result.localVersion}");
if (result.storeVersion == result.localVersion) {
if (viewModel.isLoggingIn()) {
viewModel.refreshUserData();
// vm.setIsHomeLoadedStateAction(true);
return PataSplashScreen();
}
if (!viewModel.isLoggedIn()) {
return LoginPage(
viewModel: viewModel,
);
}
print("homeloaded:${viewModel.state.isHomeloaded}");
print("userIdLogin:${viewModel.state.user.userId}");
if (viewModel.state.isHomeloaded == false) {
if (viewModel.state.user.userId > 0) {
viewModel.initHome();
} else {
return LoginPage(
viewModel: viewModel,
);
}
}
return PataHome(title: "e-Mpata");
} else {
_ackAlert2("Mise a jour", 'Votre version est trop obsolète.');
}
});
}