Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add repo logic to coupon, notifs, feedback and profile page #232

Merged
merged 9 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/presentation/coupons/bloc/coupons_page_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'package:appetizer/domain/models/coupon/coupon.dart';
import 'package:appetizer/domain/repositories/coupon_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'coupons_page_event.dart';
part 'coupons_page_state.dart';

class CouponsPageBloc extends Bloc<CouponsPageEvent, CouponsPageState> {
CouponsPageBloc() : super(const CouponsPageInitialState()) {
final CouponRepository repo;
CouponsPageBloc({
required this.repo,
}) : super(const CouponsPageInitialState()) {
on<CouponsPageFetchEvent>(
NanoNish marked this conversation as resolved.
Show resolved Hide resolved
(CouponsPageFetchEvent event, Emitter<CouponsPageState> emit) {
// TODO: implement repository call
Expand Down
4 changes: 3 additions & 1 deletion lib/presentation/coupons/coupons_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/domain/repositories/coupon_repository.dart';
import 'package:appetizer/presentation/components/no_data_found_container.dart';
import 'package:appetizer/presentation/coupons/bloc/coupons_page_bloc.dart';
import 'package:appetizer/presentation/coupons/components/coupon_card.dart';
Expand Down Expand Up @@ -31,7 +32,8 @@ class CouponsScreen extends StatelessWidget {
toolbarHeight: 120.toAutoScaledHeight,
),
body: BlocProvider(
create: (context) => CouponsPageBloc(),
create: (context) =>
CouponsPageBloc(repo: context.read<CouponRepository>()),
child: BlocBuilder<CouponsPageBloc, CouponsPageState>(
builder: (context, state) {
if (state is CouponsPageInitialState) {
Expand Down
7 changes: 5 additions & 2 deletions lib/presentation/feedback/bloc/feedback_page_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package:appetizer/domain/repositories/feedback_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'feedback_page_event.dart';
part 'feedback_page_state.dart';

class FeedbackPageBloc extends Bloc<FeedbackPageEvent, FeedbackPageState> {
FeedbackPageBloc()
: super(
final FeedbackRepository repo;
FeedbackPageBloc({
required this.repo,
}) : super(
FeedbackPageState(
NanoNish marked this conversation as resolved.
Show resolved Hide resolved
rating: List<int>.filled(5, 0),
description: '',
Expand Down
12 changes: 7 additions & 5 deletions lib/presentation/feedback/feedback_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/domain/repositories/feedback_repository.dart';
import 'package:appetizer/presentation/components/black_button.dart';
import 'package:appetizer/presentation/feedback/bloc/feedback_page_bloc.dart';
import 'package:appetizer/presentation/feedback/components/FeedbackTile/feedback_tile.dart';
Expand Down Expand Up @@ -37,13 +38,14 @@ class FeedbackPage extends StatelessWidget {
toolbarHeight: 120.toAutoScaledHeight,
),
body: BlocProvider(
create: (context) => FeedbackPageBloc(),
create: (context) =>
FeedbackPageBloc(repo: context.read<FeedbackRepository>()),
child: BlocBuilder<FeedbackPageBloc, FeedbackPageState>(
builder: (context, state) {
// if (state.submitted) {
// // TODO: Add success screen or navigate back
// return const Placeholder();
// }
if (state.submitted) {
// TODO: Add success screen or navigate back
return const Placeholder();
}
return SingleChildScrollView(
padding: const EdgeInsets.only(left: 24, right: 26),
child: Column(
Expand Down
90 changes: 35 additions & 55 deletions lib/presentation/notifications/bloc/notification_page_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appetizer/domain/models/user/notification.dart';
import 'package:appetizer/domain/repositories/user_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

Expand All @@ -7,68 +8,47 @@ part 'notification_page_state.dart';

class NotificationPageBloc
extends Bloc<NotificationPageEvent, NotificationPageState> {
NotificationPageBloc() : super(const NotificationPageInitialState()) {
on<NotificationPageFetchEvent>((NotificationPageFetchEvent event,
Emitter<NotificationPageState> emit) {
// TODO: implement repository call
bool submissionSuccessful = true;
List<Notification> notifications = [
const Notification(
id: 123,
dateCreated: 532523,
title: "Yesssir",
message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas"),
const Notification(
id: 123,
dateCreated: 532523,
title: "Yesssir",
message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas"),
const Notification(
id: 123,
dateCreated: 532523,
title: "Yesssir",
message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas")
];
if (submissionSuccessful) {
final UserRepository repo;
NotificationPageBloc({
required this.repo,
}) : super(const NotificationPageInitialState()) {
on<NotificationPageFetchEvent>(
(NotificationPageFetchEvent event,
Emitter<NotificationPageState> emit) async {
List<Notification> notifications = await repo.getNotifications();
emit(
NotificationPageFetchedState(
option: 0,
notifications: notifications,
),
);
}
// else {
// emit(
// NotificationPageFailedState(
// notifications: event.notifications,
// ),
// );
// }
});

on<NotificationPageSwitchChangedEvent>(
(NotificationPageSwitchChangedEvent event,
Emitter<NotificationPageState> emit) {
List<Notification> notifications = [
const Notification(
id: 123,
dateCreated: 532523,
title: "Yesssir",
message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas"),
const Notification(
id: 123,
dateCreated: 532523,
title: "Yesssir",
message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas"),
const Notification(
id: 123,
dateCreated: 532523,
title: "Yesssir",
message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas")
];
emit(NotificationPageFetchedState(
option: event.option, notifications: notifications));
// TODO: add fail state
},
);
// TODO: remove swithc bar and option related events and logic
// on<NotificationPageSwitchChangedEvent>(
// (NotificationPageSwitchChangedEvent event,
// Emitter<NotificationPageState> emit) {
// List<Notification> notifications = [
// const Notification(
// id: 123,
// dateCreated: 532523,
// title: "Yesssir",
// message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas"),
// const Notification(
// id: 123,
// dateCreated: 532523,
// title: "Yesssir",
// message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas"),
// const Notification(
// id: 123,
// dateCreated: 532523,
// title: "Yesssir",
// message: "fasfafafassfadasdadsafafasfsdfafasfasfasfasfasfas")
// ];
// emit(NotificationPageFetchedState(
// option: event.option, notifications: notifications));
// },
// );
}
}
16 changes: 8 additions & 8 deletions lib/presentation/notifications/bloc/notification_page_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class NotificationPageFetchEvent extends NotificationPageEvent {
List<Object> get props => [notifications];
}

class NotificationPageSwitchChangedEvent extends NotificationPageEvent {
const NotificationPageSwitchChangedEvent({
required this.option,
});
// class NotificationPageSwitchChangedEvent extends NotificationPageEvent {
// const NotificationPageSwitchChangedEvent({
// required this.option,
// });

final int option;
// final int option;

@override
List<Object> get props => [option];
}
// @override
// List<Object> get props => [option];
// }
164 changes: 82 additions & 82 deletions lib/presentation/notifications/components/switch_bar.dart
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/notifications/bloc/notification_page_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
// import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
// import 'package:appetizer/presentation/notifications/bloc/notification_page_bloc.dart';
// import 'package:flutter/material.dart';
// import 'package:flutter_bloc/flutter_bloc.dart';

class SwitchBarWidget extends StatelessWidget {
const SwitchBarWidget({
required this.option,
Key? key,
}) : super(key: key);
// class SwitchBarWidget extends StatelessWidget {
// const SwitchBarWidget({
// required this.option,
// Key? key,
// }) : super(key: key);

final int option;
// final int option;

@override
Widget build(BuildContext context) {
return Row(
children: [
SizedBox(
width: 180.toAutoScaledWidth,
child: GestureDetector(
onTap: () => context
.read<NotificationPageBloc>()
.add(const NotificationPageSwitchChangedEvent(option: 0)),
child: Column(
children: [
SizedBox(height: 2.toAutoScaledHeight),
SizedBox(
width: 180.toAutoScaledWidth,
height: 31.toAutoScaledHeight,
child: Text(
'New',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 20.toAutoScaledFont,
fontFamily: 'Lato',
fontWeight: FontWeight.w600,
),
),
),
Divider(
height: 2,
thickness: 2,
color: option == 0 ? Colors.black : Colors.transparent,
),
],
),
),
),
SizedBox(
width: 181.toAutoScaledWidth,
child: GestureDetector(
onTap: () => context
.read<NotificationPageBloc>()
.add(const NotificationPageSwitchChangedEvent(option: 1)),
child: Column(
children: [
SizedBox(height: 2.toAutoScaledHeight),
SizedBox(
width: 181.toAutoScaledWidth,
height: 31.toAutoScaledHeight,
child: Text(
'Previous',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 20.toAutoScaledFont,
fontFamily: 'Lato',
fontWeight: FontWeight.w600,
),
),
),
Divider(
height: 2,
thickness: 2,
color: option == 1 ? Colors.black : Colors.transparent,
),
],
),
),
),
],
);
}
}
// @override
// Widget build(BuildContext context) {
// return Row(
// children: [
// SizedBox(
// width: 180.toAutoScaledWidth,
// child: GestureDetector(
// onTap: () => context
// .read<NotificationPageBloc>()
// .add(const NotificationPageSwitchChangedEvent(option: 0)),
// child: Column(
// children: [
// SizedBox(height: 2.toAutoScaledHeight),
// SizedBox(
// width: 180.toAutoScaledWidth,
// height: 31.toAutoScaledHeight,
// child: Text(
// 'New',
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 20.toAutoScaledFont,
// fontFamily: 'Lato',
// fontWeight: FontWeight.w600,
// ),
// ),
// ),
// Divider(
// height: 2,
// thickness: 2,
// color: option == 0 ? Colors.black : Colors.transparent,
// ),
// ],
// ),
// ),
// ),
// SizedBox(
// width: 181.toAutoScaledWidth,
// child: GestureDetector(
// onTap: () => context
// .read<NotificationPageBloc>()
// .add(const NotificationPageSwitchChangedEvent(option: 1)),
// child: Column(
// children: [
// SizedBox(height: 2.toAutoScaledHeight),
// SizedBox(
// width: 181.toAutoScaledWidth,
// height: 31.toAutoScaledHeight,
// child: Text(
// 'Previous',
// textAlign: TextAlign.center,
// style: TextStyle(
// color: Colors.white,
// fontSize: 20.toAutoScaledFont,
// fontFamily: 'Lato',
// fontWeight: FontWeight.w600,
// ),
// ),
// ),
// Divider(
// height: 2,
// thickness: 2,
// color: option == 1 ? Colors.black : Colors.transparent,
// ),
// ],
// ),
// ),
// ),
// ],
// );
// }
// }
Loading