softplayer-web/lib/components/environments.dart

82 lines
3.0 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
}
@override
Widget build(BuildContext context) {
return Scaffold(
2024-04-30 15:31:53 +00:00
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/login_background.jpg"),
fit: BoxFit.cover,
),
),
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) {
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),
),
));
}
}
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
})));
}
}