Yeni Feature Olusturma Sirasi
lib/features/[name]/domain/entities/- Entity (freezed, saf Dart)lib/features/[name]/domain/repositories/- Abstract repositorylib/features/[name]/data/models/- Model (freezed + json_serializable)lib/features/[name]/data/datasources/- Remote/local datasourcelib/features/[name]/data/repositories/- Repository impllib/features/[name]/presentation/providers/- Riverpod providerlib/features/[name]/presentation/screens/- Ekranlib/features/[name]/presentation/widgets/- Widgetdart run build_runner build --delete-conflicting-outputs- Test yaz
Katman Kurallari
- Domain: SADECE Dart, Flutter import YASAK. Entity + abstract repo.
- Data: Model (DTO), datasource, repo implementasyonu. Dio, Hive vs burada.
- Presentation: Provider, screen, widget. Riverpod burada.
- Core: Paylasilan (network, storage, error, widget). Feature'lar arasi kopru.
Abstract Repository
abstract class UserRepository {
Future<User> getById(String id);
Future<List<User>> getAll();
Future<void> create(User user);
Future<void> update(User user);
Future<void> delete(String id);
}
Repository Implementation
class UserRepositoryImpl implements UserRepository {
final UserRemoteDataSource _remote;
final UserLocalDataSource _local;
UserRepositoryImpl(this._remote, this._local);
@override
Future<User> getById(String id) async {
try {
final model = await _remote.getUser(id);
await _local.cacheUser(model);
return model.toEntity();
} catch (e) {
final cached = await _local.getCachedUser(id);
if (cached != null) return cached.toEntity();
rethrow;
}
}
}
Model -> Entity Donusumu
extension UserModelX on UserModel {
User toEntity() => User(id: id, name: name, email: email);
}
extension UserX on User {
UserModel toModel() => UserModel(id: id, name: name, email: email);
}