softplayer-web/lib/components/environments.dart

106 lines
4.2 KiB
Dart
Raw Normal View History

2024-04-19 11:19:44 +00:00
import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
2024-04-29 10:42:16 +00:00
import 'package:softplayer_web/api/grpc/creds.dart';
2024-04-19 11:19:44 +00:00
import 'package:softplayer_web/api/grpc/environments.dart';
2024-04-29 10:42:16 +00:00
import 'package:softplayer_web/components/environment_card.dart';
2024-04-19 11:19:44 +00:00
class EnvirnomentList extends StatefulWidget {
2024-04-29 10:42:16 +00:00
const EnvirnomentList({
2024-04-19 11:19:44 +00:00
super.key,
required this.channel,
});
final GrpcWebClientChannel channel;
@override
State<StatefulWidget> createState() => _EnvirnomentListState();
}
class _EnvirnomentListState extends State<EnvirnomentList> {
late EnvironmentsGrpc envGrpc;
List<String> envs = [];
@override
void initState() {
super.initState();
2024-04-29 10:42:16 +00:00
envGrpc = EnvironmentsGrpc(widget.channel);
2024-04-19 11:19:44 +00:00
}
2024-05-02 21:56:55 +00:00
final GlobalKey<ScaffoldState> _key = GlobalKey(); // Create a key
2024-04-19 11:19:44 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-05-02 21:56:55 +00:00
key: _key,
endDrawer: const Drawer(child: Text("Env")),
2024-04-30 15:31:53 +00:00
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
2024-05-02 21:56:55 +00:00
gradient: LinearGradient(colors: [
Colors.blueGrey,
Colors.cyan,
Colors.yellow,
])),
2024-04-19 11:19:44 +00:00
child: StreamBuilder(
2024-04-29 10:42:16 +00:00
stream:
envGrpc.list(SoftplayerCredsHelpers().fromLocalStorage()),
2024-04-19 11:19:44 +00:00
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
2024-04-29 10:42:16 +00:00
return const CircularProgressIndicator();
2024-04-19 11:19:44 +00:00
} else if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
2024-04-29 10:42:16 +00:00
return const Text('Error!');
2024-04-19 11:19:44 +00:00
} else {
2024-04-30 15:31:53 +00:00
if (snapshot.hasData) {
var data = snapshot.requireData;
if (data.isNotEmpty) {
2024-05-03 11:10:06 +00:00
return Container(
margin: const EdgeInsetsDirectional.fromSTEB(
50.0, 20.0, 50.0, 10.0),
child: Column(children: [
Flexible(
child: Container(
child: const TextField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
labelText: "Search",
prefixIcon: Icon(Icons.search)),
),
2024-05-02 17:09:44 +00:00
),
),
2024-05-03 11:10:06 +00:00
Container(
child: Flexible(
child: GridView.count(
childAspectRatio: (30 / 13),
crossAxisCount: 4,
children: snapshot.data!
.map((e) => EnvirnomentCard(
env: e,
))
.toList(),
)),
)
]),
);
2024-04-30 15:31:53 +00:00
} else {
return Center(
child: Container(
height: 300,
decoration: BoxDecoration(
border: Border.all(),
shape: BoxShape.rectangle,
borderRadius:
2024-05-02 21:56:55 +00:00
const BorderRadius.all(Radius.circular(10)),
color: const Color.fromRGBO(100, 150, 80, 20),
2024-04-30 15:31:53 +00:00
),
2024-05-02 21:56:55 +00:00
child: const Text(
"To get strated, use the button in the corner"),
2024-04-30 15:31:53 +00:00
));
}
}
2024-04-19 11:19:44 +00:00
}
}
2024-04-29 10:42:16 +00:00
return const Text("err");
2024-04-19 11:19:44 +00:00
})));
}
}