Debugging and Common Errors
Common Errors and Solutions
1. Error: Launching lib/main.dart on sdk gphone x86 in debug mode...
Solution:
- Go to lib → utils → api.dart and make sure your server base URL is correct.
- Go to lib → firebase_option.dart and make sure all firebase configurations are set up correctly.
- Make sure that your AVD (Android Virtual Device) is correctly configured and working properly.
2. Error: MissingPluginException(No implementation found for method getAll on channel)
Solution:
- Go to the location where the flutter project exists and use the terminal for the below commands:
flutter clean
flutter pub get - Check build.gradle if Google Services plugin is added.
- Restart the Android Studio and rebuild the project.
3. Error: RPC Error: Invalid argument(s)
Solution:
- Go to Android Studio Settings → Preferences → Tools → Flutter and Uncheck "Format code on save" option.
- Completely delete your project from Android Studio and reopen it.
- Restart your computer and check internet connection.
4. Error: Firebase connectionFailed
Error
Solution:
- Ensure the JSON file for Firebase configuration has been placed correctly.
- Check that your app has internet permission in AndroidManifest.xml.
- Verify all Firebase-related dependencies are correctly included in pubspec.yaml.
- Make sure your Google-services.json file has the correct SHA-1 key.
5. Error: App crashes when sending notifications
Solution:
- Check that the FCM token is being generated and stored correctly.
- Verify that the notification channels are set up correctly.
- Ensure proper permissions are set in AndroidManifest.xml.
6. Error: Image assets not showing up
Solution:
- Make sure the paths to image assets in the pubspec.yaml file are correct.
- Run
flutter clean
followed byflutter pub get
. - Verify that the images are in the correct format and not corrupted.
Performance Tips
-
Memory Usage: Monitor memory usage with the Flutter DevTools.
-
Render Performance: Use the Timeline view in DevTools to identify expensive build operations.
-
Widgets Optimization:
- Use const constructors where possible
- Implement the
shouldRepaint
method in custom painters - Use RepaintBoundary to isolate repaints
-
Network Requests:
- Cache responses when appropriate
- Implement pagination for large data sets
- Use proper error handling for network failures