-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* search implementation * Apply code formatting * Fixed revisions * Fixed revisions * Fixed revisions * Fixed revisions
- Loading branch information
1 parent
3f3895e
commit 956a4f6
Showing
10 changed files
with
354 additions
and
3 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 @@ | ||
enum SearchResultType { session, speaker, organizer } |
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,21 @@ | ||
import 'package:fluttercon/common/data/enums/search_result_type.dart'; | ||
import 'package:fluttercon/common/data/models/local/local_individual_organiser.dart'; | ||
import 'package:fluttercon/common/data/models/local/local_session.dart'; | ||
import 'package:fluttercon/common/data/models/local/local_speaker.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'search_result.freezed.dart'; | ||
|
||
@freezed | ||
class SearchResult with _$SearchResult { | ||
const factory SearchResult({ | ||
required String id, | ||
required String title, | ||
required String subtitle, | ||
required String imageUrl, | ||
required SearchResultType type, | ||
LocalSession? session, | ||
LocalSpeaker? speaker, | ||
LocalIndividualOrganiser? organizer, | ||
}) = _SearchResult; | ||
} |
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
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,69 @@ | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:fluttercon/common/data/enums/search_result_type.dart'; | ||
import 'package:fluttercon/common/data/models/failure.dart'; | ||
import 'package:fluttercon/common/data/models/search_result.dart'; | ||
import 'package:fluttercon/common/repository/db_repository.dart'; | ||
import 'package:fluttercon/search/cubit/search_state.dart'; | ||
|
||
class SearchCubit extends Cubit<SearchState> { | ||
SearchCubit({ | ||
required DBRepository dbRepository, | ||
}) : super(const SearchState.initial()) { | ||
_dbRepository = dbRepository; | ||
} | ||
|
||
late DBRepository _dbRepository; | ||
|
||
Future<void> search(String query) async { | ||
emit(const SearchState.loading()); | ||
try { | ||
final sessions = await _dbRepository.searchSessions(query); | ||
final speakers = await _dbRepository.searchSpeakers(query); | ||
final individualOrganizers = | ||
await _dbRepository.searchIndividualOrganisers(query); | ||
|
||
final results = [ | ||
...sessions.map( | ||
(session) => SearchResult( | ||
id: session.serverId.toString(), | ||
title: session.title, | ||
subtitle: 'Session', | ||
imageUrl: session.sessionImage, | ||
type: SearchResultType.session, | ||
session: session, | ||
), | ||
), | ||
...speakers.map( | ||
(speaker) => SearchResult( | ||
id: speaker.id.toString(), | ||
title: speaker.name, | ||
subtitle: speaker.tagline ?? '', | ||
imageUrl: speaker.avatar, | ||
type: SearchResultType.speaker, | ||
speaker: speaker, | ||
), | ||
), | ||
...individualOrganizers.map( | ||
(organizer) => SearchResult( | ||
id: organizer.id.toString(), | ||
title: organizer.name, | ||
subtitle: 'Organizer', | ||
imageUrl: organizer.photo, | ||
type: SearchResultType.organizer, | ||
organizer: organizer, | ||
), | ||
), | ||
]; | ||
|
||
emit(SearchState.loaded(results: results)); | ||
} on Failure catch (e) { | ||
emit(SearchState.error(message: e.message)); | ||
} catch (e) { | ||
emit(SearchState.error(message: e.toString())); | ||
} | ||
} | ||
|
||
void clearSearch() { | ||
emit(const SearchState.initial()); | ||
} | ||
} |
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,12 @@ | ||
import 'package:fluttercon/common/data/models/search_result.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
part 'search_state.freezed.dart'; | ||
|
||
@freezed | ||
class SearchState with _$SearchState { | ||
const factory SearchState.initial() = SearchInitial; | ||
const factory SearchState.loading() = SearchLoading; | ||
const factory SearchState.loaded({required List<SearchResult> results}) = | ||
SearchLoaded; | ||
const factory SearchState.error({required String message}) = SearchError; | ||
} |
Oops, something went wrong.