Overview
ReUCM uses a modular portal system where each book source is implemented as a separate package that implements thePortal and PortalService interfaces from re_ucm_core.
Prerequisites
Before creating a new portal, you should:- Understand the portal system architecture
- Review the
PortalandPortalServiceinterfaces - Study the Author.Today implementation as a reference
Step-by-step guide
Create a new package
Create a new directory in the monorepo root:Create a Add your package to the workspace in the root
pubspec.yaml file:pubspec.yaml:Implement the Portal interface
Create
lib/your_portal.dart:The
code property must be unique across all portals and is used for portal identification and registration.Implement the PortalService interface
Create
lib/your_portal_service.dart:The
onSettingsChanged callback allows you to notify the app when settings change (e.g., token refresh).Implement API client
Create an API client to communicate with the portal’s backend. Use Dio for HTTP requests:
Add logo asset
Add your portal’s logo to
assets/logo.svg (or .png) in your package directory.Update pubspec.yaml to include the asset:Register the portal
In the main app, register your portal in Add the dependency to
re_ucm_app/lib/core/di.dart:re_ucm_app/pubspec.yaml:Best practices
Error handling
Handle network errors gracefully:Token refresh
If your portal uses tokens that expire, implement automatic refresh:Content parsing
If the portal returns HTML content, you may need to parse it:Common issues
Portal doesn't appear in the app
Portal doesn't appear in the app
Make sure you:
- Added the portal to
PortalFactory.registerAll()indi.dart - Added the package dependency to
re_ucm_app/pubspec.yaml - Ran
flutter pub getafter adding the dependency
Authentication fails
Authentication fails
Check:
- The
startUrlandsuccessUrlin your WebAuthButton are correct - The
cookieNamematches what the portal sets - Your
_loginByCookiemethod correctly exchanges the cookie for a token
Book metadata parsing fails
Book metadata parsing fails
- Log the raw API response to understand the structure
- Ensure your model classes match the API response format
- Handle optional fields with nullable types
Next steps
- Review the Portal interface documentation
- Study the Author.Today implementation
- Learn about FB2 converters
- Submit a pull request to add your portal to ReUCM