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: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((_) {
|
||||||
|
_mountType = "S3";
|
||||||
|
_mountName = "";
|
||||||
setState(() {
|
setState(() {
|
||||||
_allowAdd = true;
|
_allowAdd = true;
|
||||||
_mountType = "S3";
|
|
||||||
_mountName = "";
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catchError((_) {
|
.catchError((_) {
|
||||||
|
@ -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,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
|
@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(
|
||||||
TextField(
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
decoration: InputDecoration(labelText: 'Name'),
|
fontWeight: FontWeight.bold,
|
||||||
onChanged: onNameChanged,
|
),
|
||||||
|
),
|
||||||
|
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