From fd8829f08e43cd2eb41c9ac9d638a9c4e7dbc4cc Mon Sep 17 00:00:00 2001
From: NicKoehler <grillinicola@proton.me>
Date: Wed, 1 Mar 2023 14:50:50 +0100
Subject: [PATCH] added icon to dialogButton, reverted some design changes. The
 outline buttons now rely on theme data

---
 flutter/lib/common.dart                       |  79 ++++++--
 flutter/lib/common/widgets/peer_card.dart     |  62 +++---
 .../lib/desktop/pages/file_manager_page.dart  |  47 ++---
 flutter/lib/mobile/widgets/dialog.dart        | 187 ++++++++----------
 flutter/lib/models/file_model.dart            |  39 ++--
 5 files changed, 210 insertions(+), 204 deletions(-)

diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart
index 29d4a195d..47850fdb1 100644
--- a/flutter/lib/common.dart
+++ b/flutter/lib/common.dart
@@ -224,7 +224,20 @@ class MyTheme {
         ),
         shape: MaterialStateProperty.all<RoundedRectangleBorder>(
           RoundedRectangleBorder(
-            borderRadius: BorderRadius.circular(18.0),
+            borderRadius: BorderRadius.circular(8.0),
+          ),
+        ),
+      ),
+    ),
+    outlinedButtonTheme: OutlinedButtonThemeData(
+      style: ButtonStyle(
+        backgroundColor: MaterialStateProperty.all(
+          Color(0xFFEEEEEE),
+        ),
+        foregroundColor: MaterialStateProperty.all(Colors.black87),
+        shape: MaterialStateProperty.all<RoundedRectangleBorder>(
+          RoundedRectangleBorder(
+            borderRadius: BorderRadius.circular(8.0),
           ),
         ),
       ),
@@ -296,9 +309,6 @@ class MyTheme {
     splashColor: Colors.transparent,
     highlightColor: Colors.transparent,
     splashFactory: isDesktop ? NoSplash.splashFactory : null,
-    outlinedButtonTheme: OutlinedButtonThemeData(
-        style:
-            OutlinedButton.styleFrom(side: BorderSide(color: Colors.white38))),
     textButtonTheme: isDesktop
         ? TextButtonThemeData(
             style: ButtonStyle(
@@ -318,7 +328,23 @@ class MyTheme {
         ),
         shape: MaterialStateProperty.all<RoundedRectangleBorder>(
           RoundedRectangleBorder(
-            borderRadius: BorderRadius.circular(18.0),
+            borderRadius: BorderRadius.circular(8.0),
+          ),
+        ),
+      ),
+    ),
+    outlinedButtonTheme: OutlinedButtonThemeData(
+      style: ButtonStyle(
+        backgroundColor: MaterialStatePropertyAll(
+          Color(0xFF24252B),
+        ),
+        side: MaterialStatePropertyAll(
+          BorderSide(color: Colors.white12, width: 0.5),
+        ),
+        foregroundColor: MaterialStateProperty.all(Colors.white70),
+        shape: MaterialStateProperty.all<RoundedRectangleBorder>(
+          RoundedRectangleBorder(
+            borderRadius: BorderRadius.circular(8.0),
           ),
         ),
       ),
@@ -1824,28 +1850,43 @@ class ServerConfig {
 Widget dialogButton(String text,
     {required VoidCallback? onPressed,
     bool isOutline = false,
+    Widget? icon,
     TextStyle? style,
     ButtonStyle? buttonStyle}) {
   if (isDesktop) {
     if (isOutline) {
-      return OutlinedButton(
-        onPressed: onPressed,
-        child: Text(translate(text), style: style),
-      );
+      return icon == null
+          ? OutlinedButton(
+              onPressed: onPressed,
+              child: Text(translate(text), style: style),
+            )
+          : OutlinedButton.icon(
+              icon: icon,
+              onPressed: onPressed,
+              label: Text(translate(text), style: style),
+            );
     } else {
-      return ElevatedButton(
-        style: ElevatedButton.styleFrom(elevation: 0).merge(buttonStyle),
-        onPressed: onPressed,
-        child: Text(translate(text), style: style),
-      );
+      return icon == null
+          ? ElevatedButton(
+              style: ElevatedButton.styleFrom(elevation: 0).merge(buttonStyle),
+              onPressed: onPressed,
+              child: Text(translate(text), style: style),
+            )
+          : ElevatedButton.icon(
+              icon: icon,
+              style: ElevatedButton.styleFrom(elevation: 0).merge(buttonStyle),
+              onPressed: onPressed,
+              label: Text(translate(text), style: style),
+            );
     }
   } else {
     return TextButton(
-        onPressed: onPressed,
-        child: Text(
-          translate(text),
-          style: style,
-        ));
+      onPressed: onPressed,
+      child: Text(
+        translate(text),
+        style: style,
+      ),
+    );
   }
 }
 
diff --git a/flutter/lib/common/widgets/peer_card.dart b/flutter/lib/common/widgets/peer_card.dart
index cc5568bca..5a7f2bfa7 100644
--- a/flutter/lib/common/widgets/peer_card.dart
+++ b/flutter/lib/common/widgets/peer_card.dart
@@ -683,23 +683,21 @@ abstract class BasePeerCard extends StatelessWidget {
             Obx(() => Offstage(
                 offstage: isInProgress.isFalse,
                 child: const LinearProgressIndicator())),
-            Row(
-              mainAxisAlignment: MainAxisAlignment.spaceBetween,
-              children: [
-                ElevatedButton.icon(
-                  icon: Icon(Icons.close_rounded),
-                  label: Text(translate("Cancel")),
-                  onPressed: close,
-                ),
-                ElevatedButton.icon(
-                  icon: Icon(Icons.done_rounded),
-                  label: Text(translate("Ok")),
-                  onPressed: submit,
-                ),
-              ],
-            ).paddingOnly(top: 20)
           ],
         ),
+        actions: [
+          dialogButton(
+            "Cancel",
+            icon: Icon(Icons.close_rounded),
+            onPressed: close,
+            isOutline: true,
+          ),
+          dialogButton(
+            "OK",
+            icon: Icon(Icons.done_rounded),
+            onPressed: submit,
+          ),
+        ],
         onSubmit: submit,
         onCancel: close,
       );
@@ -740,26 +738,20 @@ abstract class BasePeerCard extends StatelessWidget {
               ),
             ],
           ),
