I have a live app on playstore and I want to use in_app_update package in flutter to check for app updates and update the app on user's phone. I have the following code which runs the app update in the background and shows a spinner until the updates are done. Before publishing this new code, I want to be sure if it works. In other words, how can I test if
InAppUpdate.performImmediateUpdate()
will work when there is an update?
Does anyone have an idea how can I be sure if this code works before publishing it to playstore?
import 'package:in_app_update/in_app_update.dart';
Future<void> main() async {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var _isLoading;
var appUpdate;
void didChangeDependencies() async {
setState(() {
_isLoading = true;
});
await InAppUpdate.checkForUpdate().then((info) {
print('Starting app updates');
AppUpdateInfo _updateInfo = info;
appUpdate = _updateInfo.updateAvailable;
print('App update aye? ' + appUpdate.toString());
if(appUpdate)
InAppUpdate.performImmediateUpdate()
.catchError((e) => print(e.toString()));
print('Finishing app updates');
}).catchError((e) {
print(e.toString());
});
super.didChangeDependencies();
print('isloadign to false');
setState(() {
// Get image url
_isLoading = false;
});
}
@override
Widget build(BuildContext context) {
return !(_isLoading)?MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => Auth(),
),
child: Consumer<Auth>(builder: (ctx, auth, _) =>
MaterialApp(
title: 'MyApp',
home: ProductDetailScreen(),
routes: {
ProductDetailScreen.routeName:(ctx) => ProductDetailScreen(),
}
),
)
):Center(child:Loading());
}
}
You can try launching a release in
closed testing track
feature on Google Play. So it will be signed & published to Google Play but will be available only to chosen users. You can create a user, add yourself to the closed testing track.As for the other point of view - This plugin wraps the official Android API, hence I recommend reading Android documentation to check if there is some information about testing it.