11import 'package:flutter/material.dart' ;
22import 'package:flutter_bloc/flutter_bloc.dart' ;
33
4- import '../../data/constants/colors.dart' ;
54import '../../domain/models/contest.dart' ;
5+ import '../components/widgets/empty_state.dart' ;
66import 'bloc/contests_bloc.dart' ;
77import 'widgets/contest_card.dart' ;
88import 'widgets/contest_header.dart' ;
9- import 'widgets/empty_state.dart' ;
109import 'widgets/loading_state.dart' ;
1110
1211class ContestsScreen extends StatelessWidget {
@@ -16,40 +15,37 @@ class ContestsScreen extends StatelessWidget {
1615 Widget build (BuildContext context) {
1716 return BlocProvider <ContestsBloc >(
1817 create: (_) => ContestsBloc ()..init (),
19- child: BlocBuilder <ContestsBloc , ContestsState >(
20- builder: (context, state) {
21- return Scaffold (
22- backgroundColor: AppColors .white,
23- appBar: const PreferredSize (
24- preferredSize: Size .fromHeight (kToolbarHeight),
25- child: ContestHeader (),
26- ),
27- body: Builder (
28- builder: (_) {
29- if (state.isLoading) {
30- return const LoadingState ();
18+ child: Scaffold (
19+ appBar: const PreferredSize (
20+ preferredSize: Size .fromHeight (kToolbarHeight),
21+ child: ContestHeader (),
22+ ),
23+ body: BlocBuilder <ContestsBloc , ContestsState >(
24+ builder: (context, state) {
25+ if (state.isLoading) {
26+ return const LoadingState ();
27+ }
28+ if (state.contests.isEmpty) {
29+ return const EmptyState (
30+ description: 'No contests found, please adjust your filters!' ,
31+ );
32+ }
33+ return ListView .builder (
34+ itemCount: state.contests.length,
35+ itemBuilder: (context, index) {
36+ if (state.contests[index] is Ongoing ) {
37+ return ContestCard (
38+ ongoing: state.contests[index],
39+ );
3140 }
32- if (state.contests.isEmpty) {
33- return const EmptyState ();
34- }
35- return ListView .builder (
36- itemCount: state.contests.length,
37- itemBuilder: (context, index) {
38- if (state.contests[index] is Ongoing ) {
39- return ContestCard (
40- ongoing: state.contests[index],
41- );
42- }
4341
44- return ContestCard (
45- upcoming: state.contests[index],
46- );
47- },
42+ return ContestCard (
43+ upcoming: state.contests[index],
4844 );
4945 },
50- ),
51- );
52- } ,
46+ );
47+ },
48+ ) ,
5349 ),
5450 );
5551 }
0 commit comments