softplayer-web/lib/components/environments.dart

103 lines
2.9 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(
body: SafeArea(
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-29 10:42:16 +00:00
return GridView.count(
crossAxisCount: 4,
children: snapshot.data!
.map((e) => EnvirnomentCard(name: e.name.name))
.toList(),
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
})));
}
}
//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()),
// // );
// }
//}