Documentation Index
Fetch the complete documentation index at: https://docs-mstore.faisalaffan.com/llms.txt
Use this file to discover all available pages before exploring further.
Supplier Management
Manajemen supplier dan purchase orders
๐ฏ Overview
Supplier adalah salah satu fitur utama dalam MStore Mobile yang menyediakan fungsionalitas untuk manajemen supplier dan purchase orders.
๐ Features
- โ
Supplier CRUD
- โ
Purchase orders
- โ
Supplier performance
- โ
Payment tracking
- โ
Product sourcing
๐๏ธ Architecture
BLoC Implementation
BLoC: SupplierBloc
// Events
abstract class SupplierEvent extends Equatable {}
class LoadSupplier extends SupplierEvent {}
class CreateSupplier extends SupplierEvent {}
class UpdateSupplier extends SupplierEvent {}
class DeleteSupplier extends SupplierEvent {}
// States
abstract class SupplierState extends Equatable {}
class SupplierInitial extends SupplierState {}
class SupplierLoading extends SupplierState {}
class SupplierLoaded extends SupplierState {}
class SupplierError extends SupplierState {}
// BLoC
class SupplierBloc extends Bloc<SupplierEvent, SupplierState> {
final SupplierRepository _repository;
SupplierBloc({required SupplierRepository repository})
: _repository = repository,
super(SupplierInitial()) {
on<LoadSupplier>(_onLoad);
on<CreateSupplier>(_onCreate);
on<UpdateSupplier>(_onUpdate);
on<DeleteSupplier>(_onDelete);
}
Future<void> _onLoad(
LoadSupplier event,
Emitter<SupplierState> emit,
) async {
emit(SupplierLoading());
final result = await _repository.getSuppliers();
result.fold(
(failure) => emit(SupplierError(failure.message)),
(data) => emit(SupplierLoaded(data)),
);
}
}
Repository Pattern
abstract class SupplierRepository {
Future<Either<Failure, List<Supplier>>> getSuppliers();
Future<Either<Failure, Supplier>> getSupplierById(String id);
Future<Either<Failure, Supplier>> createSupplier(Supplier data);
Future<Either<Failure, Supplier>> updateSupplier(String id, Supplier data);
Future<Either<Failure, void>> deleteSupplier(String id);
}
class SupplierRepositoryImpl implements SupplierRepository {
final SupplierApi _api;
final SupplierLocalRepository _localRepo;
@override
Future<Either<Failure, List<Supplier>>> getSuppliers() async {
try {
// Try local first (offline-first)
final local = await _localRepo.getSuppliers();
// Sync with API in background
final result = await _api.getSuppliers();
result.fold(
(failure) => null,
(data) => _localRepo.saveSuppliers(data),
);
return Right(local.isNotEmpty ? local : result.getOrElse(() => []));
} catch (e) {
return Left(UnexpectedFailure(e.toString()));
}
}
}
๐ก API Integration
Endpoints
Request/Response Examples
Get List
GET /api/v1/suppliers/*
Authorization: Bearer {access_token}
Response:
{
"success": true,
"data": [
{
"id": "123",
"name": "Example",
"created_at": "2024-10-14T10:00:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 100
}
}
๐พ Local Database (Isar)
@collection
class SupplierLocal {
Id id = Isar.autoIncrement;
@Index()
String? supplierId;
String? name;
DateTime? createdAt;
DateTime? updatedAt;
DateTime? syncedAt;
bool? isSynced;
bool? isDeleted;
}
Queries
// Get all
final items = await isar.supplierLocals.where().findAll();
// Get by ID
final item = await isar.supplierLocals
.filter()
.supplierIdEqualTo(id)
.findFirst();
// Search
final results = await isar.supplierLocals
.filter()
.nameContains(query, caseSensitive: false)
.findAll();
// Get unsynced
final unsynced = await isar.supplierLocals
.filter()
.isSyncedEqualTo(false)
.findAll();
๐ Offline-First Strategy
Write Operations
- Save to local Isar immediately
- Show success to user
- Add to sync queue
- Background sync when online
- Update with server response
Read Operations
- Read from local Isar (fast)
- Show to user immediately
- Background fetch from API
- Update local cache if changed
- Notify UI if data updated
Conflict Resolution
- Strategy: Last-write-wins
- Timestamp: Server timestamp as source of truth
- Logging: All conflicts logged for audit
๐จ UI Components
Main Screen
class SupplierPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => getIt<SupplierBloc>()..add(LoadSupplier()),
child: Scaffold(
appBar: AppBar(title: Text('Supplier Management')),
body: BlocBuilder<SupplierBloc, SupplierState>(
builder: (context, state) {
if (state is SupplierLoading) {
return Center(child: CircularProgressIndicator());
}
if (state is SupplierError) {
return ErrorWidget(message: state.message);
}
if (state is SupplierLoaded) {
return SupplierListView(items: state.items);
}
return SizedBox.shrink();
},
),
floatingActionButton: FloatingActionButton(
onPressed: () => _navigateToCreate(context),
child: Icon(Icons.add),
),
),
);
}
}
๐งช Testing
Unit Tests
void main() {
group('SupplierBloc', () {
late SupplierBloc bloc;
late MockSupplierRepository mockRepository;
setUp(() {
mockRepository = MockSupplierRepository();
bloc = SupplierBloc(repository: mockRepository);
});
tearDown(() {
bloc.close();
});
test('initial state is SupplierInitial', () {
expect(bloc.state, equals(SupplierInitial()));
});
blocTest<SupplierBloc, SupplierState>(
'emits [Loading, Loaded] when Load succeeds',
build: () {
when(() => mockRepository.getSuppliers()).thenAnswer(
(_) async => Right([Supplier(id: '1', name: 'Test')]),
);
return bloc;
},
act: (bloc) => bloc.add(LoadSupplier()),
expect: () => [
SupplierLoading(),
isA<SupplierLoaded>(),
],
);
});
}
- Lazy Loading: Load data on demand
- Pagination: Implement pagination for large datasets
- Caching: Cache frequently accessed data
- Indexing: Use Isar indexes for fast queries
- Background Sync: Sync in background to avoid blocking UI
๐ Security
- Authorization: Check user permissions before operations
- Data Encryption: Sensitive data encrypted in Isar
- Input Validation: Validate all user inputs
- Audit Trail: Log all operations for audit
- Use Cupertino widgets
- Follow iOS HIG
- Handle safe area insets
Android
- Use Material widgets
- Follow Material Design
- Handle back button
Last Updated: October 14, 2024
Status: โ
Production Ready