defaultDialog function

void defaultDialog({
  1. required BuildContext context,
  2. required String? latestVersion,
  3. required String appVersion,
  4. required UpdatStatus status,
  5. required String? changelog,
  6. required void checkForUpdate(),
  7. required void openDialog(),
  8. required void startUpdate(),
  9. required Future<void> launchInstaller(),
  10. required void dismissUpdate(),
})

Implementation

void defaultDialog({
  required BuildContext context,
  required String? latestVersion,
  required String appVersion,
  required UpdatStatus status,
  required String? changelog,
  required void Function() checkForUpdate,
  required void Function() openDialog,
  required void Function() startUpdate,
  required Future<void> Function() launchInstaller,
  required void Function() dismissUpdate,
}) {
  showDialog(
    context: context,
    builder: (context) => AlertDialog(
      scrollable: true,
      title: Flex(
        direction:
            Theme.of(context).useMaterial3 ? Axis.vertical : Axis.horizontal,
        children: const [
          Icon(Icons.update),
          Text('Update available'),
        ],
      ),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text('A new version of the app is available.'),
          const SizedBox(width: 10),
          Text('New Version: ${latestVersion!.toString()}'),
          const SizedBox(height: 10),
          if (status == UpdatStatus.availableWithChangelog) ...[
            Text(
              'Changelog:',
              style: Theme.of(context).textTheme.bodyLarge?.copyWith(
                    fontWeight: FontWeight.bold,
                  ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(changelog!),
            ),
          ],
        ],
      ),
      actions: <Widget>[
        TextButton(
          child: const Text('Later'),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        TextButton(
          onPressed: () {
            Navigator.pop(context);
            startUpdate();
          },
          child: const Text('Update Now'),
        ),
      ],
    ),
  );
}