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

View File

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

View File

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

View File

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

View File

@ -3,16 +3,13 @@ import 'package:flutter/material.dart';
class FileDropOverlay extends StatelessWidget { class FileDropOverlay extends StatelessWidget {
final Widget? graphic; final Widget? graphic;
final String? title; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Positioned.fill( return Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
@ -37,17 +34,16 @@ class FileDropOverlay extends StatelessWidget {
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,
) )
], ],
if (subTitle != null) ...[ if (subtitle != null) ...[
const SizedBox(height: 12.0), const SizedBox(height: 12.0),
Text( Text(
subTitle!, subtitle!,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleSmall, style: Theme.of(context).textTheme.titleSmall,
) )
] ]
], ],
), ),
), );
));
} }
} }

View File

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