Skip to content

Instantly share code, notes, and snippets.

View FlutterWiz's full-sized avatar
🎯
Discipline

FlutterWiz FlutterWiz

🎯
Discipline
View GitHub Profile
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()
final searchProvider = StateNotifierProvider.autoDispose<SearchNotifier, SearchState>(
(ref) {
final characterModelList = ref.watch(charactersDatasProvider).whenOrNull(data: (data) => data);
return SearchNotifier()
..mapEventsToState(
UpdateListItems(
characterModelList: characterModelList ?? [],
),
);
void main() {
runApp(
ProviderScope(
child: Sizer(
builder: (context, orientation, deviceType) {
return const AppWidget();
},
),
),
);
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(
final List<CharacterModel> characterList = ref.watch(searchProvider).characterList;
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
void main() {
//configureDependencies() method is for the Dependenct Injection
configureDependencies();
runApp(const AppWidget());
}
final getIt = GetIt.instance;
@InjectableInit()
void configureDependencies() => $initGetIt(getIt);
@module
abstract class InjectableModule {
@singleton
AppRouter get appRouter => AppRouter();
}
@freezed
class NotificationEvent with _$NotificationEvent {
const factory NotificationEvent.sendNormalNotification() =
SendNormalNotification;
const factory NotificationEvent.sendNotificationAfter3Seconds() =
SendNotificationAfter3Seconds;
}