I am trying to implement ota updates in a flutter app. I am using this package Ota Update to implement the ota update. For now I am following the example shown by the package documentation. How can I impement it in such a way that it checks the version of the app installed on the phone and compares it with whats stored in the server then proceed to download if a newer version is found.
Here is my code
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late OtaEvent currentEvent;
@override
void initState() {
super.initState();
tryOtaUpdate();
}
Future<void> tryOtaUpdate() async {
try {
//LINK CONTAINS APK OF FLUTTER HELLO WORLD FROM FLUTTER SDK EXAMPLES
OtaUpdate()
.execute(
'https://internal1.4q.sk/flutter_hello_world.apk',
destinationFilename: 'flutter_hello_world.apk',
//FOR NOW ANDROID ONLY - ABILITY TO VALIDATE CHECKSUM OF FILE:
sha256checksum:
'd6da28451a1e15cf7a75f2c3f151befad3b80ad0bb232ab15c20897e54f21478',
)
.listen(
(OtaEvent event) {
setState(() => currentEvent = event);
},
);
// ignore: avoid_catches_without_on_clauses
} catch (e) {
print('Failed to make OTA update. Details: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('OTA status: ${currentEvent.status} : ${currentEvent.value} \n'),
],
),
),
);
}
}