2022-03-02 12:44:35 +03:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2022-03-02 10:23:29 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
|
|
|
import '../../widgets/circle_timer.dart';
|
|
|
|
import '../models.dart';
|
2022-03-03 12:01:36 +03:00
|
|
|
import 'account_mixin.dart';
|
2022-03-02 10:23:29 +03:00
|
|
|
|
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-03-03 12:01:36 +03:00
|
|
|
const AccountDialog(this.credential, {Key? key}) : super(key: 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.
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return AccountDialog(renamed);
|
2022-03-02 10:23:29 +03:00
|
|
|
},
|
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) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
return deleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> _buildActions(BuildContext context, WidgetRef ref) {
|
|
|
|
return buildActions(ref).map((e) {
|
|
|
|
final action = e.action;
|
|
|
|
return IconButton(
|
|
|
|
icon: e.icon,
|
|
|
|
tooltip: e.text,
|
|
|
|
onPressed: action != null
|
|
|
|
? () {
|
|
|
|
action(context);
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
);
|
|
|
|
}).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-03-02 10:23:29 +03:00
|
|
|
|
2022-03-02 12:44:35 +03:00
|
|
|
return BackdropFilter(
|
|
|
|
filter: ImageFilter.blur(sigmaX: 3, sigmaY: 3),
|
|
|
|
child: Dialog(
|
2022-03-02 10:23:29 +03:00
|
|
|
backgroundColor: Colors.transparent,
|
2022-03-02 12:44:35 +03:00
|
|
|
elevation: 0.0,
|
|
|
|
insetPadding: const EdgeInsets.all(0),
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
appBar: AppBar(
|
2022-03-03 12:01:36 +03:00
|
|
|
actions: _buildActions(context, ref),
|
2022-03-02 12:44:35 +03:00
|
|
|
),
|
|
|
|
body: LayoutBuilder(builder: (context, constraints) {
|
|
|
|
return ListView(
|
|
|
|
children: [
|
|
|
|
GestureDetector(
|
|
|
|
behavior: HitTestBehavior.opaque,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight: constraints.maxHeight,
|
|
|
|
),
|
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {}, // Blocks parent detector GestureDetector
|
|
|
|
child: Material(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(20.0)),
|
|
|
|
elevation: 16.0,
|
|
|
|
child: SizedBox(
|
|
|
|
width: 320,
|
|
|
|
child: Padding(
|
2022-03-02 13:08:07 +03:00
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 12.0, horizontal: 12.0),
|
2022-03-02 12:44:35 +03:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2022-03-02 13:08:07 +03:00
|
|
|
FittedBox(
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
child: Text(
|
2022-03-03 12:01:36 +03:00
|
|
|
formatCode(ref),
|
2022-03-02 13:08:07 +03:00
|
|
|
softWrap: false,
|
2022-03-03 12:01:36 +03:00
|
|
|
style: isExpired(ref)
|
2022-03-02 13:08:07 +03:00
|
|
|
? Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.headline2
|
|
|
|
?.copyWith(color: Colors.grey)
|
|
|
|
: Theme.of(context).textTheme.headline2,
|
|
|
|
),
|
2022-03-02 12:44:35 +03:00
|
|
|
),
|
2022-03-02 13:08:07 +03:00
|
|
|
Text(label),
|
2022-03-02 12:44:35 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: SizedBox.square(
|
|
|
|
dimension: 16,
|
|
|
|
child: code != null
|
|
|
|
? CircleTimer(
|
|
|
|
code.validFrom * 1000,
|
|
|
|
code.validTo * 1000,
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-03-02 10:23:29 +03:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-03-02 12:44:35 +03:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
2022-03-02 10:23:29 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|