Launching lib\main.dart on SM G975N in debug mode...
√ Built build\app\outputs\flutter-apk\app-debug.apk
Connecting to VM Service at ws://127.0.0.1:51827/GCI3B2shZa8=/ws
Connected to the VM Service.
D/ProfileInstaller( 5697): Installing profile for com.example.learning
I/1.raster( 5697): type=1400 audit(0.0:1553): avc: denied { ioctl } for path="/dev/fastpipe" dev="tmpfs" ino=6208 ioctlcmd=6867 scontext=u:r:untrusted_app:s0:c61,c256,c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
D/EGL_adreno( 5697): eglMakeCurrent: 0x7fff6c06d160: ver 3 1 (tinfo 0x7fff4bc4d000)
I/1.raster( 5697): type=1400 audit(0.0:1572): avc: denied { ioctl } for path="/dev/fastpipe" dev="tmpfs" ino=6208 ioctlcmd=6867 scontext=u:r:untrusted_app:s0:c61,c256,c512,c768 tcontext=u:object_r:device:s0 tclass=chr_file permissive=1
E/flutter ( 5697): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Failed to retrieve the webpage. Status code: 404
E/flutter ( 5697): #0 NovelRemoteDataSource.getSearchedNovels (package:learning/Data/novel_remote_data_source.dart:428:7)
E/flutter ( 5697):
E/flutter ( 5697): #1 NovelRepository.getSearchedNovels (package:learning/Data/Repository/novel_repository.dart:81:9)
E/flutter ( 5697):
E/flutter ( 5697): #2 GetSearchedNovelsUsecase.execute (package:learning/Domain/Usecase/get_searched_novels_usecase.dart:12:12)
E/flutter ( 5697):
E/flutter ( 5697): #3 NovelCubit.getSearchedNovels (package:learning/Presentation/Controller/Novel/novel_cubit.dart:114:9)
E/flutter ( 5697):
E/flutter ( 5697):
Application finished.
Exited (-1).
Assistant
The error message you're encountering indicates that there was an unhandled exception in your Flutter application. Specifically, a 404 error occurred while attempting to retrieve a webpage, which likely means that the URL your application is trying to access is incorrect or the resource does not exist on the server.
User
Assistant
Here's a breakdown of the error and some steps you can take to troubleshoot and fix it:
Understand the Stack Trace:
The error originated in NovelRemoteDataSource.getSearchedNovels at line 428 in novel_remote_data_source.dart.
This function is called by NovelRepository.getSearchedNovels at line 81 in novel_repository.dart.
Then, the GetSearchedNovelsUsecase.execute is called at line 12 in get_searched_novels_usecase.dart.
Finally, it leads back to a method NovelCubit.getSearchedNovels at line 114 in novel_cubit.dart.
Verify the URL:
Check the URL that is being used in the getSearchedNovels method in novel_remote_data_source.dart. Ensure the URL is correct and that the server actually hosts the resource you're trying to access.
Server Side Check:
Verify that the server is running properly and that the endpoint you're trying to reach is available. Ensure that the endpoint hasn't been moved or removed.
Exception Handling:
Implement error handling for network requests. Make sure to handle any exceptions and provide a user-friendly message or a fallback mechanism if data fails to load.
Check Network Connection:
Ensure that the device running the app has a stable internet connection.
Log the URL and Response:
Add logging to the code to print out the URL being accessed and the response code to the console. This might give you more context on what's failing.
Check App Permissions:
Make sure your app has the necessary permissions defined in AndroidManifest.xml or Info.plist (for iOS) to access the internet.
Testing in Development:
Try running the application in debug mode with additional logging to trace how far the network call goes and at what point it fails.
Implement these troubleshooting steps to identify the root cause of the issue, and adjust your code or server configuration accordingly.
the function work here , import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:html/parser.dart';
import 'page2.dart'; // For HTML parsing
class NovelModel {
final String id;
final String title;
final String author;
final String image;
final List genre;
final String status;
final String publishers;
final String yearOfPublishing;
final String description;
final List chapters;
class _NovelSearchPageState extends State {
final TextEditingController _queryController = TextEditingController();
List _novels = [];
bool _isLoading = false;
To understand why the function that works in one context doesn't work in another, let's analyze the differences between the two implementations.
Standalone Implementation:
The first implementation uses a direct approach without Bloc, focusing on fetching data and displaying it on UI using a simple callback.
You manually handle HTTP requests and parse the HTML, which works fine in isolation when controlled directly within a stateful widget.
Bloc Implementation:
In the second implementation, you are using the Flutter Bloc library to manage state, which adds an abstraction layer.
Bloc is useful in separating business logic from UI, but it requires proper handling of events and states.
Troubleshooting Steps:
Check API Calls:
Ensure that getSearchedNovelsUsecase.execute(query, page) is correctly making the API call and that the URL is correct, similar to the standalone version.
Ensure that network requests are actually being fired and check what response is returned (HTTP status or errors).
Bloc State Management:
Ensure that states like NovelLoading, NovelSuccessfullyLoaded, and NovelError are properly defined.
Check if the states are emitted as expected in getSearchedNovels and properly handled in the UI like SearchResultScreen.
Error Handling:
Place logging around your network call method in getSearchedNovels to check if any errors occur that stop the execution.
Improve error messages, particularly checking if the URL changes based on different environments (dev, production).
Dependencies and Context:
Double-check that dependencies like searchedNovelsUsecase are properly injected.
Make sure serverLocator() provides all dependencies required by NovelCubit.
Navigation and Data Flow:
Ensure the NovelCubit instance is correctly initialized and that it has access to necessary dependencies or services for data fetching.
Verify that navigation to SearchResultScreen is happening correctly and that NovelCubit or any other Bloc necessary is provided to the screen using BlocProvider.
Handle State Changes:
Make sure the UI (like SearchResultScreen) listens to state changes from NovelCubit properly. Use BlocBuilder or BlocListener.
Debugging and Logging:
Add thorough debugging prints/logs within the Bloc implementation to monitor what events are fired, what the API call returns, and how states are changed.
By following these detailed steps, you should be able to identify the discrepancies and ensure that the behavior in the Bloc-based code matches your standalone code.