feat : chicken root page , inventory , sale in province

This commit is contained in:
MrM
2025-06-05 23:26:44 +03:30
parent 5849466e3b
commit 1cfcf9fa8f
68 changed files with 16615 additions and 126 deletions

View File

@@ -0,0 +1,14 @@
enum ApiEnvironment {
dam(url: 'https://api.dam.rasadyar.net/');
const ApiEnvironment({required this.url});
final String url;
String get baseUrl {
switch (this) {
case ApiEnvironment.dam:
return url;
}
}
}

View File

@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
class DioErrorHandler {
void handle(DioException error) {
switch (error.response?.statusCode) {
case 401:
_handleGeneric(error);
break;
case 403:
_handleGeneric(error);
break;
case 410:
_handle410();
break;
default:
_handleGeneric(error);
}
}
//wrong password/user name => "detail": "No active account found with the given credentials" - 401
void _handle410() {
Get.showSnackbar(_errorSnackBar('نام کاربری یا رمز عبور اشتباه است'));
}
//wrong captcha => "detail": "Captcha code is incorrect" - 403
void _handle403() {}
void _handleGeneric(DioException error) {
Get.showSnackbar(
_errorSnackBar(
error.response?.data.keys.first == 'is_user'
? 'کاربر با این شماره تلفن وجود ندارد'
: error.response?.data[error.response?.data.keys.first] ??
'خطا در برقراری ارتباط با سرور',
),
);
}
GetSnackBar _errorSnackBar(String message) {
return GetSnackBar(
titleText: Text(
'خطا',
style: AppFonts.yekan14.copyWith(color: Colors.white),
),
messageText: Text(
message,
style: AppFonts.yekan12.copyWith(color: Colors.white),
),
backgroundColor: AppColor.error,
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
borderRadius: 12,
duration: Duration(milliseconds: 3500),
snackPosition: SnackPosition.TOP,
);
}
}

View File

@@ -0,0 +1,33 @@
import 'package:rasadyar_auth/data/repositories/auth_repository_imp.dart';
import 'package:rasadyar_core/core.dart';
import '../di/chicken_di.dart';
import 'constant.dart';
class DioRemoteManager {
DioRemote? _currentClient;
ApiEnvironment? _currentEnv;
Future<DioRemote> setEnvironment([
ApiEnvironment env = ApiEnvironment.dam,
]) async {
if (_currentEnv != env) {
_currentClient = DioRemote(baseUrl: env.baseUrl);
await _currentClient?.init();
_currentEnv = env;
}
return _currentClient!;
}
DioRemote get currentClient {
if (_currentClient == null) {
throw Exception('Call setEnvironment() before accessing DioRemote.');
}
return _currentClient!;
}
ApiEnvironment? get currentEnv => _currentEnv;
}