Created
June 14, 2020 09:25
-
-
Save EffyCoder/cc424113d8926f8008d7ae0b86514b6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import 'package:jivitva/core/common/widgets/loading_widget.dart'; | |
import 'package:jivitva/core/common/widgets/timer_widget.dart'; | |
class OrdersPage extends StatelessWidget { | |
const OrdersPage({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold(body: buildBody(context)); | |
} | |
} | |
Widget buildBody(BuildContext context) { | |
return SingleChildScrollView( | |
padding: EdgeInsets.all(8), | |
controller: ScrollController(keepScrollOffset: true), | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
loadPanelFirst(), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
Text( | |
'Lunch', | |
style: TextStyle(fontSize: 24, backgroundColor: Colors.white), | |
), | |
// if (shouldShowTimer(orderStatus.date)) | |
TimerWidget(countDownTime: getCountDownTime('Lunch')), | |
], | |
) | |
, | |
Text( | |
'Regular Orders', | |
style: Theme.of(context).textTheme.headline6, | |
), | |
loadRegLunchOrders(), | |
Text( | |
'Plan Orders', | |
style: Theme.of(context).textTheme.headline6, | |
), | |
loadPlanLunchOrders(), | |
SizedBox(height: 5), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
mainAxisSize: MainAxisSize.max, | |
children: <Widget>[ | |
Text( | |
'Dinner', | |
style: TextStyle(fontSize: 24, backgroundColor: Colors.white), | |
), | |
// if (shouldShowTimer(orderStatus.date)) | |
TimerWidget(countDownTime: getCountDownTime('Dinner')), | |
], | |
), | |
Text( | |
'Regular Orders', | |
style: Theme.of(context).textTheme.headline6, | |
), | |
loadRegDinnerOrders(), | |
Text( | |
'Plan Orders', | |
style: Theme.of(context).textTheme.headline6, | |
), | |
loadPlanDinnerOrders(), | |
SizedBox(height: 5), | |
Text( | |
'Testimonials', | |
textWidthBasis: TextWidthBasis.parent, | |
style: TextStyle(fontSize: 24, backgroundColor: Colors.white), | |
), | |
Padding( | |
padding: EdgeInsets.all(5), | |
child: DynamicImages(), | |
) | |
], | |
), | |
); | |
} | |
Widget loadPanelFirst() { | |
return Placeholder(fallbackHeight: 100,color: Colors.amber,); | |
} | |
Widget loadPanelLast() { | |
return Placeholder(fallbackHeight: 70,); | |
} | |
BlocProvider<RegOrdersBloc> loadRegLunchOrders() { | |
return BlocProvider<RegOrdersBloc>( | |
create: (context) => sl<RegOrdersBloc>(), | |
child: BlocListener<RegOrdersBloc, RegOrdersState>( | |
listener: (context, state) { | |
if (state is RegOrdersErrorState) { | |
Scaffold.of(context).showSnackBar(SnackBar( | |
content: Text(state.message), | |
)); | |
} | |
}, | |
child: | |
BlocBuilder<RegOrdersBloc, RegOrdersState>(builder: (context, state) { | |
if (state is OrdersInitial) { | |
BlocProvider.of<RegOrdersBloc>(context).add(RegOrdersRequested()); | |
return LoadingWidget(); | |
} else if (state is RegLunchOrdersLoaded) { | |
return RegOrdersPanel(orderStatusList: state.lunchOrders); | |
// return Placeholder(fallbackHeight:200); | |
} else { | |
return Container(); | |
} | |
}), | |
), | |
); | |
} | |
BlocProvider<PlanOrdersBloc> loadPlanDinnerOrders() { | |
return BlocProvider( | |
create: (context) => sl<PlanOrdersBloc>(), | |
child: BlocListener<PlanOrdersBloc, PlanOrdersState>( | |
listener: (context, state) { | |
if (state is DinnerPlanOrdersError) { | |
Scaffold.of(context).showSnackBar(SnackBar( | |
content: Text(state.message), | |
)); | |
} | |
}, | |
child: BlocBuilder<PlanOrdersBloc, PlanOrdersState>( | |
builder: (context, state) { | |
if (state is PlanOrdersInitial) { | |
// BlocProvider.of<PlanOrdersBloc>(context).add(PlanOrdersRequested()); | |
return LoadingWidget(); | |
} else if (state is PlanDinnerOrdersLoaded) { | |
return PlanOrdersPanel(orderStatusList: state.dinnerOrdersMenus); | |
}else if (state is NoDinnerPlansState){ | |
return Text('Buy meal plans for Dinner from Meal plans tab'); | |
} else { | |
return Container(); | |
} | |
}), | |
), | |
); | |
} | |
BlocProvider<PlanOrdersBloc> loadPlanLunchOrders() { | |
return BlocProvider( | |
create: (context) => sl<PlanOrdersBloc>(), | |
child: BlocListener<PlanOrdersBloc, PlanOrdersState>( | |
listener: (context, state) { | |
if (state is LunchPlanOrdersError) { | |
Scaffold.of(context).showSnackBar(SnackBar( | |
content: Text(state.message), | |
)); | |
} | |
}, | |
child: BlocBuilder<PlanOrdersBloc, PlanOrdersState>( | |
builder: (context, state) { | |
if (state is PlanOrdersInitial) { | |
BlocProvider.of<PlanOrdersBloc>(context).add(PlanOrdersRequested()); | |
return LoadingWidget(); | |
} else if (state is PlanLunchOrdersLoaded) { | |
return PlanOrdersPanel(orderStatusList: state.lunchOrdersMenus); | |
} else if (state is NoLunchPlansState){ | |
return Text('Buy meal plans for lunch from Meal plans tab'); | |
}else { | |
return Container(); | |
} | |
}), | |
), | |
); | |
} | |
BlocProvider<RegOrdersBloc> loadRegDinnerOrders() { | |
return BlocProvider<RegOrdersBloc>( | |
create: (context) => sl<RegOrdersBloc>(), | |
child: BlocListener<RegOrdersBloc, RegOrdersState>( | |
listener: (context, state) { | |
if (state is RegOrdersErrorState) { | |
Scaffold.of(context).showSnackBar(SnackBar( | |
content: Text(state.message), | |
)); | |
} | |
}, | |
child: | |
BlocBuilder<RegOrdersBloc, RegOrdersState>(builder: (context, state) { | |
if (state is OrdersInitial) { | |
BlocProvider.of<RegOrdersBloc>(context).add(RegOrdersRequested()); | |
return LoadingWidget(); | |
} else if (state is RegDinnerOrdersLoaded) { | |
return RegOrdersPanel(orderStatusList: state.dinnerOrders); | |
// return Placeholder(fallbackHeight:200); | |
} else { | |
return Container(); | |
} | |
}), | |
), | |
); | |
} | |
int getCountDownTime(String mealType){ | |
int countDownTime = 0; | |
if (mealType.toLowerCase() == 'lunch') { | |
DateTime now = DateTime.now(); | |
DateTime closingTime = DateTime(now.year, now.month, now.day, 10, 30); | |
countDownTime = closingTime.difference(now).inSeconds; | |
} else if (mealType.toLowerCase() == 'dinner') { | |
DateTime now = DateTime.now(); | |
DateTime closingTime = DateTime(now.year, now.month, now.day, 16, 30); | |
countDownTime = closingTime.difference(now).inSeconds; | |
} else { | |
DateTime now = DateTime.now(); | |
DateTime closingTime = DateTime(now.year, now.month, now.day, 8, 0); | |
countDownTime = closingTime.difference(now).inSeconds; | |
} | |
return countDownTime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
``import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
part 'orders_event.dart';
part 'orders_state.dart';
class RegOrdersBloc extends Bloc<OrdersEvent, RegOrdersState> {
final GetRegularOrderStatuses getRegularOrderStatuses;
RegOrdersBloc({this.getRegularOrderStatuses});
@OverRide
RegOrdersState get initialState => OrdersInitial();
@OverRide
Stream mapEventToState(
OrdersEvent event,
) async* {
if (event is RegOrdersRequested) {
final orderStatusListOrFailure = await getRegularOrderStatuses
.call(OrderStatusRequest(city: 'Pune', userId: 172));
yield* orderStatusListOrFailure.fold((failure) async* {
yield RegOrdersErrorState(message: failure.message);
}, (map) async* {
yield RegLunchOrdersLoaded(lunchOrders: map.lunchOrders);
yield RegDinnerOrdersLoaded(dinnerOrders:map.dinnerOrders);
// yield ErrorState(message: 'Failed to load list');
});
}
}
}