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 createState() => _EnvirnomentListState(); } class _EnvirnomentListState extends State { late EnvironmentsGrpc envGrpc; List 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 envs; // late EnvironmentsGrpc envGrpc; // List getEnvs() { // List envs = []; // envGrpc.list().then((value) { // return value; // }).catchError((e) { // return envs; // }); // return envs; // } // // List bootstrapCards(List envs) { // List 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()), // // ); // } //}