Skip to content

Commit

Permalink
privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
mo7amedaliEbaid committed Jul 27, 2024
1 parent a60b19d commit 6521c22
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/application/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'blocs/restaurants/restaurants_bloc.dart';
export 'blocs/tags/tags_bloc.dart';
export 'blocs/about_us/about_us_bloc.dart';
export 'blocs/terms/terms_bloc.dart';
export 'blocs/privacy/privacy_bloc.dart';

//cubits
export 'cubits/connectivity/connectivity_cubit.dart';
Expand Down
25 changes: 25 additions & 0 deletions lib/application/blocs/privacy/privacy_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:garcon/repositories/privacy/base_privacy_repo.dart';

import '../../../models/info.dart';

part 'privacy_event.dart';

part 'privacy_state.dart';

class PrivacyBloc extends Bloc<PrivacyEvent, PrivacyState> {
final BasePrivacyRepository _privacyRepository;

PrivacyBloc(this._privacyRepository) : super(PrivacyInitial()) {
on<GetPrivacyEvent>((event, emit) async {
emit(PrivacyLoading());
try {
final privacy = await _privacyRepository.getPrivacy().first;
emit(PrivacyLoaded(privacy));
} catch (e) {
emit(PrivacyError('Failed to fetch terms info: $e'));
}
});
}
}
10 changes: 10 additions & 0 deletions lib/application/blocs/privacy/privacy_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
part of 'privacy_bloc.dart';

abstract class PrivacyEvent extends Equatable {
const PrivacyEvent();

@override
List<Object> get props => [];
}

class GetPrivacyEvent extends PrivacyEvent {}
30 changes: 30 additions & 0 deletions lib/application/blocs/privacy/privacy_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
part of 'privacy_bloc.dart';

abstract class PrivacyState extends Equatable {
const PrivacyState();

@override
List<Object> get props => [];
}

class PrivacyInitial extends PrivacyState {}

class PrivacyLoading extends PrivacyState {}

class PrivacyLoaded extends PrivacyState {
final Info privacy;

const PrivacyLoaded(this.privacy);

@override
List<Object> get props => [privacy];
}

class PrivacyError extends PrivacyState {
final String error;

const PrivacyError(this.error);

@override
List<Object> get props => [error];
}
2 changes: 1 addition & 1 deletion lib/application/blocs/terms/terms_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TermsInitial extends TermsState {}
class TermsLoading extends TermsState {}

