]> git.proxmox.com Git - flutter/proxmox_login_manager.git/commitdiff
tree wide: use 'const' with the constructor to improve performance
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 3 Apr 2024 10:26:34 +0000 (12:26 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 3 Apr 2024 10:28:22 +0000 (12:28 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
lib/proxmox_general_settings_form.dart
lib/proxmox_login_form.dart
lib/proxmox_login_model.dart
lib/proxmox_login_selector.dart
lib/proxmox_tfa_form.dart

index 8183fb85bf3312b370b5d83f0acee738eb6c98c4..eb3105d544e3f1fb36386e3d2c35b419a69de9db 100644 (file)
@@ -20,7 +20,7 @@ class _ProxmoxGeneralSettingsFormState
   Widget build(BuildContext context) {
     return Scaffold(
       appBar: AppBar(
-        title: Text('Settings'),
+        title: const Text('Settings'),
       ),
       body: FutureBuilder<ProxmoxGeneralSettingsModel>(
           future: _settings,
@@ -31,8 +31,8 @@ class _ProxmoxGeneralSettingsFormState
                 child: Column(
                   children: [
                     SwitchListTile(
-                      title: Text('Validate SSL connections'),
-                      subtitle: Text('e.g. validates certificates'),
+                      title: const Text('Validate SSL connections'),
+                      subtitle: const Text('e.g. validates certificates'),
                       value: settings.sslValidation!,
                       onChanged: (value) async {
                         await settings
@@ -49,7 +49,7 @@ class _ProxmoxGeneralSettingsFormState
               );
             }
 
-            return Center(
+            return const Center(
               child: CircularProgressIndicator(),
             );
           }),
index b6a4c832622d48cfd791369f6b09a99484eed4e9..f2a771d2054653627ef7af1be574013f9d468d67 100644 (file)
@@ -24,9 +24,9 @@ class ProxmoxProgressModel {
 
 // FIXME: copied from pve_flutter_frontend, re-use common set
 class ProxmoxColors {
-  static final Color orange = Color(0xFFE57000);
-  static final Color supportGrey = Color(0xFFABBABA);
-  static final Color supportBlue = Color(0xFF00617F);
+  static const Color orange = Color(0xFFE57000);
+  static const Color supportGrey = Color(0xFFABBABA);
+  static const Color supportBlue = Color(0xFF00617F);
 }
 
 class ProxmoxLoginForm extends StatefulWidget {
@@ -72,7 +72,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
   Widget build(BuildContext context) {
     if (widget.accessDomains == null) {
       return TextFormField(
-        decoration: InputDecoration(
+        decoration: const InputDecoration(
             icon: Icon(Icons.vpn_lock),
             labelText: 'Origin',
             hintText: 'e.g. 192.168.1.2',
@@ -90,7 +90,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
         mainAxisAlignment: MainAxisAlignment.center,
         children: [
           TextFormField(
-            decoration: InputDecoration(
+            decoration: const InputDecoration(
               icon: Icon(Icons.vpn_lock),
               labelText: 'Origin',
             ),
@@ -98,7 +98,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
             enabled: false,
           ),
           TextFormField(
-            decoration: InputDecoration(
+            decoration: const InputDecoration(
               icon: Icon(Icons.person),
               labelText: 'Username',
             ),
@@ -112,7 +112,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
             autofillHints: [AutofillHints.username],
           ),
           DropdownButtonFormField(
-            decoration: InputDecoration(icon: Icon(Icons.domain)),
+            decoration: const InputDecoration(icon: Icon(Icons.domain)),
             items: widget.accessDomains!
                 .map((e) => DropdownMenuItem(
                       child: ListTile(
@@ -130,7 +130,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
           Stack(
             children: [
               TextFormField(
-                decoration: InputDecoration(
+                decoration: const InputDecoration(
                   icon: Icon(Icons.lock),
                   labelText: 'Password',
                 ),
@@ -150,7 +150,7 @@ class _ProxmoxLoginFormState extends State<ProxmoxLoginForm> {
               Align(
                 alignment: Alignment.bottomRight,
                 child: IconButton(
-                  constraints: BoxConstraints.tight(Size(58, 58)),
+                  constraints: BoxConstraints.tight(const Size(58, 58)),
                   iconSize: 24,
                   icon:
                       Icon(_obscure ? Icons.visibility : Icons.visibility_off),
@@ -251,7 +251,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
             disabledBackgroundColor: Colors.grey,
           ),
         ),
-        colorScheme: ColorScheme.dark().copyWith(
+        colorScheme: const ColorScheme.dark().copyWith(
             primary: ProxmoxColors.orange,
             secondary: ProxmoxColors.orange,
             onSecondary: ProxmoxColors.supportGrey),
@@ -309,7 +309,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
           elevation: 0.0,
           backgroundColor: Colors.transparent,
           leading: IconButton(
-            icon: Icon(Icons.close),
+            icon: const Icon(Icons.close),
             onPressed: () => Navigator.of(context).pop(),
           ),
         ),
@@ -431,7 +431,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
                                                 }
                                               }
                                             : null,
-                                        child: Text('Continue'),
+                                        child: const Text('Continue'),
                                       ),
                                     ),
                                   ),
@@ -544,13 +544,13 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
         showDialog(
           context: context,
           builder: (context) => AlertDialog(
-            title: Text('Version Error'),
-            content: Text(
+            title: const Text('Version Error'),
+            content: const Text(
                 'Proxmox VE version not supported, please update your instance to use this app.'),
             actions: [
               TextButton(
                 onPressed: () => Navigator.of(context).pop(),
-                child: Text('Close'),
+                child: const Text('Close'),
               ),
             ],
           ),
@@ -569,7 +569,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
       if (e.runtimeType == HandshakeException) {
         showDialog(
           context: context,
-          builder: (context) => ProxmoxCertificateErrorDialog(),
+          builder: (context) => const ProxmoxCertificateErrorDialog(),
         );
       } else {
         showDialog(
@@ -598,7 +598,7 @@ class _ProxmoxLoginPageState extends State<ProxmoxLoginPage> {
     } on HandshakeException {
       showDialog(
         context: context,
-        builder: (context) => ProxmoxCertificateErrorDialog(),
+        builder: (context) => const ProxmoxCertificateErrorDialog(),
       );
     }
     return response;
@@ -700,12 +700,12 @@ class ProxmoxProgressOverlay extends StatelessWidget {
           children: [
             Text(
               message,
-              style: TextStyle(
+              style: const TextStyle(
                 fontSize: 20,
               ),
             ),
-            Padding(
-              padding: const EdgeInsets.only(top: 20.0),
+            const Padding(
+              padding: EdgeInsets.only(top: 20.0),
               child: CircularProgressIndicator(),
             )
           ],
@@ -726,12 +726,12 @@ class ConnectionErrorDialog extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return AlertDialog(
-      title: Text('Connection error'),
+      title: const Text('Connection error'),
       content: Text('Could not establish connection: ${this.exception}'),
       actions: [
         TextButton(
           onPressed: () => Navigator.of(context).pop(),
-          child: Text('Close'),
+          child: const Text('Close'),
         ),
       ],
     );
@@ -749,14 +749,14 @@ class ProxmoxApiErrorDialog extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return AlertDialog(
-      title: Text('API Error'),
+      title: const Text('API Error'),
       content: SingleChildScrollView(
         child: Text(exception.message),
       ),
       actions: [
         TextButton(
           onPressed: () => Navigator.of(context).pop(),
-          child: Text('Close'),
+          child: const Text('Close'),
         ),
       ],
     );
@@ -771,12 +771,12 @@ class ProxmoxCertificateErrorDialog extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return AlertDialog(
-      title: Text('Certificate error'),
+      title: const Text('Certificate error'),
       content: SingleChildScrollView(
         child: Column(
           crossAxisAlignment: CrossAxisAlignment.start,
           children: [
-            Text('Your connection is not private.'),
+            const Text('Your connection is not private.'),
             Text(
               'Note: Consider to disable SSL validation,'
               ' if you use a self signed, not commonly trusted, certificate.',
@@ -788,13 +788,13 @@ class ProxmoxCertificateErrorDialog extends StatelessWidget {
       actions: [
         TextButton(
           onPressed: () => Navigator.of(context).pop(),
-          child: Text('Close'),
+          child: const Text('Close'),
         ),
         TextButton(
           onPressed: () => Navigator.of(context).pushReplacement(
               MaterialPageRoute(
                   builder: (context) => ProxmoxGeneralSettingsForm())),
-          child: Text('Settings'),
+          child: const Text('Settings'),
         )
       ],
     );
index 6e9b0e037494b6e9e9e644a19e9b0e616de3088c..6c781f785798f351de2d6c025c412cc37bc04feb 100644 (file)
@@ -127,7 +127,7 @@ abstract class ProxmoxLoginModel
         .firstMatch(ticket!)!;
     final time = DateTime.fromMillisecondsSinceEpoch(
         int.parse(ticketRegex.group(3)!, radix: 16) * 1000);
-    return DateTime.now().isAfter(time.add(Duration(hours: 1)));
+    return DateTime.now().isAfter(time.add(const Duration(hours: 1)));
   }
 }
 
index 8573ab06f986a28bc129271a0f00fb770925fa9a..06e8c39a164851e1f534989e8f2a0102a95e6000 100644 (file)
@@ -33,7 +33,7 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
       child: Scaffold(
         backgroundColor: Theme.of(context).colorScheme.background,
         appBar: AppBar(
-          title: Column(
+          title: const Column(
             crossAxisAlignment: CrossAxisAlignment.start,
             children: [
               Text(
@@ -52,7 +52,7 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
           ),
           actions: [
             IconButton(
-                icon: Icon(Icons.settings),
+                icon: const Icon(Icons.settings),
                 onPressed: () {
                   Navigator.of(context).push(MaterialPageRoute(
                     builder: (context) => ProxmoxGeneralSettingsForm(),
@@ -64,13 +64,13 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
             future: loginStorage,
             builder: (context, snapshot) {
               if (!snapshot.hasData) {
-                return Center(
+                return const Center(
                   child: CircularProgressIndicator(),
                 );
               }
               if (snapshot.hasData &&
                   (snapshot.data!.logins?.isEmpty ?? true)) {
-                return Center(
+                return const Center(
                   child: Text('Add an account'),
                 );
               }
@@ -83,8 +83,8 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
 
               if (activeSessions.isNotEmpty) {
                 items.addAll([
-                  Padding(
-                    padding: const EdgeInsets.all(12.0),
+                  const Padding(
+                    padding: EdgeInsets.all(12.0),
                     child: Text(
                       'Active Sessions',
                       style: TextStyle(
@@ -96,15 +96,15 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                   ...activeSessions.map((s) => ListTile(
                         title: Text(s.fullHostname),
                         subtitle: Text(s.fullUsername),
-                        trailing: Icon(Icons.navigate_next),
+                        trailing: const Icon(Icons.navigate_next),
                         leading: PopupMenuButton(
-                            icon: Icon(Icons.more_vert, color: Colors.green),
+                            icon: const Icon(Icons.more_vert, color: Colors.green),
                             itemBuilder: (context) => [
                                   PopupMenuItem(
                                     child: ListTile(
                                       dense: true,
-                                      leading: Icon(Icons.logout),
-                                      title: Text('Logout'),
+                                      leading: const Icon(Icons.logout),
+                                      title: const Text('Logout'),
                                       onTap: () async {
                                         await snapshot.data!
                                             .rebuild((b) => b.logins
@@ -122,8 +122,8 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                 ]);
               }
               items.addAll([
-                Padding(
-                  padding: const EdgeInsets.all(12.0),
+                const Padding(
+                  padding: EdgeInsets.all(12.0),
                   child: Text(
                     'Available Sites',
                     style: TextStyle(
@@ -136,15 +136,15 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                     ListTile(
                       title: Text(login.fullHostname),
                       subtitle: Text(login.fullUsername),
-                      trailing: Icon(Icons.navigate_next),
+                      trailing: const Icon(Icons.navigate_next),
                       leading: PopupMenuButton(
                           itemBuilder: (context) => [
                                 if (login.passwordSaved ?? false)
                                   PopupMenuItem(
                                     child: ListTile(
                                       dense: true,
-                                      leading: Icon(Icons.key_off),
-                                      title: Text('Delete Password'),
+                                      leading: const Icon(Icons.key_off),
+                                      title: const Text('Delete Password'),
                                       onTap: () async {
                                         await deletePassword(login.identifier!);
 
@@ -163,8 +163,8 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
                                 PopupMenuItem(
                                   child: ListTile(
                                     dense: true,
-                                    leading: Icon(Icons.delete),
-                                    title: Text('Delete'),
+                                    leading: const Icon(Icons.delete),
+                                    title: const Text('Delete'),
                                     onTap: () async {
                                       await deletePassword(login.identifier!);
                                       await snapshot.data!
@@ -186,8 +186,8 @@ class _ProxmoxLoginSelectorState extends State<ProxmoxLoginSelector> {
             }),
         floatingActionButton: FloatingActionButton.extended(
           onPressed: () => _login(isCreate: true),
-          label: Text('Add'),
-          icon: Icon(Icons.account_circle),
+          label: const Text('Add'),
+          icon: const Icon(Icons.account_circle),
         ),
       ),
     );
index 3d5a93bfc56806723a7958d4033fbedb3f824e33..89dec246747379ef5c9483fe1c58915073604e2e 100644 (file)
@@ -28,7 +28,7 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
   Widget build(BuildContext context) {
     return Theme(
       data: ThemeData.dark().copyWith(
-          colorScheme: ColorScheme.dark().copyWith(
+          colorScheme: const ColorScheme.dark().copyWith(
               secondary: ProxmoxColors.orange,
               onSecondary: ProxmoxColors.supportGrey)),
       child: Scaffold(
@@ -38,7 +38,7 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
           elevation: 0.0,
           backgroundColor: Colors.transparent,
           leading: IconButton(
-            icon: Icon(Icons.close),
+            icon: const Icon(Icons.close),
             onPressed: () => Navigator.of(context).pop(),
           ),
         ),
@@ -56,21 +56,21 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
                       mainAxisAlignment: MainAxisAlignment.start,
                       crossAxisAlignment: CrossAxisAlignment.center,
                       children: <Widget>[
-                        Padding(
-                          padding: const EdgeInsets.fromLTRB(0, 100.0, 0, 30.0),
+                        const Padding(
+                          padding: EdgeInsets.fromLTRB(0, 100.0, 0, 30.0),
                           child: Icon(
                             Icons.lock,
                             size: 48,
                           ),
                         ),
-                        Text(
+                        const Text(
                           'Verify',
                           style: TextStyle(
                               fontSize: 36,
                               color: Colors.white,
                               fontWeight: FontWeight.bold),
                         ),
-                        Text(
+                        const Text(
                           'Check your second factor provider',
                           style: TextStyle(
                               color: Colors.white38,
@@ -83,7 +83,7 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
                             child: Column(
                               children: <Widget>[
                                 DropdownButtonFormField(
-                                  decoration: InputDecoration(
+                                  decoration: const InputDecoration(
                                       labelText: 'Method',
                                       icon: Icon(Icons.input)),
                                   items: _tfa_kinds
@@ -104,7 +104,7 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
                                 TextField(
                                     controller: _codeController,
                                     textAlign: TextAlign.center,
-                                    decoration: InputDecoration(
+                                    decoration: const InputDecoration(
                                         labelText: 'Code',
                                         icon: Icon(Icons.pin)),
                                     keyboardType: _selected_tfa_kind == 'totp'
@@ -124,11 +124,11 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
                               child: TextButton(
                                 style: TextButton.styleFrom(
                                   foregroundColor: Colors.white,
-                                  backgroundColor: Color(0xFFE47225),
+                                  backgroundColor: const Color(0xFFE47225),
                                   disabledBackgroundColor: Colors.grey,
                                 ),
                                 onPressed: () => _submitTfaCode(),
-                                child: Text('Continue'),
+                                child: const Text('Continue'),
                               ),
                             ),
                           ),
@@ -140,7 +140,7 @@ class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
               ),
             ),
             if (_isLoading)
-              ProxmoxProgressOverlay(
+              const ProxmoxProgressOverlay(
                 message: 'Verifying second-factor...',
               )
           ],