refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-03-14 20:38:21 -05:00
parent 79262ef862
commit 7dd56cf715
3 changed files with 88 additions and 11 deletions

View File

@ -181,7 +181,7 @@ class _AddMountScreenState extends State<AddMountScreen> {
Navigator.pop(context); Navigator.pop(context);
}, },
label: const Text('Add'), label: const Text('Add'),
icon: Icon(Icons.add), icon: const Icon(Icons.add),
); );
}, },
), ),

View File

@ -30,7 +30,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
if (!isAdvanced || widget.showAdvanced) { if (!isAdvanced || widget.showAdvanced) {
list.add( list.add(
SettingsTile.switchTile( SettingsTile.switchTile(
leading: Icon(Icons.quiz), leading: const Icon(Icons.quiz),
title: Text(key), title: Text(key),
initialValue: (value as bool), initialValue: (value as bool),
onPressed: onPressed:
@ -60,7 +60,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
if (!isAdvanced || widget.showAdvanced) { if (!isAdvanced || widget.showAdvanced) {
list.add( list.add(
SettingsTile.navigation( SettingsTile.navigation(
leading: Icon(Icons.onetwothree), leading: const Icon(Icons.onetwothree),
title: Text(key), title: Text(key),
value: Text(value.toString()), value: Text(value.toString()),
onPressed: (_) { onPressed: (_) {
@ -71,11 +71,11 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
return AlertDialog( return AlertDialog(
actions: [ actions: [
TextButton( TextButton(
child: Text('Cancel'), child: const Text('Cancel'),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
TextButton( TextButton(
child: Text('OK'), child: const Text('OK'),
onPressed: () { onPressed: () {
final result = validators.firstWhereOrNull( final result = validators.firstWhereOrNull(
(validator) => !validator(updatedValue), (validator) => !validator(updatedValue),
@ -197,7 +197,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
if (!isAdvanced || widget.showAdvanced) { if (!isAdvanced || widget.showAdvanced) {
list.add( list.add(
SettingsTile.navigation( SettingsTile.navigation(
leading: Icon(Icons.password), leading: const Icon(Icons.password),
title: Text(key), title: Text(key),
value: Text('*' * (value as String).length), value: Text('*' * (value as String).length),
onPressed: (_) { onPressed: (_) {
@ -209,11 +209,11 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
return AlertDialog( return AlertDialog(
actions: [ actions: [
TextButton( TextButton(
child: Text('Cancel'), child: const Text('Cancel'),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
TextButton( TextButton(
child: Text('OK'), child: const Text('OK'),
onPressed: () { onPressed: () {
if (updatedValue1 != updatedValue2) { if (updatedValue1 != updatedValue2) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -305,11 +305,11 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
return AlertDialog( return AlertDialog(
actions: [ actions: [
TextButton( TextButton(
child: Text('Cancel'), child: const Text('Cancel'),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
TextButton( TextButton(
child: Text('OK'), child: const Text('OK'),
onPressed: () { onPressed: () {
final result = validators.firstWhereOrNull( final result = validators.firstWhereOrNull(
(validator) => !validator(updatedValue), (validator) => !validator(updatedValue),

View File

@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:repertory/helpers.dart'; import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart'; import 'package:repertory/models/mount.dart';
@ -71,7 +73,82 @@ class _MountWidgetState extends State<MountWidget> {
String? location = mount.path; String? location = mount.path;
if (!isActive && mount.path.isEmpty) { if (!isActive && mount.path.isEmpty) {
location = await mount.getMountLocation(); location = await mount.getMountLocation();
if (location == null) {} if (location == null) {
String? updatedValue;
if (context.mounted) {
location = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
actions: [
TextButton(
child: const Text('Cancel'),
onPressed:
() =>
Navigator.of(context).pop(null),
),
TextButton(
child: const Text('OK'),
onPressed: () {
final result = getSettingValidators(
'Path',
).firstWhereOrNull(
(validator) =>
!validator(updatedValue ?? ''),
);
if (result != null) {
ScaffoldMessenger.of(
context,
).showSnackBar(
SnackBar(
content: const Text(
"mount location is not valid",
textAlign: TextAlign.center,
),
),
);
return;
}
Navigator.of(
context,
).pop(updatedValue);
},
),
],
content: TextField(
autofocus: true,
controller: TextEditingController(
text: updatedValue,
),
inputFormatters: [
FilteringTextInputFormatter.deny(
RegExp(r'\s'),
),
],
onChanged: null,
),
title: const Text('Set Mount Location'),
);
},
);
}
}
}
if (location == null) {
if (!context.mounted) {
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text(
"mount location is not set",
textAlign: TextAlign.center,
),
),
);
return;
} }
mount mount