Some updates
This commit is contained in:
131
lib/components/create_env_form.dart
Normal file
131
lib/components/create_env_form.dart
Normal file
@ -0,0 +1,131 @@
|
||||
import 'dart:html';
|
||||
import 'dart:js' as js;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grpc/grpc_web.dart';
|
||||
import 'package:softplayer_web/api/grpc/creds.dart';
|
||||
import 'package:softplayer_web/api/grpc/environments.dart';
|
||||
|
||||
class CreateEnvForm extends StatefulWidget {
|
||||
CreateEnvForm(GrpcWebClientChannel channel, {super.key})
|
||||
: environmentsGrpc = EnvironmentsGrpc(channel);
|
||||
final EnvironmentsGrpc environmentsGrpc;
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CreateEnvFormState();
|
||||
}
|
||||
|
||||
class _CreateEnvFormState extends State<CreateEnvForm> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
final nameCtl = TextEditingController();
|
||||
final descriptionCtl = TextEditingController();
|
||||
String? serverLocation;
|
||||
String? serverType;
|
||||
|
||||
void createEnvironment() {
|
||||
// Validate returns true if the form is valid, or false otherwise.
|
||||
if (_formKey.currentState!.validate()) {
|
||||
final name = nameCtl.text;
|
||||
final description = descriptionCtl.text;
|
||||
widget.environmentsGrpc
|
||||
.create(
|
||||
EnvironmentLocalData(
|
||||
serverType: serverType!,
|
||||
serverLocation: serverLocation!,
|
||||
provider: "",
|
||||
name: name,
|
||||
description: description),
|
||||
SoftplayerCredsHelpers().fromLocalStorage())
|
||||
.then((rs) {
|
||||
Navigator.pop(context);
|
||||
}).catchError((e) {
|
||||
print(e);
|
||||
GrpcError error = e;
|
||||
String msg;
|
||||
if (error.message != null) {
|
||||
msg = error.message!;
|
||||
} else {
|
||||
msg = error.toString();
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(msg),
|
||||
backgroundColor: Colors.red,
|
||||
showCloseIcon: true,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget createEnvForm() => SizedBox(
|
||||
width: 420,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: Column(children: [
|
||||
Divider(),
|
||||
Text("Provider the environment metadata"),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
controller: nameCtl,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Enter the environment name",
|
||||
icon: Icon(Icons.computer),
|
||||
label: Text("Name"),
|
||||
),
|
||||
cursorWidth: 1,
|
||||
cursorHeight: 18,
|
||||
cursorRadius: const Radius.circular(10),
|
||||
),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
controller: descriptionCtl,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Enter the environment description",
|
||||
icon: Icon(Icons.description),
|
||||
label: Text("Description"),
|
||||
),
|
||||
maxLength: 360,
|
||||
cursorWidth: 1,
|
||||
cursorHeight: 18,
|
||||
cursorRadius: const Radius.circular(10),
|
||||
),
|
||||
Divider(),
|
||||
DropdownButtonFormField(
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Enter the environment description",
|
||||
icon: Icon(Icons.computer),
|
||||
label: Text("Type of the server"),
|
||||
),
|
||||
value: null,
|
||||
isDense: true,
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
child: Text("lala1"),
|
||||
value: "test1",
|
||||
),
|
||||
DropdownMenuItem(child: Text("lala2"), value: "test2"),
|
||||
DropdownMenuItem(child: Text("lala3"), value: "test3"),
|
||||
DropdownMenuItem(child: Text("lala4"), value: "test4"),
|
||||
],
|
||||
onChanged: (value) => print(value),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => js.context.callMethod(
|
||||
'open', ['https://stackoverflow.com/questions/ask']),
|
||||
child: Text("Read more about environment types here"),
|
||||
)
|
||||
]))));
|
||||
List<Widget> createEnvActions() => [
|
||||
TextButton(
|
||||
onPressed: createEnvironment,
|
||||
child: const Text('OK'),
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AlertDialog(
|
||||
title: const Text("Create a new environment"),
|
||||
content: createEnvForm(),
|
||||
actions: createEnvActions(),
|
||||
);
|
||||
}
|
@ -1,23 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:softplayer_web/api/grpc/environments.dart';
|
||||
|
||||
class EnvirnomentCard extends StatelessWidget {
|
||||
final String name;
|
||||
final EnvironmentLocalData env;
|
||||
|
||||
const EnvirnomentCard({
|
||||
super.key,
|
||||
required this.name,
|
||||
required this.env,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(name),
|
||||
Row(
|
||||
children: [Text(name)],
|
||||
)
|
||||
],
|
||||
child: SelectionArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(env.name),
|
||||
const Divider(),
|
||||
Table(
|
||||
border: const TableBorder(
|
||||
bottom: BorderSide.none,
|
||||
left: BorderSide.none,
|
||||
right: BorderSide.none,
|
||||
top: BorderSide.none,
|
||||
),
|
||||
children: [
|
||||
TableRow(children: [
|
||||
Text("Provider"),
|
||||
Text(env.provider),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Description"),
|
||||
Text(env.description),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Server Type"),
|
||||
Text(env.serverType),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Location"),
|
||||
Text(env.serverLocation),
|
||||
]),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -26,7 +26,15 @@ class _EnvirnomentListState extends State<EnvirnomentList> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
body: Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("assets/login_background.jpg"),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
child: StreamBuilder(
|
||||
stream:
|
||||
envGrpc.list(SoftplayerCredsHelpers().fromLocalStorage()),
|
||||
@ -37,66 +45,37 @@ class _EnvirnomentListState extends State<EnvirnomentList> {
|
||||
if (snapshot.hasError) {
|
||||
return const Text('Error!');
|
||||
} else {
|
||||
return GridView.count(
|
||||
crossAxisCount: 4,
|
||||
children: snapshot.data!
|
||||
.map((e) => EnvirnomentCard(name: e.name.name))
|
||||
.toList(),
|
||||
);
|
||||
if (snapshot.hasData) {
|
||||
var data = snapshot.requireData;
|
||||
if (data.isNotEmpty) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 4,
|
||||
children: snapshot.data!
|
||||
.map((e) => EnvirnomentCard(
|
||||
env: e,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
} else {
|
||||
print("npo data");
|
||||
return Center(
|
||||
child: Container(
|
||||
height: 300,
|
||||
child: Text(
|
||||
"To get strated, use the button in the corner"),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(),
|
||||
shape: BoxShape.rectangle,
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(10)),
|
||||
color: Color.fromRGBO(100, 150, 80, 20),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return const Text("err");
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
//class EnvirnomentList extends StatelessWidget {
|
||||
// EnvirnomentList({
|
||||
// super.key,
|
||||
// required this.channel,
|
||||
// });
|
||||
// final GrpcWebClientChannel channel;
|
||||
// late List<String> envs;
|
||||
// late EnvironmentsGrpc envGrpc;
|
||||
// List<String> getEnvs() {
|
||||
// List<String> envs = [];
|
||||
// envGrpc.list().then((value) {
|
||||
// return value;
|
||||
// }).catchError((e) {
|
||||
// return envs;
|
||||
// });
|
||||
// return envs;
|
||||
// }
|
||||
//
|
||||
// List<Widget> bootstrapCards(List<String> envs) {
|
||||
// List<Widget> cards = [];
|
||||
// envs.forEach((element) {
|
||||
// cards.add(Center(child: Text(element)));
|
||||
// });
|
||||
// return cards;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// envGrpc = EnvironmentsGrpc(channel: channel);
|
||||
// envGrpc.init();
|
||||
// envs = getEnvs();
|
||||
// return GridView.count(
|
||||
// crossAxisCount: 2,
|
||||
// children: bootstrapCards(envs),
|
||||
// );
|
||||
// // children: List.generate(100, (index) {
|
||||
// // return Center(
|
||||
// // child: Text(
|
||||
// // 'Item $index',
|
||||
// // style: Theme.of(context).textTheme.headlineSmall,
|
||||
// // ),
|
||||
// // );
|
||||
// // }),
|
||||
// // );
|
||||
// // return GridView.count(
|
||||
// // children: bootstrapCards(getEnvs()),
|
||||
// // );
|
||||
// }
|
||||
//}
|
||||
|
Reference in New Issue
Block a user