-          content: Column(
-            crossAxisAlignment: CrossAxisAlignment.start,
-            children: [
-              Row(
-                mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                children: [
-                  ElevatedButton.icon(
-                    icon: Icon(Icons.close_rounded),
-                    label: Text(translate("Cancel")),
-                    onPressed: close,
-                  ),
-                  ElevatedButton.icon(
-                    icon: Icon(Icons.done_rounded),
-                    label: Text(translate("Ok")),
-                    onPressed: submit,
-                  ),
-                ],
-              ).paddingOnly(top: 20)
-            ],
-          ),
+          content: SizedBox.shrink(),
+          actions: [
+            dialogButton(
+              "Cancel",
+              icon: Icon(Icons.close_rounded),
+              onPressed: close,
+              isOutline: true,
+            ),
+            dialogButton(
+              "OK",
+              icon: Icon(Icons.done_rounded),
+              onPressed: submit,
+            ),
+          ],
           onSubmit: submit,
           onCancel: close,
         );
diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dart
index 9210a30c1..9c72caa5f 100644
--- a/flutter/lib/desktop/pages/file_manager_page.dart
+++ b/flutter/lib/desktop/pages/file_manager_page.dart
@@ -989,37 +989,30 @@ class _FileManagerPageState extends State<FileManagerPage>
                             content: Column(
                               mainAxisSize: MainAxisSize.min,
                               children: [
-                                Column(
-                                  children: [
-                                    TextFormField(
-                                      decoration: InputDecoration(
-                                        labelText: translate(
-                                          "Please enter the folder name",
-                                        ),
-                                      ),
-                                      controller: name,
-                                      autofocus: true,
+                                TextFormField(
+                                  decoration: InputDecoration(
+                                    labelText: translate(
+                                      "Please enter the folder name",
                                     ),
-                                    Row(
-                                      mainAxisAlignment:
-                                          MainAxisAlignment.spaceBetween,
-                                      children: [
-                                        ElevatedButton.icon(
-                                          icon: Icon(Icons.close_rounded),
-                                          label: Text(translate("Cancel")),
-                                          onPressed: cancel,
-                                        ),
-                                        ElevatedButton.icon(
-                                          icon: Icon(Icons.done_rounded),
-                                          label: Text(translate("Ok")),
-                                          onPressed: submit,
-                                        ),
-                                      ],
-                                    ).paddingOnly(top: 20)
-                                  ],
+                                  ),
+                                  controller: name,
+                                  autofocus: true,
                                 ),
                               ],
                             ),
+                            actions: [
+                              dialogButton(
+                                "Cancel",
+                                icon: Icon(Icons.close_rounded),
+                                onPressed: cancel,
+                                isOutline: true,
+                              ),
+                              dialogButton(
+                                "Ok",
+                                icon: Icon(Icons.done_rounded),
+                                onPressed: submit,
+                              ),
+                            ],
                             onSubmit: submit,
                             onCancel: cancel,
                           );
diff --git a/flutter/lib/mobile/widgets/dialog.dart b/flutter/lib/mobile/widgets/dialog.dart
index 6b87d62ba..3832ca7b1 100644
--- a/flutter/lib/mobile/widgets/dialog.dart
+++ b/flutter/lib/mobile/widgets/dialog.dart
@@ -28,27 +28,21 @@ void showRestartRemoteDevice(
               Icon(Icons.warning_rounded, color: Colors.redAccent, size: 28),
               Text(translate("Restart Remote Device")).paddingOnly(left: 10),
             ]),
