ente/mobile/lib/ui/settings/app_update_dialog.dart
Ashil dac0ddf41c
[mob][photos] Migrate use of WillPopScope to PopScope (#1473)
## Description

[Documentation followed for the
migration](https://docs.flutter.dev/release/breaking-changes/android-predictive-back)

## Tests

- [x] Tested screens in which migration wasn't straight forward
(HomeScreen)
2024-04-19 09:16:42 +05:30

114 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/services/update_service.dart';
import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import 'package:url_launcher/url_launcher_string.dart';
class AppUpdateDialog extends StatefulWidget {
final LatestVersionInfo? latestVersionInfo;
const AppUpdateDialog(this.latestVersionInfo, {Key? key}) : super(key: key);
@override
State<AppUpdateDialog> createState() => _AppUpdateDialogState();
}
class _AppUpdateDialogState extends State<AppUpdateDialog> {
@override
Widget build(BuildContext context) {
final List<Widget> changelog = [];
final enteTextTheme = getEnteTextTheme(context);
final enteColor = getEnteColorScheme(context);
for (final log in widget.latestVersionInfo!.changelog) {
changelog.add(
Padding(
padding: const EdgeInsets.fromLTRB(0, 4, 0, 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"- ",
style: enteTextTheme.small.copyWith(color: enteColor.textMuted),
),
Flexible(
child: Text(
log,
softWrap: true,
style:
enteTextTheme.small.copyWith(color: enteColor.textMuted),
),
),
],
),
),
);
}
final content = Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
S.of(context).aNewVersionOfEnteIsAvailable,
style: enteTextTheme.body.copyWith(color: enteColor.textMuted),
),
const Padding(padding: EdgeInsets.all(8)),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: changelog,
),
const Padding(padding: EdgeInsets.all(8)),
ButtonWidget(
buttonType: ButtonType.primary,
labelText: S.of(context).download,
onTap: () async {
// ignore: unawaited_futures
launchUrlString(
widget.latestVersionInfo!.url,
mode: LaunchMode.externalApplication,
);
},
),
const SizedBox(height: 6),
ButtonWidget(
buttonType: ButtonType.secondary,
labelText: S.of(context).cancel,
onTap: () async {
Navigator.of(context).pop();
},
),
],
);
final shouldForceUpdate =
UpdateService.instance.shouldForceUpdate(widget.latestVersionInfo!);
return PopScope(
canPop: !shouldForceUpdate,
child: AlertDialog(
key: const ValueKey("updateAppDialog"),
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.auto_awesome_outlined,
size: 48,
color: enteColor.strokeMuted,
),
const SizedBox(
height: 16,
),
Text(
shouldForceUpdate
? S.of(context).criticalUpdateAvailable
: S.of(context).updateAvailable,
style: enteTextTheme.h3Bold,
),
],
),
content: content,
),
);
}
}