class TermsLoaded extends TermsState {
final Terms terms;
final Info terms;

const TermsLoaded(this.terms);

Expand Down
10 changes: 10 additions & 0 deletions lib/core/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class MyApp extends StatelessWidget {
BlocProvider(
create: (context) => SelectedTapCubit(),
),
BlocProvider(
create: (context) => TermsBloc(
TermsRepository(),
),
),
BlocProvider(
create: (context) => PrivacyBloc(
PrivacyRepository(),
),
),
],
child: MaterialApp(
title: 'Garcon',
Expand Down
10 changes: 5 additions & 5 deletions lib/models/terms.dart → lib/models/info.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:equatable/equatable.dart';

class Terms extends Equatable {
class Info extends Equatable {
final String header1;
final String subheader1;
final String header2;
final String subheader2;

const Terms({
const Info({
required this.header1,
required this.subheader1,
required this.header2,
required this.subheader2,
});

static Terms fromSnapShot(DocumentSnapshot snap) {
Terms terms = Terms(
static Info fromSnapShot(DocumentSnapshot snap) {
Info info = Info(
header1: snap["header1"],
subheader1: snap["subheader1"],
header2: snap["header2"],
subheader2: snap["subheader2"],
);
return terms;
return info;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export 'pickup.dart';
export 'reservation.dart';
export 'about_us.dart';
export 'order.dart';
export 'terms.dart';
export 'info.dart';
67 changes: 65 additions & 2 deletions lib/presentation/screens/privacy.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:garcon/configs/configs.dart';
import 'package:garcon/core/core.dart';
import 'package:garcon/application/application.dart';
import '../widgets.dart';

class PrivacyScreen extends StatelessWidget {
class PrivacyScreen extends StatefulWidget {
const PrivacyScreen({super.key});

@override
State<PrivacyScreen> createState() => _PrivacyScreenState();
}

class _PrivacyScreenState extends State<PrivacyScreen> {
@override
void initState() {
context.read<PrivacyBloc>().add(GetPrivacyEvent());
super.initState();
}

@override
Widget build(BuildContext context) {
return const Placeholder();
return Scaffold(
appBar: customAppBar(context: context, title: "Privacy Policy"),
body: BlocBuilder<PrivacyBloc, PrivacyState>(
builder: (context, state) {
if (state is PrivacyError) {
return Center(
child: Text(
"error loading info",
style: AppText.h3b,
),
);
} else if (state is PrivacyLoading) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (state is PrivacyLoaded) {
return Padding(
padding: Space.hf(1.5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Space.yf(1.5),
Text(
state.privacy.header1.capitalize(),
style: AppText.h3b?.copyWith(height: 2),
),
verseText(
text: state.privacy.subheader1,
withPadding: false,
),
Space.yf(1.5),
Text(
state.privacy.header2.capitalize(),
style: AppText.h3b?.copyWith(height: 2),
),
verseText(
text: state.privacy.subheader2,
withPadding: false,
),
],
),
);
}
return const SizedBox.shrink();
},
),
);
;
}
}
68 changes: 66 additions & 2 deletions lib/presentation/screens/terms.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,74 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:garcon/core/core.dart';
import 'package:garcon/application/application.dart';
import 'package:garcon/configs/configs.dart';
import 'package:garcon/presentation/widgets.dart';

class TermsScreen extends StatelessWidget {
class TermsScreen extends StatefulWidget {
const TermsScreen({super.key});

@override
State<TermsScreen> createState() => _TermsScreenState();
}

class _TermsScreenState extends State<TermsScreen> {
@override
void initState() {
context.read<TermsBloc>().add(
GetTermsEvent(),
);
super.initState();
}

@override
Widget build(BuildContext context) {
return const Placeholder();
return Scaffold(
appBar: customAppBar(context: context, title: "Terms of Service"),
body: BlocBuilder<TermsBloc, TermsState>(
builder: (context, state) {
if (state is TermsError) {
return Center(
child: Text(
"error loading info",
style: AppText.h3b,
),
);
} else if (state is TermsLoading) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (state is TermsLoaded) {
return Padding(
padding: Space.hf(1.5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Space.yf(1.5),
Text(
state.terms.header1.capitalize(),
style: AppText.h3b?.copyWith(height: 2),
),
verseText(
text: state.terms.subheader1,
withPadding: false,
),
Space.yf(1.5),
Text(
state.terms.header2.capitalize(),
style: AppText.h3b?.copyWith(height: 2),
),
verseText(
text: state.terms.subheader2,
withPadding: false,
),
],
),
);
}
return const SizedBox.shrink();
},
),
);
}
}
10 changes: 7 additions & 3 deletions lib/presentation/widgets/settings_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ Widget settingsItem(
],
);
}
Widget verseText({required String text}) {

Widget verseText({
required String text,
bool withPadding = true,
}) {
return Padding(
padding: Space.h1!,
padding: withPadding ? Space.h1! : EdgeInsets.zero,
child: Text(
text,
style: AppText.b2!.copyWith(
color: AppColors.greyColor,
),
),
);
}
}
5 changes: 5 additions & 0 deletions lib/repositories/privacy/base_privacy_repo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../../models/models.dart';

abstract class BasePrivacyRepository{
Stream<Info> getPrivacy();
}
19 changes: 19 additions & 0 deletions lib/repositories/privacy/privacy_repo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:garcon/models/info.dart';
import 'package:garcon/repositories/privacy/base_privacy_repo.dart';

class PrivacyRepository extends BasePrivacyRepository {
final FirebaseFirestore _firebaseFirestore;

PrivacyRepository({FirebaseFirestore? firebaseFirestore})
: _firebaseFirestore = firebaseFirestore ?? FirebaseFirestore.instance;

@override
Stream<Info> getPrivacy() {
return _firebaseFirestore
.collection("info")
.doc("privacy")
.snapshots()
.map((snap) => Info.fromSnapShot(snap));
}
}
3 changes: 2 additions & 1 deletion lib/repositories/repositories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export 'reservation/reservation_repo.dart';
export 'about/about_repo.dart';
export 'cart/cart_repo.dart';
export 'orders/orders_repo.dart';
export 'terms/terms_repo.dart';
export 'terms/terms_repo.dart';
export 'privacy/privacy_repo.dart';
2 changes: 1 addition & 1 deletion lib/repositories/terms/base_terms_repo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../../models/models.dart';

abstract class BaseTermsRepository{
Stream<Terms> getTerms();
Stream<Info> getTerms();
}
6 changes: 3 additions & 3 deletions lib/repositories/terms/terms_repo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:garcon/models/terms.dart';
import 'package:garcon/models/models.dart';
import 'package:garcon/repositories/terms/base_terms_repo.dart';

class TermsRepository extends BaseTermsRepository {
Expand All @@ -9,11 +9,11 @@ class TermsRepository extends BaseTermsRepository {
: _firebaseFirestore = firebaseFirestore ?? FirebaseFirestore.instance;

@override
Stream<Terms> getTerms() {
Stream<Info> getTerms() {
return _firebaseFirestore
.collection("info")
.doc("terms")
.snapshots()
.map((snap) => Terms.fromSnapShot(snap));
.map((snap) => Info.fromSnapShot(snap));
}
}

0 comments on commit 6521c22

Please sign in to comment.