Create management portal in Flutter #39

This commit is contained in:
Scott E. Graves 2025-03-04 19:42:13 -06:00
parent 71f3567375
commit 15f6b116cc
2 changed files with 80 additions and 36 deletions

View File

@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:repertory/constants.dart' as constants; import 'package:repertory/constants.dart' as constants;
@ -9,7 +10,9 @@ import 'package:repertory/widgets/mount_list_widget.dart';
import 'package:repertory/widgets/mount_settings.dart'; import 'package:repertory/widgets/mount_settings.dart';
void main() { void main() {
runApp(const MyApp()); runApp(
ChangeNotifierProvider(create: (_) => MountList(), child: const MyApp()),
);
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@ -85,10 +88,7 @@ class _MyHomePageState extends State<MyHomePage> {
leading: const Icon(Icons.storage), leading: const Icon(Icons.storage),
title: Text(widget.title), title: Text(widget.title),
), ),
body: ChangeNotifierProvider( body: MountListWidget(),
create: (context) => MountList(),
child: MountListWidget(),
),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: onPressed:
_allowAdd _allowAdd
@ -102,19 +102,17 @@ class _MyHomePageState extends State<MyHomePage> {
builder: (_, mountList, __) { builder: (_, mountList, __) {
return AddMountWidget( return AddMountWidget(
allowEncrypt: allowEncrypt:
!mountList.items.contains( mountList.items.firstWhereOrNull(
(item) => item.type == "encrypt", (item) => item.type == "encrypt",
), ) ==
mountName: _mountName, null,
mountType: _mountType, mountType: _mountType,
onNameChanged: onNameChanged: (mountName) {
(mountName) => setState( _mountName = mountName ?? "";
() => _mountName = mountName ?? "", },
), onTypeChanged: (mountType) {
onTypeChanged: _mountType = mountType ?? "S3";
(mountType) => setState( },
() => _mountType = mountType ?? "S3",
),
); );
}, },
), ),
@ -122,10 +120,8 @@ class _MyHomePageState extends State<MyHomePage> {
TextButton( TextButton(
child: const Text('Cancel'), child: const Text('Cancel'),
onPressed: () { onPressed: () {
setState(() {
_mountType = "S3"; _mountType = "S3";
_mountName = ""; _mountName = "";
});
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
@ -137,10 +133,10 @@ class _MyHomePageState extends State<MyHomePage> {
Provider.of<MountList>(context, listen: false) Provider.of<MountList>(context, listen: false)
.add(_mountType, _mountName) .add(_mountType, _mountName)
.then((_) { .then((_) {
setState(() {
_allowAdd = true;
_mountType = "S3"; _mountType = "S3";
_mountName = ""; _mountName = "";
setState(() {
_allowAdd = true;
}); });
}) })
.catchError((_) { .catchError((_) {

View File

@ -1,8 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AddMountWidget extends StatelessWidget { class AddMountWidget extends StatefulWidget {
final bool allowEncrypt; final bool allowEncrypt;
final String mountName;
final String mountType; final String mountType;
final void Function(String? newName) onNameChanged; final void Function(String? newName) onNameChanged;
final void Function(String? newType) onTypeChanged; final void Function(String? newType) onTypeChanged;
@ -12,7 +11,6 @@ class AddMountWidget extends StatelessWidget {
AddMountWidget({ AddMountWidget({
super.key, super.key,
required this.allowEncrypt, required this.allowEncrypt,
required this.mountName,
required this.mountType, required this.mountType,
required this.onNameChanged, required this.onNameChanged,
required this.onTypeChanged, required this.onTypeChanged,
@ -22,22 +20,72 @@ class AddMountWidget extends StatelessWidget {
} }
} }
@override
State<AddMountWidget> createState() => _AddMountWidgetState();
}
class _AddMountWidgetState extends State<AddMountWidget> {
String? _mountType;
@override
void initState() {
_mountType = widget.mountType;
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// DropdownButton<String>( Column(
// value: mountType, mainAxisAlignment: MainAxisAlignment.start,
// onChanged: onTypeChanged, crossAxisAlignment: CrossAxisAlignment.start,
// items: children: [
// _items.map<DropdownMenuItem<String>>((item) { Text(
// return DropdownMenuItem<String>(value: item, child: Text(item)); 'Provider Type',
// }).toList(), textAlign: TextAlign.left,
// ), style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 10),
DropdownButton<String>(
value: _mountType,
onChanged: (value) {
setState(() {
_mountType = value;
});
widget.onTypeChanged(value);
},
items:
widget._items.map<DropdownMenuItem<String>>((item) {
return DropdownMenuItem<String>(
value: item,
child: Text(item),
);
}).toList(),
),
],
),
const SizedBox(height: 10),
if (_mountType != "Encrypt")
Text(
'Configuration Name',
textAlign: TextAlign.left,
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold,
),
),
if (_mountType != "Encrypt")
TextField( TextField(
decoration: InputDecoration(labelText: 'Name'), autofocus: true,
onChanged: onNameChanged, decoration: InputDecoration(),
onChanged: widget.onNameChanged,
), ),
], ],
); );