Create management portal in Flutter #39
This commit is contained in:
parent
71f3567375
commit
15f6b116cc
@ -1,3 +1,4 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
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';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
runApp(
|
||||
ChangeNotifierProvider(create: (_) => MountList(), child: const MyApp()),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@ -85,10 +88,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
leading: const Icon(Icons.storage),
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: ChangeNotifierProvider(
|
||||
create: (context) => MountList(),
|
||||
child: MountListWidget(),
|
||||
),
|
||||
body: MountListWidget(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed:
|
||||
_allowAdd
|
||||
@ -102,19 +102,17 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
builder: (_, mountList, __) {
|
||||
return AddMountWidget(
|
||||
allowEncrypt:
|
||||
!mountList.items.contains(
|
||||
mountList.items.firstWhereOrNull(
|
||||
(item) => item.type == "encrypt",
|
||||
),
|
||||
mountName: _mountName,
|
||||
) ==
|
||||
null,
|
||||
mountType: _mountType,
|
||||
onNameChanged:
|
||||
(mountName) => setState(
|
||||
() => _mountName = mountName ?? "",
|
||||
),
|
||||
onTypeChanged:
|
||||
(mountType) => setState(
|
||||
() => _mountType = mountType ?? "S3",
|
||||
),
|
||||
onNameChanged: (mountName) {
|
||||
_mountName = mountName ?? "";
|
||||
},
|
||||
onTypeChanged: (mountType) {
|
||||
_mountType = mountType ?? "S3";
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -122,10 +120,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_mountType = "S3";
|
||||
_mountName = "";
|
||||
});
|
||||
_mountType = "S3";
|
||||
_mountName = "";
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
@ -137,10 +133,10 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
Provider.of<MountList>(context, listen: false)
|
||||
.add(_mountType, _mountName)
|
||||
.then((_) {
|
||||
_mountType = "S3";
|
||||
_mountName = "";
|
||||
setState(() {
|
||||
_allowAdd = true;
|
||||
_mountType = "S3";
|
||||
_mountName = "";
|
||||
});
|
||||
})
|
||||
.catchError((_) {
|
||||
|
@ -1,8 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AddMountWidget extends StatelessWidget {
|
||||
class AddMountWidget extends StatefulWidget {
|
||||
final bool allowEncrypt;
|
||||
final String mountName;
|
||||
final String mountType;
|
||||
final void Function(String? newName) onNameChanged;
|
||||
final void Function(String? newType) onTypeChanged;
|
||||
@ -12,7 +11,6 @@ class AddMountWidget extends StatelessWidget {
|
||||
AddMountWidget({
|
||||
super.key,
|
||||
required this.allowEncrypt,
|
||||
required this.mountName,
|
||||
required this.mountType,
|
||||
required this.onNameChanged,
|
||||
required this.onTypeChanged,
|
||||
@ -22,23 +20,73 @@ 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
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// DropdownButton<String>(
|
||||
// value: mountType,
|
||||
// onChanged: onTypeChanged,
|
||||
// items:
|
||||
// _items.map<DropdownMenuItem<String>>((item) {
|
||||
// return DropdownMenuItem<String>(value: item, child: Text(item));
|
||||
// }).toList(),
|
||||
// ),
|
||||
TextField(
|
||||
decoration: InputDecoration(labelText: 'Name'),
|
||||
onChanged: onNameChanged,
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Provider Type',
|
||||
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(
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(),
|
||||
onChanged: widget.onNameChanged,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user