Refactor: extract server cert dialogs

This commit is contained in:
Ming Ming 2024-06-18 00:37:06 +08:00
parent 0b766723d8
commit 9bf3e0e7ff
2 changed files with 64 additions and 41 deletions

View file

@ -18,6 +18,7 @@ import 'package:nc_photos/platform/features.dart' as features;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/url_launcher_util.dart';
import 'package:nc_photos/use_case/ls_single_file.dart';
import 'package:nc_photos/widget/server_cert_error_dialog.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:np_string/np_string.dart';
@ -132,58 +133,22 @@ class _ConnectState extends State<Connect> {
void _onSelfSignedCert(BuildContext context) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(L10n.global().serverCertErrorDialogTitle),
content: Text(L10n.global().serverCertErrorDialogContent),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(L10n.global().advancedButtonLabel),
),
],
),
builder: (_) => const ServerCertErrorDialog(),
).then((value) {
if (value != true) {
Navigator.of(context).pop(null);
Navigator.of(context).pop();
return;
}
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(L10n.global().whitelistCertDialogTitle),
content: Text(L10n.global().whitelistCertDialogContent(
SelfSignedCertManager().getLastBadCertHost(),
SelfSignedCertManager().getLastBadCertFingerprint())),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(L10n.global().whitelistCertButtonLabel),
),
],
),
builder: (context) => const WhitelistLastBadCertDialog(),
).then((value) {
if (value != true) {
Navigator.of(context).pop(null);
Navigator.of(context).pop();
return;
}
SelfSignedCertManager().whitelistLastBadCert().then((value) {
Navigator.of(context).pop(null);
Navigator.of(context).pop();
});
});
});

View file

@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:nc_photos/app_localizations.dart';
import 'package:nc_photos/mobile/self_signed_cert_manager.dart';
class ServerCertErrorDialog extends StatelessWidget {
const ServerCertErrorDialog({super.key});
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(L10n.global().serverCertErrorDialogTitle),
content: Text(L10n.global().serverCertErrorDialogContent),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(MaterialLocalizations.of(context).closeButtonLabel),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(L10n.global().advancedButtonLabel),
),
],
);
}
}
class WhitelistLastBadCertDialog extends StatelessWidget {
const WhitelistLastBadCertDialog({super.key});
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(L10n.global().whitelistCertDialogTitle),
content: Text(L10n.global().whitelistCertDialogContent(
SelfSignedCertManager().getLastBadCertHost(),
SelfSignedCertManager().getLastBadCertFingerprint(),
)),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(MaterialLocalizations.of(context).cancelButtonLabel),
),
TextButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(L10n.global().whitelistCertButtonLabel),
),
],
);
}
}