-            content: Column(
-              children: [
-                Text(
-                    "${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
-                Row(
-                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                  children: [
-                    ElevatedButton.icon(
-                      icon: Icon(Icons.close_rounded),
-                      label: Text(translate("Cancel")),
-                      onPressed: close,
-                    ),
-                    ElevatedButton.icon(
-                      icon: Icon(Icons.done_rounded),
-                      label: Text(translate("Ok")),
-                      onPressed: () => close(true),
-                    ),
-                  ],
-                ).paddingOnly(top: 20)
-              ],
-            ),
+            content: Text(
+                "${translate('Are you sure you want to restart')} \n${pi.username}@${pi.hostname}($id) ?"),
+            actions: [
+              dialogButton(
+                "Cancel",
+                icon: Icon(Icons.close_rounded),
+                onPressed: close,
+                isOutline: true,
+              ),
+              dialogButton(
+                "OK",
+                icon: Icon(Icons.done_rounded),
+                onPressed: () => close(true),
+              ),
+            ],
             onCancel: close,
             onSubmit: () => close(true),
           ));
@@ -82,76 +76,65 @@ void setPermanentPasswordDialog(OverlayDialogManager dialogManager) async {
           Text(translate('Set your own password')).paddingOnly(left: 10),
         ],
       ),
-      content: Column(
-        children: [
-          Form(
-            autovalidateMode: AutovalidateMode.onUserInteraction,
-            child: Column(
-              mainAxisSize: MainAxisSize.min,
-              children: [
-                TextFormField(
-                  autofocus: true,
-                  obscureText: true,
-                  keyboardType: TextInputType.visiblePassword,
-                  decoration: InputDecoration(
-                    labelText: translate('Password'),
-                  ),
-                  controller: p0,
-                  validator: (v) {
-                    if (v == null) return null;
-                    final val = v.trim().length > 5;
-                    if (validateLength != val) {
-                      // use delay to make setState success
-                      Future.delayed(Duration(microseconds: 1),
-                          () => setState(() => validateLength = val));
-                    }
-                    return val
-                        ? null
-                        : translate('Too short, at least 6 characters.');
-                  },
-                ),
-                TextFormField(
-                  obscureText: true,
-                  keyboardType: TextInputType.visiblePassword,
-                  decoration: InputDecoration(
-                    labelText: translate('Confirmation'),
-                  ),
-                  controller: p1,
-                  validator: (v) {
-                    if (v == null) return null;
-                    final val = p0.text == v;
-                    if (validateSame != val) {
-                      Future.delayed(Duration(microseconds: 1),
-                          () => setState(() => validateSame = val));
-                    }
-                    return val
-                        ? null
-                        : translate('The confirmation is not identical.');
-                  },
-                ),
-                Row(
-                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                  children: [
-                    ElevatedButton.icon(
-                      icon: Icon(Icons.close_rounded),
-                      label: Text(translate("Cancel")),
-                      onPressed: close,
-                    ),
-                    ElevatedButton.icon(
-                      icon: Icon(Icons.done_rounded),
-                      label: Text(translate("Ok")),
-                      onPressed:
-                          (validateLength && validateSame) ? submit : null,
-                    ),
-                  ],
-                ).paddingOnly(top: 20)
-              ],
+      content: Form(
+          autovalidateMode: AutovalidateMode.onUserInteraction,
+          child: Column(mainAxisSize: MainAxisSize.min, children: [
+            TextFormField(
+              autofocus: true,
+              obscureText: true,
+              keyboardType: TextInputType.visiblePassword,
+              decoration: InputDecoration(
+                labelText: translate('Password'),
+              ),
+              controller: p0,
+              validator: (v) {
+                if (v == null) return null;
+                final val = v.trim().length > 5;
+                if (validateLength != val) {
+                  // use delay to make setState success
+                  Future.delayed(Duration(microseconds: 1),
+                      () => setState(() => validateLength = val));
+                }
+                return val
+                    ? null
+                    : translate('Too short, at least 6 characters.');
+              },
             ),
-          ),
-        ],
-      ),
+            TextFormField(
+              obscureText: true,
+              keyboardType: TextInputType.visiblePassword,
+              decoration: InputDecoration(
+                labelText: translate('Confirmation'),
+              ),
+              controller: p1,
+              validator: (v) {
+                if (v == null) return null;
+                final val = p0.text == v;
+                if (validateSame != val) {
+                  Future.delayed(Duration(microseconds: 1),
+                      () => setState(() => validateSame = val));
+                }
+                return val
+                    ? null
+                    : translate('The confirmation is not identical.');
+              },
+            ),
+          ])),
       onCancel: close,
       onSubmit: (validateLength && validateSame) ? submit : null,
+      actions: [
+        dialogButton(
+          'Cancel',
+          icon: Icon(Icons.close_rounded),
+          onPressed: close,
+          isOutline: true,
+        ),
+        dialogButton(
+          'OK',
+          icon: Icon(Icons.done_rounded),
+          onPressed: (validateLength && validateSame) ? submit : null,
+        ),
+      ],
     );
   });
 }
