This file contains hidden or 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
class SearchNotifier extends StateNotifier<SearchState> { | |
SearchNotifier() : super(SearchState.empty()); | |
void mapEventsToState(SearchEvent event) { | |
event.map( | |
searchedTextChanged: (searchedTextChangedEvent) { | |
final characterList = [...state.characterList]; | |
final searchedCharacterList = characterList | |
.where((characterModel) => characterModel.characterName | |
.toLowerCase() |
This file contains hidden or 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
final searchProvider = StateNotifierProvider.autoDispose<SearchNotifier, SearchState>( | |
(ref) { | |
final characterModelList = ref.watch(charactersDatasProvider).whenOrNull(data: (data) => data); | |
return SearchNotifier() | |
..mapEventsToState( | |
UpdateListItems( | |
characterModelList: characterModelList ?? [], | |
), | |
); |
This file contains hidden or 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
void main() { | |
runApp( | |
ProviderScope( | |
child: Sizer( | |
builder: (context, orientation, deviceType) { | |
return const AppWidget(); | |
}, | |
), | |
), | |
); |
This file contains hidden or 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
Consumer( | |
builder: (context, ref, child) { | |
return IconButton( | |
onPressed: () { | |
if (textfieldController.text.isEmpty) { | |
ref.refresh(searchProvider); | |
} else { | |
ref.refresh(searchProvider); | |
ref.read(searchProvider.notifier).mapEventsToState( | |
SearchedTextChanged( |
This file contains hidden or 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
final List<CharacterModel> characterList = ref.watch(searchProvider).characterList; |
This file contains hidden or 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
dependencies: | |
flutter: | |
sdk: flutter | |
auto_route: ^5.0.1 | |
flutter_riverpod: ^2.0.0 | |
awesome_notifications: ^0.7.1 | |
get_it: ^7.2.0 | |
injectable: ^1.5.3 | |
freezed_annotation: ^2.1.0 | |
cupertino_icons: ^1.0.2 |
This file contains hidden or 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
void main() { | |
//configureDependencies() method is for the Dependenct Injection | |
configureDependencies(); | |
runApp(const AppWidget()); | |
} |
This file contains hidden or 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
final getIt = GetIt.instance; | |
@InjectableInit() | |
void configureDependencies() => $initGetIt(getIt); |
This file contains hidden or 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
@module | |
abstract class InjectableModule { | |
@singleton | |
AppRouter get appRouter => AppRouter(); | |
} |
This file contains hidden or 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
@freezed | |
class NotificationEvent with _$NotificationEvent { | |
const factory NotificationEvent.sendNormalNotification() = | |
SendNormalNotification; | |
const factory NotificationEvent.sendNotificationAfter3Seconds() = | |
SendNotificationAfter3Seconds; | |
} |