ente/mobile/lib/ui/settings/app_update_dialog.dart

114 lines
3.5 KiB
Dart
Raw Normal View History

2021-05-22 15:46:04 +00:00
import 'package:flutter/material.dart';
2023-04-06 04:42:07 +00:00
import "package:photos/generated/l10n.dart";
2021-05-22 15:46:04 +00:00
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';
2021-05-22 15:46:04 +00:00
class AppUpdateDialog extends StatefulWidget {
final LatestVersionInfo? latestVersionInfo;
2021-05-22 15:46:04 +00:00
const AppUpdateDialog(this.latestVersionInfo, {Key? key}) : super(key: key);
2021-05-22 15:46:04 +00:00
@override
2022-07-03 09:45:00 +00:00
State<AppUpdateDialog> createState() => _AppUpdateDialogState();
2021-05-22 15:46:04 +00:00
}
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) {
2022-06-11 08:23:52 +00:00
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),
),
2023-08-19 11:39:56 +00:00
),
],
),
2022-06-11 08:23:52 +00:00
),
);
2021-05-22 15:46:04 +00:00
}
final content = Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
2023-04-06 04:42:07 +00:00
S.of(context).aNewVersionOfEnteIsAvailable,
style: enteTextTheme.body.copyWith(color: enteColor.textMuted),
2021-05-22 15:46:04 +00:00
),
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.all(8)),
2021-05-22 15:46:04 +00:00
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: changelog,
),
2022-07-04 06:02:17 +00:00
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();
},
2021-05-22 15:46:04 +00:00
),
],
);
2022-07-03 09:49:33 +00:00
final shouldForceUpdate =
UpdateService.instance.shouldForceUpdate(widget.latestVersionInfo!);
return PopScope(
canPop: !shouldForceUpdate,
2021-05-22 15:46:04 +00:00
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
2023-04-06 04:42:07 +00:00
? S.of(context).criticalUpdateAvailable
: S.of(context).updateAvailable,
style: enteTextTheme.h3Bold,
),
],
2022-06-11 08:23:52 +00:00
),
2021-05-22 15:46:04 +00:00
content: content,
),
);
}
}