2022-04-05 15:53:18 +03:00
|
|
|
import 'dart:async';
|
2022-04-03 12:06:22 +03:00
|
|
|
|
2022-03-02 10:23:29 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2022-05-18 16:17:53 +03:00
|
|
|
import '../../app/models.dart';
|
2022-05-12 09:34:51 +03:00
|
|
|
import '../../app/state.dart';
|
2022-04-07 11:48:59 +03:00
|
|
|
import '../../core/state.dart';
|
2022-05-18 16:17:53 +03:00
|
|
|
import '../../theme.dart';
|
2022-03-31 13:25:14 +03:00
|
|
|
import '../../widgets/dialog_frame.dart';
|
2022-03-02 10:23:29 +03:00
|
|
|
import '../models.dart';
|
2022-03-03 12:01:36 +03:00
|
|
|
import 'account_mixin.dart';
|
2022-03-02 10:23:29 +03:00
|
|
|
|
2022-05-18 16:17:53 +03:00
|
|
|
extension on MenuAction {
|
|
|
|
Color? get iconColor => text.startsWith('Copy') ? Colors.black : Colors.white;
|
|
|
|
|
|
|
|
Color get backgroundColor => text.startsWith('Copy')
|
|
|
|
? primaryGreen
|
|
|
|
: (text.startsWith('Delete')
|
|
|
|
? const Color(0xffea4335)
|
|
|
|
: const Color(0xff3d3d3d));
|
|
|
|
}
|
|
|
|
|
2022-03-03 12:01:36 +03:00
|
|
|
class AccountDialog extends ConsumerWidget with AccountMixin {
|
|
|
|
@override
|
2022-03-02 10:23:29 +03:00
|
|
|
final OathCredential credential;
|
2022-05-12 10:56:55 +03:00
|
|
|
const AccountDialog(this.credential, {super.key});
|
2022-03-02 10:23:29 +03:00
|
|
|
|
2022-03-03 12:01:36 +03:00
|
|
|
@override
|
|
|
|
Future<OathCredential?> renameCredential(
|
|
|
|
BuildContext context, WidgetRef ref) async {
|
|
|
|
final renamed = await super.renameCredential(context, ref);
|
|
|
|
if (renamed != null) {
|
|
|
|
// Replace this dialog with a new one, for the renamed credential.
|
2022-05-12 09:34:51 +03:00
|
|
|
await ref.read(withContextProvider)((context) async {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return AccountDialog(renamed);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2022-03-03 12:01:36 +03:00
|
|
|
}
|
|
|
|
return renamed;
|
2022-03-02 10:23:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-03-03 12:01:36 +03:00
|
|
|
Future<bool> deleteCredential(BuildContext context, WidgetRef ref) async {
|
|
|
|
final deleted = await super.deleteCredential(context, ref);
|
|
|
|
if (deleted) {
|
2022-05-12 09:34:51 +03:00
|
|
|
await ref.read(withContextProvider)((context) async {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
});
|
2022-03-03 12:01:36 +03:00
|
|
|
}
|
|
|
|
return deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> _buildActions(BuildContext context, WidgetRef ref) {
|
2022-03-03 15:55:07 +03:00
|
|
|
return buildActions(context, ref).map((e) {
|
2022-03-03 12:01:36 +03:00
|
|
|
final action = e.action;
|
2022-05-18 16:17:53 +03:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
|
|
child: CircleAvatar(
|
|
|
|
backgroundColor: e.backgroundColor,
|
|
|
|
child: IconButton(
|
|
|
|
color: e.iconColor,
|
|
|
|
icon: e.icon,
|
|
|
|
tooltip: e.text,
|
|
|
|
onPressed: action != null
|
|
|
|
? () {
|
|
|
|
action(context);
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
),
|
2022-03-03 12:01:36 +03:00
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
}
|
2022-03-02 10:23:29 +03:00
|
|
|
|
2022-03-03 12:01:36 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final code = getCode(ref);
|
2022-04-05 15:53:18 +03:00
|
|
|
if (code == null) {
|
2022-04-07 11:48:59 +03:00
|
|
|
if (isDesktop) {
|
|
|
|
Timer(Duration.zero, () => calculateCode(context, ref));
|
|
|
|
}
|
2022-04-05 15:53:18 +03:00
|
|
|
}
|
2022-03-31 13:25:14 +03:00
|
|
|
return DialogFrame(
|
|
|
|
child: AlertDialog(
|
2022-05-18 18:29:50 +03:00
|
|
|
title: Center(
|
|
|
|
child: Text(
|
|
|
|
title,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
|
|
maxLines: 1,
|
|
|
|
softWrap: false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12.0),
|
2022-03-31 13:25:14 +03:00
|
|
|
content: Column(
|
2022-05-18 18:29:50 +03:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2022-03-31 13:25:14 +03:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2022-05-18 18:29:50 +03:00
|
|
|
if (subtitle != null)
|
|
|
|
Text(
|
|
|
|
subtitle!,
|
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
maxLines: 1,
|
|
|
|
softWrap: false,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 12.0),
|
|
|
|
DecoratedBox(
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
shape: BoxShape.rectangle,
|
|
|
|
color: Color(0xff3d3d3d),
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(30.0)),
|
|
|
|
),
|
|
|
|
child: Center(
|
|
|
|
child: FittedBox(child: buildCodeView(ref, big: true)),
|
|
|
|
),
|
|
|
|
),
|
2022-03-31 13:25:14 +03:00
|
|
|
],
|
2022-03-02 12:44:35 +03:00
|
|
|
),
|
2022-05-18 18:29:50 +03:00
|
|
|
actionsPadding: const EdgeInsets.only(top: 10.0, right: -16.0),
|
2022-05-18 16:17:53 +03:00
|
|
|
actions: [
|
|
|
|
Center(
|
|
|
|
child: FittedBox(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Row(children: _buildActions(context, ref)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2022-03-02 10:23:29 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|