Change subTitle to subtitle and make overlay required.

This commit is contained in:
Elias Bonnici 2024-01-09 12:17:37 +01:00
parent 33be7edbf0
commit ec1459315d
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
6 changed files with 56 additions and 64 deletions

View File

@ -51,7 +51,8 @@ class AppPage extends StatelessWidget {
this.onFileDropped,
this.delayedContent = false,
this.keyActionsBadge = false,
});
}) : assert(!(onFileDropped != null && fileDropOverlay == null),
'Declaring onFileDropped requires declaring a fileDropOverlay');
@override
Widget build(BuildContext context) => LayoutBuilder(
@ -209,7 +210,7 @@ class AppPage extends StatelessWidget {
child: onFileDropped != null
? FileDropTarget(
onFileDropped: onFileDropped!,
overlay: fileDropOverlay,
overlay: fileDropOverlay!,
child: body,
)
: body,
@ -276,7 +277,7 @@ class AppPage extends StatelessWidget {
Expanded(
child: FileDropTarget(
onFileDropped: onFileDropped!,
overlay: fileDropOverlay,
overlay: fileDropOverlay!,
child: body,
),
)

View File

@ -71,7 +71,7 @@ class _AddAccountDialogState extends ConsumerState<AddAccountDialog> {
},
overlay: FileDropOverlay(
title: l10n.s_add_account,
subTitle: l10n.l_drop_qr_description,
subtitle: l10n.l_drop_qr_description,
),
child: ResponsiveDialog(
title: Text(l10n.s_add_account),

View File

@ -340,7 +340,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
},
overlay: FileDropOverlay(
title: l10n.s_add_account,
subTitle: l10n.l_drop_qr_description,
subtitle: l10n.l_drop_qr_description,
),
child: ResponsiveDialog(
title: Text(l10n.s_add_account),

View File

@ -133,15 +133,15 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
final hasActions = ref.watch(featureProvider)(features.actions);
Future<void> onFileDropped(List<int> fileData) async {
final qrScanner = ref.watch(qrScannerProvider);
final withContext = ref.read(withContextProvider);
final credentials = ref.read(credentialsProvider);
final qrScanner = ref.read(qrScannerProvider);
if (qrScanner != null) {
final b64Image = base64Encode(fileData);
final qrData = await qrScanner.scanQr(b64Image);
final withContext = ref.read(withContextProvider);
await withContext(
(context) async {
if (qrData != null) {
final credentials = ref.read(credentialsProvider);
await handleUri(context, credentials, qrData, widget.devicePath,
widget.oathState, l10n);
} else {
@ -167,7 +167,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
onFileDropped: onFileDropped,
fileDropOverlay: FileDropOverlay(
title: l10n.s_add_account,
subTitle: l10n.l_drop_qr_description,
subtitle: l10n.l_drop_qr_description,
),
);
}
@ -253,7 +253,7 @@ class _UnlockedViewState extends ConsumerState<_UnlockedView> {
onFileDropped: onFileDropped,
fileDropOverlay: FileDropOverlay(
title: l10n.s_add_account,
subTitle: l10n.l_drop_qr_description,
subtitle: l10n.l_drop_qr_description,
),
centered: numCreds == null,
delayedContent: numCreds == null,

View File

@ -3,51 +3,47 @@ import 'package:flutter/material.dart';
class FileDropOverlay extends StatelessWidget {
final Widget? graphic;
final String? title;
final String? subTitle;
final String? subtitle;
const FileDropOverlay({super.key, this.graphic, this.title, this.subTitle});
const FileDropOverlay({super.key, this.graphic, this.title, this.subtitle});
@override
Widget build(BuildContext context) {
return Positioned.fill(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.secondaryContainer
.withOpacity(0.95),
border: Border.all(color: Theme.of(context).colorScheme.primary),
borderRadius: const BorderRadius.all(Radius.circular(20.0))),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
graphic ??
Icon(
Icons.upload_file,
size: 120,
color: Theme.of(context).colorScheme.primary,
),
if (title != null) ...[
const SizedBox(height: 16.0),
Text(
title!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)
],
if (subTitle != null) ...[
const SizedBox(height: 12.0),
Text(
subTitle!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleSmall,
)
]
return Container(
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.secondaryContainer
.withOpacity(0.95),
border: Border.all(color: Theme.of(context).colorScheme.primary),
borderRadius: const BorderRadius.all(Radius.circular(20.0))),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
graphic ??
Icon(
Icons.upload_file,
size: 120,
color: Theme.of(context).colorScheme.primary,
),
if (title != null) ...[
const SizedBox(height: 16.0),
Text(
title!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
)
],
),
if (subtitle != null) ...[
const SizedBox(height: 12.0),
Text(
subtitle!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleSmall,
)
]
],
),
));
);
}
}

View File

@ -22,13 +22,13 @@ import '../core/state.dart';
class FileDropTarget extends StatefulWidget {
final Widget child;
final Function(List<int> filedata) onFileDropped;
final Widget? overlay;
final Widget overlay;
const FileDropTarget({
super.key,
required this.child,
required this.onFileDropped,
this.overlay,
required this.overlay,
});
@override
@ -38,17 +38,6 @@ class FileDropTarget extends StatefulWidget {
class _FileDropTargetState extends State<FileDropTarget> {
bool _hovering = false;
Widget _buildDefaultOverlay() => Positioned.fill(
child: Container(
color: Colors.blue.withOpacity(0.4),
child: Icon(
Icons.upload_file,
size: 200,
color: Colors.black.withOpacity(0.6),
),
),
);
@override
Widget build(BuildContext context) {
return DropTarget(
@ -77,7 +66,13 @@ class _FileDropTargetState extends State<FileDropTarget> {
child: Stack(
children: [
widget.child,
if (_hovering) widget.overlay ?? _buildDefaultOverlay(),
if (_hovering)
Positioned.fill(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: widget.overlay,
),
)
],
),
);