zeba_academy_app_updater 0.0.1
zeba_academy_app_updater: ^0.0.1 copied to clipboard
Flutter package to handle app updates with optional and force update dialogs, version checking, and silent background updates.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:zeba_academy_app_updater/zeba_academy_app_updater.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Zeba App Updater Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
textStyle:
const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
),
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late ZebaAppUpdater updater;
String status = "Checking for updates...";
@override
void initState() {
super.initState();
updater = ZebaAppUpdater(
context: context,
apiUrl: 'https://example.com/api/version', // Replace with your API
playStoreUrl:
'https://play.google.com/store/apps/details?id=com.example.app',
appStoreUrl: 'https://apps.apple.com/app/id123456789',
showOptionalUpdate: true,
);
checkForUpdates();
}
Future<void> checkForUpdates() async {
try {
await updater.checkUpdate(); // Show dialogs if update available
await updater.silentCheck(); // Silent background check
setState(() {
status = "App is up-to-date!";
});
} catch (e) {
setState(() {
status = "Error checking update: $e";
});
}
}
// ---------------- Public demo methods ----------------
Future<void> simulateUpdateDialogs() async {
// Force update demo
updater.showForceUpdateDialogDemo(
"🚀 Version 2.0.0 is required!\n\nChangelog:\n- Critical bug fixes\n- UI improvements",
);
// Optional update demo
await Future.delayed(const Duration(seconds: 2));
updater.showOptionalUpdateDialogDemo(
"✨ Optional update available (v2.1.0)\n- New features added\n- Performance improvements",
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Zeba App Updater Demo"),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.update,
size: 80,
color: Colors.blueAccent.shade400,
),
const SizedBox(height: 20),
Text(
status,
textAlign: TextAlign.center,
style:
const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
),
const SizedBox(height: 30),
ElevatedButton.icon(
onPressed: simulateUpdateDialogs,
icon: const Icon(Icons.play_circle_fill),
label: const Text("Simulate Update Dialogs"),
),
const SizedBox(height: 15),
ElevatedButton.icon(
onPressed: checkForUpdates,
icon: const Icon(Icons.refresh),
label: const Text("Check for Updates"),
),
],
),
),
),
);
}
}