app_upgrader 0.1.2 app_upgrader: ^0.1.2 copied to clipboard
a Flutter package designed to handle application upgrades seamlessly.
import 'dart:io';
import 'package:app_upgrader/app_upgrader.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
// dummy json data for Android Version Info from your own service
// or firebase config
Map<String, dynamic> androidVersionInfo = {
"41452": {"update_type": "forceUpdate"},
"41451": {"update_type": "flexible"},
"41450": {"update_type": "none"}
};
// dummy json data for iOS Version Info from your own service
// or firebase config
Map<String, dynamic> iosVersionInfo = {
"10.3.1": {"update_type": "forceUpdate"},
"10.3.0": {"update_type": "none"},
"10.2.9": {"update_type": "flexible"},
};
class MyVersionInfoFetcher implements VersionInfoFetcher {
// you can use your own service or firebase remote config.
// for example we use dummy json data
@override
Future<Map<String, dynamic>> fetchVersionInfo() {
final versionInfo =
Platform.isAndroid ? androidVersionInfo : iosVersionInfo;
return Future.value(versionInfo);
}
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App Upgrader Test App',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: AppUpgrader(
// for example, telegram bundleId added
bundleId: Platform.isAndroid
? 'org.telegram.messenger'
: 'ph.telegra.Telegraph',
versionInfoFetcher: MyVersionInfoFetcher(),
child: const MyHomePage(title: 'App Upgrader Test App')),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[Text('Prod App with App Updater')],
),
),
);
}
}