basic_force_update 1.0.4
basic_force_update: ^1.0.4 copied to clipboard
Basic Force Update
example/lib/main.dart
import 'package:basic_force_update/basic_force_update.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Force Update Example',
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _showUpdateDialog = false;
ForceUpdateType _updateType = ForceUpdateType.dialog;
@override
Widget build(BuildContext context) {
return ForceUpdateWidget(
delegate: const ForceUpdateDelegate(
version: '1.0.0', // Current app version
type: ForceUpdateType.sheet, // Use dialog for force update UI
title: 'Update Required',
description:
'A new version of the app is available. Please update to continue using the app.',
button: 'Update Now',
appStoreId: 'com.example.app', // Replace with your iOS App Store ID
packageName:
'com.example.app', // Replace with your Android package name
),
provider: const DummyUpdateProvider(
version:
'1.0.1', // Minimum required version (higher than current to trigger update)
active: true, // Set to true to activate force update
),
child: Scaffold(
appBar: AppBar(
title: const Text('Force Update Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Force Update Example App',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
const Text(
'Current Version: 1.0.0\nRequired Version: 1.0.1',
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Update Type: '),
const SizedBox(width: 10),
SegmentedButton<ForceUpdateType>(
segments: const [
ButtonSegment<ForceUpdateType>(
value: ForceUpdateType.dialog,
label: Text('Dialog'),
),
ButtonSegment<ForceUpdateType>(
value: ForceUpdateType.sheet,
label: Text('Sheet'),
),
],
selected: {_updateType},
onSelectionChanged: (Set<ForceUpdateType> newSelection) {
setState(() {
_updateType = newSelection.first;
});
},
),
],
),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () {
setState(() {
_showUpdateDialog = !_showUpdateDialog;
});
if (_showUpdateDialog) {
if (_updateType == ForceUpdateType.dialog) {
showForceUpdateDialog(
context,
delegate: const ForceUpdateDelegate(
version: '1.0.0',
title: 'Manual Update Check',
description:
'This is a manually triggered update dialog.',
button: 'Update Now',
appStoreId: 'com.example.app',
packageName: 'com.example.app',
),
);
} else {
showForceUpdateSheet(
context,
delegate: const ForceUpdateDelegate(
version: '1.0.0',
title: 'Manual Update Check',
description:
'This is a manually triggered update sheet.',
button: 'Update Now',
appStoreId: 'com.example.app',
packageName: 'com.example.app',
),
);
}
}
},
child: Text(_showUpdateDialog
? 'Hide Update Dialog'
: 'Show Update Dialog'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (_updateType == ForceUpdateType.dialog) {
showForceUpdateDialog(
context,
delegate: const ForceUpdateDelegate(
version: '1.0.0',
title: 'Update Available',
description:
'This is a manually triggered update UI based on your selection.',
button: 'Update Now',
appStoreId: 'com.example.app',
packageName: 'com.example.app',
),
);
} else {
showForceUpdateSheet(
context,
delegate: const ForceUpdateDelegate(
version: '1.0.0',
title: 'Update Available',
description:
'This is a manually triggered update UI based on your selection.',
button: 'Update Now',
appStoreId: 'com.example.app',
packageName: 'com.example.app',
),
);
}
},
child: const Text('Show Selected Update UI'),
),
],
),
),
),
);
}
}