]> git.proxmox.com Git - flutter/pve_flutter_frontend.git/commitdiff
add network model selector
authorTim Marx <t.marx@proxmox.com>
Fri, 6 Dec 2019 16:59:57 +0000 (17:59 +0100)
committerTim Marx <t.marx@proxmox.com>
Fri, 6 Dec 2019 17:12:43 +0000 (18:12 +0100)
Signed-off-by: Tim Marx <t.marx@proxmox.com>
lib/widgets/pve_network_model_selector.dart [new file with mode: 0644]

diff --git a/lib/widgets/pve_network_model_selector.dart b/lib/widgets/pve_network_model_selector.dart
new file mode 100644 (file)
index 0000000..a98f0b8
--- /dev/null
@@ -0,0 +1,52 @@
+import 'package:flutter/material.dart';
+
+class PveNetworkInterfaceModelSelector extends StatefulWidget {
+  final String labelText;
+  final Function onChange;
+  final String initialSelection;
+
+  const PveNetworkInterfaceModelSelector({Key key, this.labelText, this.onChange, this.initialSelection})
+      : super(key: key);
+  @override
+  _PveNetworkInterfaceModelSelectorState createState() =>
+      _PveNetworkInterfaceModelSelectorState();
+}
+
+class _PveNetworkInterfaceModelSelectorState
+    extends State<PveNetworkInterfaceModelSelector> {
+  Map<String, String> models = {
+    'e1000': 'Intel E1000',
+    'virtio': 'VirtIO (paravirtualized)',
+    'rtl8139': 'Realtek RTL8139',
+    'vmxnet3': 'VMware vmxnet3'
+  };
+  String selection;
+  @override
+  Widget build(BuildContext context) {
+    return DropdownButtonFormField<String>(
+      decoration: InputDecoration(
+        labelText: widget.labelText,
+        helperText: ' ',
+      ),
+      items: models.keys
+          .map((f) => DropdownMenuItem(
+                child: Text(models[f]),
+                value: f,
+              ))
+          .toList(),
+      selectedItemBuilder: (context) => models.keys
+          .map((f) => DropdownMenuItem(
+                child: Text(models[f]),
+                value: f,
+              ))
+          .toList(),
+      onChanged: (String selection) {
+        setState(() {
+          this.selection = selection;
+        });
+        widget.onChange(selection);
+      },
+      value: selection ?? widget.initialSelection,
+    );
+  }
+}