From b1350b825fed49fb2e8501a7f0d0e07c157c7775 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 13 Jun 2024 15:40:25 +0100 Subject: [PATCH] Fix deprecations and code style --- lib/main.dart | 1 + lib/src/pages/downloader_page.dart | 4 +-- lib/src/pages/main_page.dart | 4 +-- lib/src/pages/manager.dart | 33 +++++++++---------- .../widgets/home_page/downloader_menu.dart | 4 +-- .../home_page/home_page_button_group.dart | 8 ++--- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 73d9857..738372b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:provider/provider.dart'; diff --git a/lib/src/pages/downloader_page.dart b/lib/src/pages/downloader_page.dart index 16bcb52..fd66b5f 100644 --- a/lib/src/pages/downloader_page.dart +++ b/lib/src/pages/downloader_page.dart @@ -13,8 +13,8 @@ class DownloaderPage extends StatelessWidget { appBar: AppBar( title: Text(context.t('Downloader')), ), - body: Column( - children: const [ + body: const Column( + children: [ Logo(), DownloaderMenu(), ], diff --git a/lib/src/pages/main_page.dart b/lib/src/pages/main_page.dart index ca0c469..823b735 100644 --- a/lib/src/pages/main_page.dart +++ b/lib/src/pages/main_page.dart @@ -28,8 +28,8 @@ class _MainPageState extends State { title: Text(context.t('Main menu')), ), drawer: const LeftMenu(), - body: Column( - children: const [ + body: const Column( + children: [ Logo(), MainMenu(), ], diff --git a/lib/src/pages/manager.dart b/lib/src/pages/manager.dart index 21dee40..2bf5df7 100644 --- a/lib/src/pages/manager.dart +++ b/lib/src/pages/manager.dart @@ -138,10 +138,10 @@ class _ManagerState extends State with PreferencesMixin { if ((entity.path.endsWith('.conf')) && (_isValidConf(entity.path))) { String name = path.basenameWithoutExtension(entity.path); currentVms.add(name); - File pidFile = File(name + '/' + name + '.pid'); + File pidFile = File('$name/$name.pid'); if (pidFile.existsSync()) { String pid = pidFile.readAsStringSync().trim(); - Directory procDir = Directory('/proc/' + pid); + Directory procDir = Directory('/proc/$pid'); if (procDir.existsSync()) { if (_activeVms.containsKey(name)) { activeVms[name] = _activeVms[name]!; @@ -172,11 +172,11 @@ class _ManagerState extends State with PreferencesMixin { } Widget _buildVmList() { - List _widgetList = []; + List widgetList = []; final Color buttonColor = Theme.of(context).brightness == Brightness.dark ? Colors.white70 : Theme.of(context).colorScheme.primary; - _widgetList.addAll( + widgetList.addAll( [ Padding( padding: const EdgeInsets.symmetric(vertical: 16.0), @@ -222,12 +222,12 @@ class _ManagerState extends State with PreferencesMixin { return _buildRow(vm, buttonColor); }).toList(); for (var row in rows) { - _widgetList.addAll(row); + widgetList.addAll(row); } return ListView( padding: const EdgeInsets.all(16.0), - children: _widgetList, + children: widgetList, ); } @@ -239,10 +239,10 @@ class _ManagerState extends State with PreferencesMixin { if (active) { vmInfo = _activeVms[currentVm]!; if (vmInfo.spicePort != null) { - connectInfo += context.t('SPICE port') + ': ' + vmInfo.spicePort! + ' '; + connectInfo += '${context.t('SPICE port')}: ${vmInfo.spicePort!} '; } if (vmInfo.sshPort != null && _terminalEmulator != null) { - connectInfo += context.t('SSH port') + ': ' + vmInfo.sshPort! + ' '; + connectInfo += '${context.t('SSH port')}: ${vmInfo.sshPort!} '; _detectSsh(int.parse(vmInfo.sshPort!)).then((sshRunning) { if (sshRunning && !sshy) { setState(() { @@ -331,12 +331,8 @@ class _ManagerState extends State with PreferencesMixin { showDialog( context: context, builder: (BuildContext context) => AlertDialog( - title: Text('Delete ' + currentVm), - content: Text('You are about to delete ' + - currentVm + - '. This cannot be undone. ' + - 'Would you like to delete the disk image but keep the ' + - 'configuration, or delete the whole VM?'), + title: Text('Delete $currentVm'), + content: Text('You are about to delete $currentVm. This cannot be undone. Would you like to delete the disk image but keep the configuration, or delete the whole VM?'), actions: [ TextButton( child: const Text('Cancel'), @@ -390,21 +386,22 @@ class _ManagerState extends State with PreferencesMixin { IconButton( icon: SvgPicture.asset('assets/images/console.svg', semanticsLabel: 'Connect with SSH', - color: sshy ? buttonColor : Colors.grey), + colorFilter: ColorFilter.mode(sshy ? buttonColor : Colors.grey, BlendMode.srcIn) + ), tooltip: sshy ? 'Connect with SSH' : 'SSH server not detected on guest', onPressed: !sshy ? null : () { - TextEditingController _usernameController = + TextEditingController usernameController = TextEditingController(); showDialog( context: context, builder: (BuildContext context) => AlertDialog( title: Text('Launch SSH connection to $currentVm'), content: TextField( - controller: _usernameController, + controller: usernameController, decoration: const InputDecoration( hintText: "SSH username"), ), @@ -426,7 +423,7 @@ class _ManagerState extends State with PreferencesMixin { 'ssh', '-p', vmInfo.sshPort!, - _usernameController.text + '@localhost' + '${usernameController.text}@localhost' ]; // Set the arguments to execute the ssh command in the default terminal. // Strip the extension as x-terminal-emulator may point to a .wrapper diff --git a/lib/src/widgets/home_page/downloader_menu.dart b/lib/src/widgets/home_page/downloader_menu.dart index bd59cb4..849cc5b 100644 --- a/lib/src/widgets/home_page/downloader_menu.dart +++ b/lib/src/widgets/home_page/downloader_menu.dart @@ -72,12 +72,12 @@ class _DownloaderMenuState extends State with PreferencesMixin { const Divider( thickness: 2, ), - Row( + const Row( children: [ Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.start, - children: const [ + children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 12), child: HomePageButtonGroup(), diff --git a/lib/src/widgets/home_page/home_page_button_group.dart b/lib/src/widgets/home_page/home_page_button_group.dart index 91c45c2..58b2d18 100644 --- a/lib/src/widgets/home_page/home_page_button_group.dart +++ b/lib/src/widgets/home_page/home_page_button_group.dart @@ -105,8 +105,8 @@ class _HomePageButtonGroupState extends State { showDialog( context: context, barrierDismissible: false, - builder: (context) => WillPopScope( - onWillPop: () async => false, + builder: (context) => PopScope( + canPop: false, child: AlertDialog( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(8.0)), @@ -153,8 +153,8 @@ class _HomePageButtonGroupState extends State { showDialog( context: context, barrierDismissible: false, - builder: (context) => WillPopScope( - onWillPop: () async => false, + builder: (context) => PopScope( + canPop: false, child: AlertDialog( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(8.0)),