class HomeTables extends StatelessWidget {
final tablesRepository = TablesRepository();
@override Widget build(BuildContext context) {
return BlocProvider<TableBloc>(
create: (context) => TableBloc(tablesRepository: tablesRepository),
child: Scaffold(
body: BlocBuilder<TableBloc, TableState>(
builder: (context, state) {
if (state is TableInitial) {
return Center(child: Text('No data received as bro said!'));
}
if (state is TableLoadingState) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Theme.of(context).primaryColor,
));
}
if (state is TableLoadedState) {
return GridView.count(
crossAxisCount: 4,
children: List.generate(state.loadedTables.length, (index) {
return Center(
child: GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/tableReview',
arguments: state.loadedTables[index]['_id']);
},
child: Container(
width: 80,
height: 80,
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2.0),
borderRadius:
BorderRadius.all(Radius.circular(25))),
padding: const EdgeInsets.all(14.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
'${state.loadedTables[index]['tableNum']}',
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 23),
),
],
)),
),
);
}),
);
}
if (state is TableErrorState) {
return Center(child: Text('Error to load tables!'));
} else {
return null;
}
},
),
),
);
}
}