5.0 KiB
API Integration Complete
✅ API Configuration Updated
All API endpoints and authentication have been updated to match the actual backend API from /lib/docs/api.sh.
🔗 API Base URL
Base URL: https://dotnet.elidev.info:8157/ws
App ID: Minhthu2016
🔐 Authentication Updates
Headers Changed:
- ❌ Old:
Authorization: Bearer {token} - ✅ New:
AccessToken: {token} - ✅ Added:
AppID: Minhthu2016
Login Request Format:
- ❌ Old fields:
username,password - ✅ New fields:
EmailPhone,Password
📍 API Endpoints Updated
| Feature | Endpoint | Method | Notes |
|---|---|---|---|
| Login | /PortalAuth/Login |
POST | EmailPhone + Password |
| Warehouses | /portalWareHouse/search |
POST | Pagination params required |
| Products | /portalProduct/getAllProduct |
GET | Returns all products |
🛠️ Files Modified
1. app_constants.dart
static const String apiBaseUrl = 'https://dotnet.elidev.info:8157/ws';
static const String appId = 'Minhthu2016';
2. api_endpoints.dart
static const String login = '/PortalAuth/Login';
static const String warehouses = '/portalWareHouse/search';
static const String products = '/portalProduct/getAllProduct';
3. api_client.dart
// Changed from Authorization: Bearer to AccessToken
options.headers['AccessToken'] = token;
options.headers['AppID'] = AppConstants.appId;
4. login_request_model.dart
Map<String, dynamic> toJson() {
return {
'EmailPhone': username, // Changed from 'username'
'Password': password, // Changed from 'password'
};
}
5. warehouse_remote_datasource.dart
// Changed from GET to POST with pagination
final response = await apiClient.post(
'/portalWareHouse/search',
data: {
'pageIndex': 0,
'pageSize': 100,
'Name': null,
'Code': null,
'sortExpression': null,
'sortDirection': null,
},
);
6. products_remote_datasource.dart
// Updated to use correct endpoint
final response = await apiClient.get('/portalProduct/getAllProduct');
🎯 Pre-filled Test Credentials
The login form is pre-filled with test credentials:
- Email:
yesterday305@gmail.com - Password:
123456
🚀 Ready to Test
The app is now configured to connect to the actual backend API. You can:
-
Run the app:
flutter run -
Test the flow:
- Login with pre-filled credentials
- View warehouses list
- Select a warehouse
- Choose Import or Export
- View products
📝 API Request Examples
Login Request:
POST https://dotnet.elidev.info:8157/ws/PortalAuth/Login
Headers:
Content-Type: application/json
AppID: Minhthu2016
Body:
{
"EmailPhone": "yesterday305@gmail.com",
"Password": "123456"
}
Get Warehouses Request:
POST https://dotnet.elidev.info:8157/ws/portalWareHouse/search
Headers:
Content-Type: application/json
AppID: Minhthu2016
AccessToken: {token_from_login}
Body:
{
"pageIndex": 0,
"pageSize": 100,
"Name": null,
"Code": null,
"sortExpression": null,
"sortDirection": null
}
Get Products Request:
GET https://dotnet.elidev.info:8157/ws/portalProduct/getAllProduct
Headers:
AppID: Minhthu2016
AccessToken: {token_from_login}
⚠️ Important Notes
-
HTTPS Certificate: The API uses a self-signed certificate. You may need to handle SSL certificate validation in production.
-
CORS: Make sure CORS is properly configured on the backend for mobile apps.
-
Token Storage: Access tokens are securely stored using
flutter_secure_storage. -
Error Handling: All API errors are properly handled and displayed to users.
-
Logging: API requests and responses are logged in debug mode for troubleshooting.
🔍 Testing Checklist
- Login with test credentials works
- Access token is saved in secure storage
- Warehouses list loads successfully
- Warehouse selection works
- Navigation to operations page works
- Products list loads successfully
- All UI states work (loading, error, success, empty)
- Refresh functionality works
- Logout clears the token
🐛 Troubleshooting
If login fails:
- Check internet connection
- Verify API is accessible at
https://dotnet.elidev.info:8157 - Check credentials are correct
- Look at debug logs for detailed error messages
If API calls fail after login:
- Verify access token is being saved
- Check that AccessToken and AppID headers are being sent
- Verify token hasn't expired
- Check API logs for detailed error information
📚 Related Files
/lib/docs/api.sh- Original curl commands/lib/core/constants/app_constants.dart- API configuration/lib/core/constants/api_endpoints.dart- Endpoint definitions/lib/core/network/api_client.dart- HTTP client configuration/lib/features/auth/data/models/login_request_model.dart- Login request format
Status: ✅ Ready for testing with production API Last Updated: $(date)