From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id EF99C9151B
 for <pve-devel@lists.proxmox.com>; Thu,  8 Sep 2022 11:56:22 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id CEE0A1ADE7
 for <pve-devel@lists.proxmox.com>; Thu,  8 Sep 2022 11:55:58 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Thu,  8 Sep 2022 11:55:53 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 03A7144567
 for <pve-devel@lists.proxmox.com>; Thu,  8 Sep 2022 11:55:53 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu,  8 Sep 2022 11:55:49 +0200
Message-Id: <20220908095550.2913416-13-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20220908095550.2913416-1-d.csapak@proxmox.com>
References: <20220908095550.2913416-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.092 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pve-devel] [PATCH pve-flutter-frontend 09/10] fix guest backup
 widget start display
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 08 Sep 2022 09:56:23 -0000

when we changed from ScaffoldState to ScaffoldMessengerState, we missed
that we have to wrap the scaffold in a ScaffoldMessenger, otherwise
there is no current state and we never could show a snack

we also have to do the null safety of the 'nodesVZDumpCreateBackup'
differently, since we get a Future<String?>, which cannot be converted
to FutureOr<String>, we got an exception (that we never saw because
of the Missing ScaffoldMessenger)

same is true for the 'remove' button

despite that the backup always actually ran, but the user did not get
any visual feedback

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 lib/widgets/pve_guest_backup_widget.dart | 144 ++++++++++++-----------
 1 file changed, 73 insertions(+), 71 deletions(-)

diff --git a/lib/widgets/pve_guest_backup_widget.dart b/lib/widgets/pve_guest_backup_widget.dart
index e6aebde..05cd725 100644
--- a/lib/widgets/pve_guest_backup_widget.dart
+++ b/lib/widgets/pve_guest_backup_widget.dart
@@ -265,11 +265,11 @@ class PveGuestBackupContent extends StatelessWidget {
                     ),
                     OutlinedButton.icon(
                       onPressed: () async {
-                        final guard = await (_showConfirmDialog(
+                        final guard = (await _showConfirmDialog(
                                 context,
                                 'Attention',
                                 'Do you really want to delete this backup?')
-                            as FutureOr<bool>);
+                           )!;
                         if (guard) {
                           fBloc.events.add(DeleteFile(volid));
                           Navigator.of(context).pop();
@@ -417,77 +417,79 @@ class _PveBackupFormState extends State<PveBackupForm> {
 
   @override
   Widget build(BuildContext context) {
-    return Scaffold(
+    return ScaffoldMessenger(
       key: _scaffoldKey,
-      appBar: AppBar(
-        iconTheme: IconThemeData(color: Colors.black),
-        backgroundColor: Colors.transparent,
-        elevation: 0,
-        title: Text(
-          "Schedule backup",
-          style: TextStyle(color: Colors.black),
+      child: Scaffold(
+        appBar: AppBar(
+          iconTheme: IconThemeData(color: Colors.black),
+          backgroundColor: Colors.transparent,
+          elevation: 0,
+          title: Text(
+            "Schedule backup",
+            style: TextStyle(color: Colors.black),
+          ),
         ),
-      ),
-      body: SingleChildScrollView(
-          padding: EdgeInsets.all(8),
-          child: Form(
-            key: _formKey,
-            onChanged: () {
-              final isValid = _formKey.currentState!.validate();
-              setState(() {
-                enableSubmitButton = isValid;
-              });
-            },
-            child: Column(
-              children: [
-                PveStorageSelectorDropdown(
-                  labelText: 'Storage',
-                  sBloc: widget.sBloc,
-                  allowBlank: false,
-                ),
-                _createModeDropdown(),
-                _createCompressionDropdown(),
-                TextFormField(
-                  decoration: InputDecoration(
-                    labelText: 'Email to',
-                    helperText: ' ',
+        body: SingleChildScrollView(
+            padding: EdgeInsets.all(8),
+            child: Form(
+              key: _formKey,
+              onChanged: () {
+                final isValid = _formKey.currentState!.validate();
+                setState(() {
+                  enableSubmitButton = isValid;
+                });
+              },
+              child: Column(
+                children: [
+                  PveStorageSelectorDropdown(
+                    labelText: 'Storage',
+                    sBloc: widget.sBloc,
+                    allowBlank: false,
                   ),
-                  controller: emailToController,
-                  autovalidateMode: AutovalidateMode.onUserInteraction,
-                  validator: (value) {
-                    if (value!.isNotEmpty && !Validators.isValidEmail(value)) {
-                      return 'Please enter valid email address';
-                    }
-                    return null;
-                  },
-                ),
-                OutlinedButton.icon(
-                    onPressed: enableSubmitButton
-                        ? () {
-                            //TODO remove when async validation is implemented
-                            if (!_formKey.currentState!.validate()) {
-                              setState(() {
-                                enableSubmitButton = false;
-                              });
-                              return;
-                            }
+                  _createModeDropdown(),
+                  _createCompressionDropdown(),
+                  TextFormField(
+                    decoration: InputDecoration(
+                      labelText: 'Email to',
+                      helperText: ' ',
+                    ),
+                    controller: emailToController,
+                    autovalidateMode: AutovalidateMode.onUserInteraction,
+                    validator: (value) {
+                      if (value!.isNotEmpty && !Validators.isValidEmail(value)) {
+                        return 'Please enter valid email address';
+                      }
+                      return null;
+                    },
+                  ),
+                  OutlinedButton.icon(
+                      onPressed: enableSubmitButton
+                          ? () {
+                              //TODO remove when async validation is implemented
+                              if (!_formKey.currentState!.validate()) {
+                                setState(() {
+                                  enableSubmitButton = false;
+                                });
+                                return;
+                              }
 
-                            startBackup(
-                              widget.sBloc.apiClient,
-                              widget.sBloc.latestState.nodeID,
-                              widget.sBloc.latestState.selected!.id,
-                              widget.guestID,
-                              compression,
-                              mode!,
-                              mailTo: emailToController!.text,
-                            );
-                          }
-                        : null,
-                    icon: Icon(Icons.save),
-                    label: Text('Start backup now'))
-              ],
-            ),
-          )),
+                              startBackup(
+                                widget.sBloc.apiClient,
+                                widget.sBloc.latestState.nodeID,
+                                widget.sBloc.latestState.selected!.id,
+                                widget.guestID,
+                                compression,
+                                mode!,
+                                mailTo: emailToController!.text,
+                              );
+                            }
+                          : null,
+                      icon: Icon(Icons.save),
+                      label: Text('Start backup now'))
+                ],
+              ),
+            )),
+      )
     );
   }
 
@@ -501,11 +503,11 @@ class _PveBackupFormState extends State<PveBackupForm> {
     String? mailTo,
   }) async {
     try {
-      final jobId = await (apiClient.nodesVZDumpCreateBackup(
+      final jobId = (await apiClient.nodesVZDumpCreateBackup(
           node, storage, guestId,
           compressionType: compression,
           mode: mode,
-          mailTo: mailTo) as FutureOr<String>);
+          mailTo: mailTo))!;
 
       await showTaskLogBottomSheet(context, apiClient, node, jobId,
           icon: Icon(Icons.save), jobTitle: Text('Backup $guestId'));
-- 
2.30.2