softplayer-web/lib/components/environments.dart

103 lines
2.9 KiB
Dart

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';
import 'package:softplayer_web/components/environment_card.dart';
class EnvirnomentList extends StatefulWidget {
const EnvirnomentList({
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();
envGrpc = EnvironmentsGrpc(widget.channel);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: StreamBuilder(
stream:
envGrpc.list(SoftplayerCredsHelpers().fromLocalStorage()),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return const Text('Error!');
} else {
return GridView.count(
crossAxisCount: 4,
children: snapshot.data!
.map((e) => EnvirnomentCard(name: e.name.name))
.toList(),
);
}
}
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()),
// // );
// }
//}