-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aae98ca
commit a60b19d
Showing
9 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
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
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
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/models/models.dart'; | ||
import 'package:garcon/repositories/terms/base_terms_repo.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
part 'terms_event.dart'; | ||
|
||
part 'terms_state.dart'; | ||
|
||
class TermsBloc extends Bloc<TermsEvent, TermsState> { | ||
final BaseTermsRepository _termsRepository; | ||
|
||
TermsBloc(this._termsRepository) : super(TermsInitial()) { | ||
on<GetTermsEvent>((event, emit) async { | ||
emit(TermsLoading()); | ||
try { | ||
final terms = await _termsRepository.getTerms().first; | ||
emit(TermsLoaded(terms)); | ||
} catch (e) { | ||
emit(TermsError('Failed to fetch terms info: $e')); | ||
} | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'terms_bloc.dart'; | ||
|
||
@sealed | ||
abstract class TermsEvent extends Equatable { | ||
const TermsEvent(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
class GetTermsEvent extends TermsEvent {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
part of 'terms_bloc.dart'; | ||
|
||
abstract class TermsState extends Equatable { | ||
const TermsState(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
class TermsInitial extends TermsState {} | ||
|
||
class TermsLoading extends TermsState {} | ||
|
||
class TermsLoaded extends TermsState { | ||
final Terms terms; | ||
|
||
const TermsLoaded(this.terms); | ||
|
||
@override | ||
List<Object> get props => [terms]; | ||
} | ||
|
||
class TermsError extends TermsState { | ||
final String error; | ||
|
||
const TermsError(this.error); | ||
|
||
@override | ||
List<Object> get props => [error]; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class Terms extends Equatable { | ||
final String header1; | ||
final String subheader1; | ||
final String header2; | ||
final String subheader2; | ||
|
||
const Terms({ | ||
required this.header1, | ||
required this.subheader1, | ||
required this.header2, | ||
required this.subheader2, | ||
}); | ||
|
||
static Terms fromSnapShot(DocumentSnapshot snap) { | ||
Terms terms = Terms( | ||
header1: snap["header1"], | ||
subheader1: snap["subheader1"], | ||
header2: snap["header2"], | ||
subheader2: snap["subheader2"], | ||
); | ||
return terms; | ||
} | ||
|
||
@override | ||
List<Object?> get props => [ | ||
header1, | ||
subheader1, | ||
header2, | ||
subheader2, | ||
]; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../../models/models.dart'; | ||
|
||
abstract class BaseTermsRepository{ | ||
Stream<Terms> getTerms(); | ||
} |
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
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/terms.dart'; | ||
import 'package:garcon/repositories/terms/base_terms_repo.dart'; | ||
|
||
class TermsRepository extends BaseTermsRepository { | ||
final FirebaseFirestore _firebaseFirestore; | ||
|
||
TermsRepository({FirebaseFirestore? firebaseFirestore}) | ||
: _firebaseFirestore = firebaseFirestore ?? FirebaseFirestore.instance; | ||
|
||
@override | ||
Stream<Terms> getTerms() { | ||
return _firebaseFirestore | ||
.collection("info") | ||
.doc("terms") | ||
.snapshots() | ||
.map((snap) => Terms.fromSnapShot(snap)); | ||
} | ||
} |