Fix deprecations and code style

This commit is contained in:
Mark Johnson 2024-06-13 15:40:25 +01:00
parent 2956c72939
commit b1350b825f
No known key found for this signature in database
GPG Key ID: EB30E1468CFAE242
6 changed files with 26 additions and 28 deletions

View File

@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart'; import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';

View File

@ -13,8 +13,8 @@ class DownloaderPage extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: Text(context.t('Downloader')), title: Text(context.t('Downloader')),
), ),
body: Column( body: const Column(
children: const [ children: [
Logo(), Logo(),
DownloaderMenu(), DownloaderMenu(),
], ],

View File

@ -28,8 +28,8 @@ class _MainPageState extends State<MainPage> {
title: Text(context.t('Main menu')), title: Text(context.t('Main menu')),
), ),
drawer: const LeftMenu(), drawer: const LeftMenu(),
body: Column( body: const Column(
children: const [ children: [
Logo(), Logo(),
MainMenu(), MainMenu(),
], ],

View File

@ -138,10 +138,10 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
if ((entity.path.endsWith('.conf')) && (_isValidConf(entity.path))) { if ((entity.path.endsWith('.conf')) && (_isValidConf(entity.path))) {
String name = path.basenameWithoutExtension(entity.path); String name = path.basenameWithoutExtension(entity.path);
currentVms.add(name); currentVms.add(name);
File pidFile = File(name + '/' + name + '.pid'); File pidFile = File('$name/$name.pid');
if (pidFile.existsSync()) { if (pidFile.existsSync()) {
String pid = pidFile.readAsStringSync().trim(); String pid = pidFile.readAsStringSync().trim();
Directory procDir = Directory('/proc/' + pid); Directory procDir = Directory('/proc/$pid');
if (procDir.existsSync()) { if (procDir.existsSync()) {
if (_activeVms.containsKey(name)) { if (_activeVms.containsKey(name)) {
activeVms[name] = _activeVms[name]!; activeVms[name] = _activeVms[name]!;
@ -172,11 +172,11 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
} }
Widget _buildVmList() { Widget _buildVmList() {
List<Widget> _widgetList = []; List<Widget> widgetList = [];
final Color buttonColor = Theme.of(context).brightness == Brightness.dark final Color buttonColor = Theme.of(context).brightness == Brightness.dark
? Colors.white70 ? Colors.white70
: Theme.of(context).colorScheme.primary; : Theme.of(context).colorScheme.primary;
_widgetList.addAll( widgetList.addAll(
[ [
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0), padding: const EdgeInsets.symmetric(vertical: 16.0),
@ -222,12 +222,12 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
return _buildRow(vm, buttonColor); return _buildRow(vm, buttonColor);
}).toList(); }).toList();
for (var row in rows) { for (var row in rows) {
_widgetList.addAll(row); widgetList.addAll(row);
} }
return ListView( return ListView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
children: _widgetList, children: widgetList,
); );
} }
@ -239,10 +239,10 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
if (active) { if (active) {
vmInfo = _activeVms[currentVm]!; vmInfo = _activeVms[currentVm]!;
if (vmInfo.spicePort != null) { if (vmInfo.spicePort != null) {
connectInfo += context.t('SPICE port') + ': ' + vmInfo.spicePort! + ' '; connectInfo += '${context.t('SPICE port')}: ${vmInfo.spicePort!} ';
} }
if (vmInfo.sshPort != null && _terminalEmulator != null) { 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) { _detectSsh(int.parse(vmInfo.sshPort!)).then((sshRunning) {
if (sshRunning && !sshy) { if (sshRunning && !sshy) {
setState(() { setState(() {
@ -331,12 +331,8 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
showDialog<String?>( showDialog<String?>(
context: context, context: context,
builder: (BuildContext context) => AlertDialog( builder: (BuildContext context) => AlertDialog(
title: Text('Delete ' + currentVm), title: Text('Delete $currentVm'),
content: Text('You are about to delete ' + 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?'),
currentVm +
'. This cannot be undone. ' +
'Would you like to delete the disk image but keep the ' +
'configuration, or delete the whole VM?'),
actions: [ actions: [
TextButton( TextButton(
child: const Text('Cancel'), child: const Text('Cancel'),
@ -390,21 +386,22 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
IconButton( IconButton(
icon: SvgPicture.asset('assets/images/console.svg', icon: SvgPicture.asset('assets/images/console.svg',
semanticsLabel: 'Connect with SSH', semanticsLabel: 'Connect with SSH',
color: sshy ? buttonColor : Colors.grey), colorFilter: ColorFilter.mode(sshy ? buttonColor : Colors.grey, BlendMode.srcIn)
),
tooltip: sshy tooltip: sshy
? 'Connect with SSH' ? 'Connect with SSH'
: 'SSH server not detected on guest', : 'SSH server not detected on guest',
onPressed: !sshy onPressed: !sshy
? null ? null
: () { : () {
TextEditingController _usernameController = TextEditingController usernameController =
TextEditingController(); TextEditingController();
showDialog<bool>( showDialog<bool>(
context: context, context: context,
builder: (BuildContext context) => AlertDialog( builder: (BuildContext context) => AlertDialog(
title: Text('Launch SSH connection to $currentVm'), title: Text('Launch SSH connection to $currentVm'),
content: TextField( content: TextField(
controller: _usernameController, controller: usernameController,
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: "SSH username"), hintText: "SSH username"),
), ),
@ -426,7 +423,7 @@ class _ManagerState extends State<Manager> with PreferencesMixin {
'ssh', 'ssh',
'-p', '-p',
vmInfo.sshPort!, vmInfo.sshPort!,
_usernameController.text + '@localhost' '${usernameController.text}@localhost'
]; ];
// Set the arguments to execute the ssh command in the default terminal. // Set the arguments to execute the ssh command in the default terminal.
// Strip the extension as x-terminal-emulator may point to a .wrapper // Strip the extension as x-terminal-emulator may point to a .wrapper

View File

@ -72,12 +72,12 @@ class _DownloaderMenuState extends State<DownloaderMenu> with PreferencesMixin {
const Divider( const Divider(
thickness: 2, thickness: 2,
), ),
Row( const Row(
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: const [ children: [
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 12), padding: EdgeInsets.symmetric(horizontal: 12),
child: HomePageButtonGroup(), child: HomePageButtonGroup(),

View File

@ -105,8 +105,8 @@ class _HomePageButtonGroupState extends State<HomePageButtonGroup> {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => WillPopScope( builder: (context) => PopScope(
onWillPop: () async => false, canPop: false,
child: AlertDialog( child: AlertDialog(
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)), borderRadius: BorderRadius.all(Radius.circular(8.0)),
@ -153,8 +153,8 @@ class _HomePageButtonGroupState extends State<HomePageButtonGroup> {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => WillPopScope( builder: (context) => PopScope(
onWillPop: () async => false, canPop: false,
child: AlertDialog( child: AlertDialog(
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)), borderRadius: BorderRadius.all(Radius.circular(8.0)),