@@ -233,22 +216,20 @@ void enterPasswordDialog(String id, OverlayDialogManager dialogManager) async {
             }
           },
         ),
-        Row(
-          mainAxisAlignment: MainAxisAlignment.spaceBetween,
-          children: [
-            ElevatedButton.icon(
-              icon: Icon(Icons.close_rounded),
-              label: Text(translate("Cancel")),
-              onPressed: close,
-            ),
-            ElevatedButton.icon(
-              icon: Icon(Icons.done_rounded),
-              label: Text(translate("Ok")),
-              onPressed: submit,
-            ),
-          ],
-        ).paddingOnly(top: 20)
       ]),
+      actions: [
+        dialogButton(
+          'Cancel',
+          icon: Icon(Icons.close_rounded),
+          onPressed: cancel,
+          isOutline: true,
+        ),
+        dialogButton(
+          'OK',
+          icon: Icon(Icons.done_rounded),
+          onPressed: submit,
+        ),
+      ],
       onSubmit: submit,
       onCancel: cancel,
     );
diff --git a/flutter/lib/models/file_model.dart b/flutter/lib/models/file_model.dart
index 7e702f6f2..a899f4106 100644
--- a/flutter/lib/models/file_model.dart
+++ b/flutter/lib/models/file_model.dart
@@ -595,9 +595,10 @@ class FileModel extends ChangeNotifier {
         final count = entries.length > 1 ? "${i + 1}/${entries.length}" : "";
         content = "$dirShow\n\n${entries[i].path}".trim();
         final confirm = await showRemoveDialog(
-            count.isEmpty ? title : "$title ($count)",
-            content,
-            item.isDirectory);
+          count.isEmpty ? title : "$title ($count)",
+          content,
+          item.isDirectory,
+        );
         try {
           if (confirm == true) {
             sendRemoveFile(entries[i].path, i, items.isLocal!);
@@ -647,7 +648,7 @@ class FileModel extends ChangeNotifier {
           ],
         ),
         contentBoxConstraints:
-            BoxConstraints(minHeight: 80, minWidth: 400, maxWidth: 400),
+            BoxConstraints(minHeight: 100, minWidth: 400, maxWidth: 400),
         content: Column(
           crossAxisAlignment: CrossAxisAlignment.start,
           children: [
@@ -673,24 +674,22 @@ class FileModel extends ChangeNotifier {
                       setState(() => removeCheckboxRemember = v);
                     },
                   )
-                : const SizedBox.shrink(),
-            Row(
-              mainAxisAlignment: MainAxisAlignment.spaceBetween,
-              children: [
-                ElevatedButton.icon(
-                  icon: Icon(Icons.close_rounded),
-                  label: Text(translate("Cancel")),
-                  onPressed: cancel,
-                ),
-                ElevatedButton.icon(
-                  icon: Icon(Icons.done_rounded),
-                  label: Text(translate("Ok")),
-                  onPressed: submit,
-                ),
-              ],
-            ).paddingOnly(top: 20)
+                : const SizedBox.shrink()
           ],
         ),
+        actions: [
+          dialogButton(
+            "Cancel",
+            icon: Icon(Icons.close_rounded),
+            onPressed: cancel,
+            isOutline: true,
+          ),
+          dialogButton(
+            "OK",
+            icon: Icon(Icons.done_rounded),
+            onPressed: submit,
+          ),
+        ],
         onSubmit: submit,
         onCancel: cancel,
       );