I want the users of my app to always have the latest version. If they don't have the latest version, it should download the latest version from play store automatically on app startup. I'm using in_app_update
for that. I'm performing Performs immediate update
Below is the code of splash screen which came after main
. Here I check for update in route
function, if update is available then perform update and navigate to homeView
, If not simply navigate to homeView
But app never informed new user about update whenever new version is uploaded on playstore. They have to manually go to playstore to update an app. Why is that? Am I doing something wrong in a code or do I need to do something extra?
import 'package:in_app_update/in_app_update.dart';
class SplashView extends StatefulWidget {
@override
_SplashViewState createState() => _SplashViewState();
}
class _SplashViewState extends State<SplashView> {
AppUpdateInfo _updateInfo; // --- To check for update
@override
void initState() {
super.initState();
startTimer();
}
startTimer() async {
var duration = Duration(milliseconds: 1500);
return Timer(duration, route);
}
route() async {
await checkForUpdate();
bool visiting = await ConstantsFtns().getVisitingFlag();
if (_updateInfo?.updateAvailable == true) {
InAppUpdate.performImmediateUpdate().catchError((e) => _showError(e));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeView(),
),
);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeView(),
),
);
}
}
Future<void> checkForUpdate() async {
InAppUpdate.checkForUpdate().then((info) {
setState(() {
_updateInfo = info;
});
}).catchError((e) => _showError(e));
}
void _showError(dynamic exception) {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content:
Text("Exception while checking for error: " + exception.toString()),
));
@override
Widget build(BuildContext context) {
return Material(
child: AnimatedSplashScreen(
.............................
),
);
}
}
I don't know why suggested solution of similar question is not working for me. https://stackoverflow.com/a/62129373/7290043