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
| import 'package:flutter/material.dart'; | |
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
| import 'package:todo_list_riverpod/domain/todo_model.dart'; | |
| import 'package:todo_list_riverpod/presentation/pages/home_page/constants/texts.dart'; | |
| import 'package:todo_list_riverpod/presentation/pages/home_page/widgets/todos_action_part.dart'; | |
| import 'package:todo_list_riverpod/presentation/pages/home_page/widgets/todos_part.dart'; | |
| import 'package:todo_list_riverpod/providers/todo_provider.dart'; | |
| class HomePage extends ConsumerWidget { | |
| const HomePage({Key? key}) : super(key: key); |
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
| @override | |
| Widget build(BuildContext context, WidgetRef ref) { | |
| final todoList = ref.watch(todoNotifierProvider.select((state) => state.todoList)); | |
| final reversedTodoList = List<TodoModel>.from(todoList.reversed); | |
| . | |
| . | |
| . |
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
| onPressed: () { | |
| ref.read(todoNotifierProvider.notifier).mapEventsToStates( | |
| TodoTitleChanged(text: textfieldController.value.text), | |
| ); | |
| ref.read(todoNotifierProvider.notifier).mapEventsToStates( | |
| const AddTodo(), | |
| ); | |
| textfieldController.clear(); | |
| }, |
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 | |
| flutter_riverpod: ^1.0.4 | |
| freezed_annotation: ^2.0.3 | |
| sizer: ^2.0.15 | |
| dio: ^4.0.6 | |
| cached_network_image: ^3.2.1 | |
| 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
| class ApiService { | |
| Future<List> getCharactersDatas() async { | |
| final response = await Dio().get( | |
| "https://rickandmortyapi.com/api/character", | |
| ); | |
| return response.data["results"]; | |
| } | |
| } |
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 apiProvider = Provider((ref) => ApiService()); |
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 charactersDatasProvider = FutureProvider.autoDispose<List<CharacterModel>>( | |
| (ref) { | |
| return ref.read(apiProvider).getCharactersDatas().then( | |
| (characters) { | |
| final List<CharacterModel> characterList = []; | |
| for (var i = 0; i < 10; i++) { | |
| characterList.add( | |
| CharacterModel( | |
| characterName: characters[i]["name"], |
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
| part 'character.freezed.dart'; | |
| @freezed | |
| class CharacterModel with _$CharacterModel { | |
| factory CharacterModel({ | |
| required String characterName, | |
| required String characterImgUrl, | |
| }) = _CharacterModel; | |
| const CharacterModel._(); |
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
| part 'search_state.freezed.dart'; | |
| @freezed | |
| class SearchState with _$SearchState { | |
| factory SearchState({ | |
| required List<CharacterModel> characterList, | |
| }) = _SearchState; | |
| const SearchState._(); | |
| factory SearchState.empty() => SearchState( |
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
| part 'search_event.freezed.dart'; | |
| @freezed | |
| class SearchEvent with _$SearchEvent { | |
| const factory SearchEvent.searchedTextChanged({required String text}) = SearchedTextChanged; | |
| const factory SearchEvent.updateListItems({required List<CharacterModel> characterModelList}) = UpdateListItems; | |
| } |